You are here

private function Link::linkFieldsAvailable in Entity Usage 8

Retrieve the link fields on a given entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity object.

Return value

array An array of field_names that could reference to other content entities.

3 calls to Link::linkFieldsAvailable()
Link::trackOnEntityCreation in src/Plugin/EntityUsage/Track/Link.php
Track usage updates on the creation of entities.
Link::trackOnEntityDeletion in src/Plugin/EntityUsage/Track/Link.php
Track usage updates on the deletion of entities.
Link::trackOnEntityUpdate in src/Plugin/EntityUsage/Track/Link.php
Track usage updates on the edition of entities.

File

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

Class

Link
Tracks usage of entities related in entity_reference fields.

Namespace

Drupal\entity_usage\Plugin\EntityUsage\Track

Code

private function linkFieldsAvailable(ContentEntityInterface $entity) {
  $return_fields = [];
  $fields_on_entity = $this->entityFieldManager
    ->getFieldDefinitions($entity
    ->getEntityTypeId(), $entity
    ->bundle());
  $link_fields_on_this_entity_type = [];
  if (!empty($this->entityFieldManager
    ->getFieldMapByFieldType('link')[$entity
    ->getEntityTypeId()])) {
    $link_fields_on_this_entity_type = $this->entityFieldManager
      ->getFieldMapByFieldType('link')[$entity
      ->getEntityTypeId()];
  }
  $link_fields_on_this_bundle = array_intersect_key($fields_on_entity, $link_fields_on_this_entity_type);

  // Clean out basefields.
  $basefields = $this->entityFieldManager
    ->getBaseFieldDefinitions($entity
    ->getEntityTypeId());
  $link_fields_on_this_bundle = array_diff_key($link_fields_on_this_bundle, $basefields);
  if (!empty($link_fields_on_this_bundle)) {
    $return_fields = array_keys($link_fields_on_this_bundle);
  }
  return $return_fields;
}