EntityUsageSourceLevel.php in Entity Usage 8.3
File
src/EntityUsageSourceLevel.php
View source
<?php
namespace Drupal\entity_usage;
use Drupal\Core\Entity\EntityInterface;
class EntityUsageSourceLevel implements EntityUsageSourceLevelInterface {
const TOP_LEVEL_TYPES = [
'node',
];
public static function isTopLevel(EntityInterface $entity) {
return in_array($entity
->getEntityTypeId(), self::TOP_LEVEL_TYPES);
}
public static function isMiddleLevel(EntityInterface $entity) {
return !self::isBottomLevel($entity);
}
public static function isBottomLevel(EntityInterface $entity) {
$types_with_local_task = \Drupal::config('entity_usage.settings')
->get('local_task_enabled_entity_types') ?: [];
return in_array($entity
->getEntityTypeId(), $types_with_local_task);
}
public static function getTopLevelEntityTypes() {
return self::TOP_LEVEL_TYPES;
}
public static function getMiddleLevelEntityTypes() {
return array_diff(array_keys(\Drupal::entityTypeManager()
->getDefinitions()), self::getBottomLevelEntityTypes());
}
public static function getBottomLevelEntityTypes() {
return \Drupal::config('entity_usage.settings')
->get('local_task_enabled_entity_types') ?: [];
}
}