You are here

protected function Link::getEntity in Field Group Link 8.3

Get the entity object from the rendering object.

Parameters

array $rendering_object: The group render array. As passed to preRender().

Return value

\Drupal\Core\Entity\ContentEntityInterface|null Either the entity, or NULL if not found.

1 call to Link::getEntity()
Link::preRender in src/Plugin/field_group/FieldGroupFormatter/Link.php

File

src/Plugin/field_group/FieldGroupFormatter/Link.php, line 255

Class

Link
Plugin implementation of the 'link' formatter.

Namespace

Drupal\field_group_link\Plugin\field_group\FieldGroupFormatter

Code

protected function getEntity(array $rendering_object) {

  // Get the entity key from the entity type.
  if (!isset($this->group->entity_type)) {
    return NULL;
  }
  $entity_key = '#' . $this->group->entity_type;
  if (!isset($rendering_object[$entity_key])) {

    // Some entity types store the key in an arbitrary name.
    // Check for the ones that we know of.
    switch ($this->group->entity_type) {
      case 'taxonomy_term':
        $entity_key = '#term';
        break;
      case 'user':
        $entity_key = '#account';
        break;

      // Otherwise just search for #entity.
      default:
        $entity_key = '#entity';
    }
  }
  if (isset($rendering_object[$entity_key]) && $rendering_object[$entity_key] instanceof ContentEntityInterface) {
    return $rendering_object[$entity_key];
  }
  else {
    return NULL;
  }
}