Skip to content

Commit

Permalink
fix: use entity_usage to solve gatsby node reference issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Oct 10, 2023
1 parent 31e223d commit 129224b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _core:
local_task_enabled_entity_types:
- media
- node
- taxonomy_term
track_enabled_source_entity_types:
- node
- block_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ use Drupal\user\UserInterface;


function _silverback_gatsby_entity_event(EntityInterface $entity) {
\Drupal::service('silverback_gatsby.update_handler')->handle(EntityFeed::class, $entity);
/** @var \Drupal\silverback_gatsby\GatsbyUpdateHandler $updateHandler */
$updateHandler = \Drupal::service('silverback_gatsby.update_handler');
$updateHandler->handle(EntityFeed::class, $entity);

if (\Drupal::hasService('entity_usage.usage')) {
/** @var \Drupal\entity_usage\EntityUsage $entityUsage */
$entityUsage = \Drupal::service('entity_usage.usage');
foreach ($entityUsage->listSources($entity) as $sourceEntityType => $sources) {
$entities = \Drupal::entityTypeManager()
->getStorage($sourceEntityType)
->loadMultiple(array_keys($sources));
foreach ($entities as $source) {
$updateHandler->handle(EntityFeed::class, $source);
}
}
}
}

/**
Expand Down Expand Up @@ -42,6 +57,18 @@ function silverback_gatsby_entity_predelete(EntityInterface $entity) {
_silverback_gatsby_entity_event($entity);
}

/**
* Implements hook_module_implements_alter().
*/
function silverback_gatsby_module_implements_alter(&$implementations, $hook) {
// Act before entity_usage module.
if (in_array($hook, ['entity_insert', 'entity_update', 'entity_predelete'], TRUE)) {
$implementations = [
'silverback_gatsby' => $implementations['silverback_gatsby'],
] + $implementations;
}
}

/**
* Implements hook_entity_type_alter().
*/
Expand Down

0 comments on commit 129224b

Please sign in to comment.