Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
EntityUsageTrackMultipleLoadInterface.php 1.30 KiB
<?php

namespace Drupal\entity_usage;

use Drupal\Core\Field\FieldItemListInterface;

/**
 * Defines the interface for entity_usage track methods.
 *
 * Track plugins use any arbitrary method to link two entities together.
 * Examples include:
 *
 * - Entities related through an entity_reference field are tracked using the
 *   "entity_reference" method.
 * - Entities embedded into other entities are tracked using the "embed" method.
 */
interface EntityUsageTrackMultipleLoadInterface extends EntityUsageTrackInterface {

  /**
   * Retrieve the target entity(ies) from a field.
   *
   * @param \Drupal\Core\Field\FieldItemListInterface $field
   *   The field to get the target entity(ies) from.
   *
   * @return array<int, string|array{target_type: string, target_id: string|int, field_name?: string, method?: string}>
   *   An indexed array where each value can be a string or an array:
   *   - if a string: the target entity type and ID concatenated with a "|"
   *     character.
   *   - if an array: an array with the target_type and target_id keys, and
   *     optionally the method and field_name keys.
   *   Will return an empty array if no target entities could be retrieved from
   *   the received field item value.
   */
  public function getTargetEntitiesFromField(FieldItemListInterface $field): array;

}