You are here

private function LayoutBuilder::prepareContentDependencyIds in Entity Usage 8.2

Prepare plugin content dependency IDs to be in the correct format.

Parameters

array $ids: An array of entity ID values as returned from the plugin dependency configuration. (Each value is expected to be in the format "media:image:4dd39aa2-068f-11ec-9a03-0242ac130003", etc).

Return value

array The same array passed in, with the following modifications:

  • Non-loadable entities will be filtered out.
  • The bundle ID in the middle will be removed.
  • The UUID will be converted to a regular ID.
  • The ":" character will be replaced by the "|" character.
1 call to LayoutBuilder::prepareContentDependencyIds()
LayoutBuilder::getTargetEntities in src/Plugin/EntityUsage/Track/LayoutBuilder.php
Retrieve the target entity(ies) from a field item value.

File

src/Plugin/EntityUsage/Track/LayoutBuilder.php, line 216

Class

LayoutBuilder
Tracks usage of entities related in Layout Builder layouts.

Namespace

Drupal\entity_usage\Plugin\EntityUsage\Track

Code

private function prepareContentDependencyIds(array $ids) {

  // Only return loadable entities.
  $ids = array_map(function ($item) {

    // Content dependencies are stored in the format:
    // "{$entity_type_id}:{$bundle_id}:{$entity_uuid}".
    list($entity_type_id, , $entity_uuid) = explode(':', $item);
    if ($entity = $this->entityRepository
      ->loadEntityByUuid($entity_type_id, $entity_uuid)) {
      return "{$entity_type_id}|{$entity->id()}";
    }
    return FALSE;
  }, $ids);
  return array_filter($ids);
}