You are here

private function LayoutBuilder::prepareEntityBrowserBlockIds in Entity Usage 8.2

Prepare Entity Browser Block IDs to be in the correct format.

Parameters

array $ebbContentIds: An array of entity ID values as returned from the EBB configuration. (Each value is expected to be in the format "node:123", "media:42", etc).

Return value

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

  • Non-loadable entities will be filtered out.
  • The ":" character will be replaced by the "|" character.
1 call to LayoutBuilder::prepareEntityBrowserBlockIds()
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 174

Class

LayoutBuilder
Tracks usage of entities related in Layout Builder layouts.

Namespace

Drupal\entity_usage\Plugin\EntityUsage\Track

Code

private function prepareEntityBrowserBlockIds(array $ebbContentIds) {

  // Only return loadable entities.
  $ids = array_filter($ebbContentIds, function ($item) {

    // Entity Browser Block stores each entity in "entity_ids" in the format:
    // "{$entity_type_id}:{$entity_id}".
    list($entity_type_id, $entity_id) = explode(":", $item);
    $storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    if (!$storage) {
      return FALSE;
    }
    $entity = $storage
      ->load($entity_id);
    if (!$entity) {
      return FALSE;
    }
    return TRUE;
  });
  if (empty($ids)) {
    return [];
  }

  // Return items in the expected format, separating type and id with a "|".
  return array_map(function (string $item) : string {
    return str_replace(":", "|", $item);
  }, $ids);
}