Creates action to link Ableplayer Caption Media to Audio or Video Media
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

<?php
/**
* @file
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\media\MediaInterface;
use Drupal\node\NodeInterface;
/**
* Implements hook_entity_insert().
*/
function caption_linker_entity_insert(EntityInterface $entity): void {
if ($entity instanceof MediaInterface) {
_caption_linker_link_caption_if_possible($entity);
}
}
/**
* Implements hook_entity_update().
*/
function caption_linker_entity_update(EntityInterface $entity): void {
if ($entity instanceof MediaInterface) {
_caption_linker_link_caption_if_possible($entity);
}
}
/**
* Tries to link a caption if applicable.
*/
function _caption_linker_link_caption_if_possible(MediaInterface $media): void {
/** @var \Drupal\islandora\IslandoraUtils $islandora_utils */
$islandora_utils = \Drupal::service('islandora.utils');
/** @var \Drupal\caption_linker\Service\CaptionLinker $caption_linker */
$caption_linker = \Drupal::service('caption_linker.caption_linker');
$node = $islandora_utils->getParentNode($media);
if ($node instanceof NodeInterface) {
$caption_linker->linkCaption($node);
}
}