You are here

protected function ThemeSuggestions::getEntityObject in Express 8

Extracts the entity from the element(s) passed in the Variables object.

Parameters

string $entity_type: Optional. The entity type to attempt to retrieve.

Return value

\Drupal\Core\Entity\EntityInterface|null The extracted entity, NULL if entity could not be found.

2 calls to ThemeSuggestions::getEntityObject()
ThemeSuggestions::addSuggestionsForEntity in themes/contrib/bootstrap/src/Plugin/Alter/ThemeSuggestions.php
Adds "bundle" and "view mode" suggestions for an entity.
ThemeSuggestions::getEntity in themes/contrib/bootstrap/src/Plugin/Alter/ThemeSuggestions.php
Extracts the entity from the element(s) passed in the Variables object.

File

themes/contrib/bootstrap/src/Plugin/Alter/ThemeSuggestions.php, line 288
Contains \Drupal\bootstrap\Plugin\Alter\ThemeSuggestions.

Class

ThemeSuggestions
Implements hook_theme_suggestions_alter().

Namespace

Drupal\bootstrap\Plugin\Alter

Code

protected function getEntityObject($entity_type = 'entity') {

  // Immediately return if there is no element.
  if (!$this->element) {
    return NULL;
  }

  // Attempt to retrieve the provided element type.
  $entity = $this->element
    ->getProperty($entity_type);

  // If the provided entity type doesn't exist, check to see if a generic
  // "entity" property was used instead.
  if ($entity_type !== 'entity' && (!$entity || !$entity instanceof EntityInterface)) {
    $entity = $this->element
      ->getProperty('entity');
  }

  // Only return the entity if it's the proper object.
  return $entity instanceof EntityInterface ? $entity : NULL;
}