|
|
|
|
@ -2,5 +2,41 @@
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @file |
|
|
|
|
* Primary module hooks for Caption Linker module. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|