class EntityUsageSourceLevel in Entity Usage 8.3
Defines the interface for the service managing top-level source entities.
Hierarchy
- class \Drupal\entity_usage\EntityUsageSourceLevel implements EntityUsageSourceLevelInterface
Expanded class hierarchy of EntityUsageSourceLevel
5 files declare their use of EntityUsageSourceLevel
- BatchUpdateForm.php in src/
Form/ BatchUpdateForm.php - entity_usage.install in ./
entity_usage.install - Install, update and uninstall functions for entity_usage module.
- entity_usage.module in ./
entity_usage.module - Contains entity_usage.module.
- entity_usage.post_update.php in ./
entity_usage.post_update.php - Post-update hooks for entity_usage module.
- ListUsageController.php in src/
Controller/ ListUsageController.php
File
- src/
EntityUsageSourceLevel.php, line 10
Namespace
Drupal\entity_usageView source
class EntityUsageSourceLevel implements EntityUsageSourceLevelInterface {
/**
* Lists entity types we consider top-level.
*/
const TOP_LEVEL_TYPES = [
'node',
];
/**
* {@inheritdoc}
*/
public static function isTopLevel(EntityInterface $entity) {
// @todo Make it easier for sites to override this. Currently the way is to
// override this service and write this method differently. Maybe it's worth
// letting sites do this in an easier way.
return in_array($entity
->getEntityTypeId(), self::TOP_LEVEL_TYPES);
}
/**
* {@inheritdoc}
*/
public static function isMiddleLevel(EntityInterface $entity) {
// For us all entities that are not bottom are middle.
return !self::isBottomLevel($entity);
}
/**
* {@inheritdoc}
*/
public static function isBottomLevel(EntityInterface $entity) {
// If the entity has the usage tab configured, we consider it bottom.
$types_with_local_task = \Drupal::config('entity_usage.settings')
->get('local_task_enabled_entity_types') ?: [];
return in_array($entity
->getEntityTypeId(), $types_with_local_task);
}
/**
* {@inheritdoc}
*/
public static function getTopLevelEntityTypes() {
// @todo Make it easier for sites to override this.
return self::TOP_LEVEL_TYPES;
}
/**
* {@inheritdoc}
*/
public static function getMiddleLevelEntityTypes() {
// For us all entities that are not bottom are middle.
return array_diff(array_keys(\Drupal::entityTypeManager()
->getDefinitions()), self::getBottomLevelEntityTypes());
}
/**
* {@inheritdoc}
*/
public static function getBottomLevelEntityTypes() {
return \Drupal::config('entity_usage.settings')
->get('local_task_enabled_entity_types') ?: [];
}
}