public function ActiveEntity::getFromEntity in Configuration selector 8.2
Same name and namespace in other branches
- 8 src/ActiveEntity.php \Drupal\config_selector\ActiveEntity::getFromEntity()
Gets the active entity from using the details from an entity.
Parameters
\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity to get the active entity for.
Return value
\Drupal\Core\Entity\EntityInterface The active entity for the provided entity.
File
- src/
ActiveEntity.php, line 64
Class
- ActiveEntity
- Helper for getting the active entity or ID of any config_selector feature.
Namespace
Drupal\config_selectorCode
public function getFromEntity(ConfigEntityInterface $entity) {
$feature = $entity
->getThirdPartySetting('config_selector', 'feature');
if (!$feature) {
// This is not a config selected entity. Therefore, do not convert the ID.
return $entity;
}
$active_entity = $this
->get($entity
->getEntityTypeId(), $feature);
// If there is no active ID return the entity.
return $active_entity ?: $entity;
}