You are here

protected function ExtraFieldTypePluginBase::getEntityTokenData in Entity Extra Field 2.0.x

Same name and namespace in other branches
  1. 8 src/ExtraFieldTypePluginBase.php \Drupal\entity_extra_field\ExtraFieldTypePluginBase::getEntityTokenData()

Get entity token data.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity instance.

Return value

array An array of token data.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to ExtraFieldTypePluginBase::getEntityTokenData()
ExtraFieldTypePluginBase::processEntityToken in src/ExtraFieldTypePluginBase.php
Process the entity token text.

File

src/ExtraFieldTypePluginBase.php, line 318

Class

ExtraFieldTypePluginBase
Define extra field type plugin base.

Namespace

Drupal\entity_extra_field

Code

protected function getEntityTokenData(ContentEntityInterface $entity) : array {
  $token_type = $entity
    ->getEntityType()
    ->get('token_type') ?? $entity
    ->getEntityTypeId();
  $data[$token_type] = $entity;
  $field_references = $this
    ->getEntityFieldReferenceTypes($entity
    ->getEntityTypeId(), $entity
    ->bundle());
  foreach ($field_references as $field_name => $target_type) {
    if (isset($data[$target_type]) || !$entity
      ->hasField($field_name)) {
      continue;
    }
    $data[$target_type] = $entity->{$field_name}->entity;
  }
  return array_filter($data);
}