public function MenuLinkConfig::getEntity in Config menu link 8
Loads the entity associated with this menu link.
Return value
\Drupal\menu_link_config\MenuLinkConfigInterface The menu link content entity.
Throws
\Drupal\Component\Plugin\Exception\PluginException If the entity ID and UUID are both invalid or missing.
Overrides MenuLinkContent::getEntity
2 calls to MenuLinkConfig::getEntity()
- MenuLinkConfig::getTranslateRoute in src/
Plugin/ Menu/ MenuLinkConfig.php - Returns route information for a route to translate the menu link.
- MenuLinkConfig::updateLink in src/
Plugin/ Menu/ MenuLinkConfig.php - @todo Simply storing the entity type ID in a variable would alleviate the need to override this entire method.
File
- src/
Plugin/ Menu/ MenuLinkConfig.php, line 89 - Contains \Drupal\menu_link_config\Plugin\Menu\MenuLinkConfig.
Class
- MenuLinkConfig
- Provides a menu link plugin based upon storage in config.
Namespace
Drupal\menu_link_config\Plugin\MenuCode
public function getEntity() {
if (empty($this->entity)) {
$entity = NULL;
$storage = $this->entityManager
->getStorage('menu_link_config');
if (!empty($this->pluginDefinition['metadata']['entity_id'])) {
$entity_id = $this->pluginDefinition['metadata']['entity_id'];
// Make sure the current ID is in the list, since each plugin empties
// the list after calling loadMultple(). Note that the list may include
// multiple IDs added earlier in each plugin's constructor.
static::$entityIdsToLoad[$entity_id] = $entity_id;
$entities = $storage
->loadMultiple(array_values(static::$entityIdsToLoad));
$entity = isset($entities[$entity_id]) ? $entities[$entity_id] : NULL;
static::$entityIdsToLoad = array();
}
if (!$entity) {
// Fallback to the loading by the ID.
$entity = $storage
->load($this
->getDerivativeId());
}
if (!$entity) {
throw new PluginException(sprintf('Entity not found through the menu link plugin definition and could not fallback on ID %s', $this
->getDerivativeId()));
}
// Clone the entity object to avoid tampering with the static cache.
$this->entity = clone $entity;
$this->entity = $this->entityManager
->getTranslationFromContext($this->entity);
}
return $this->entity;
}