You are here

class EntityUsageSourceLevel in Entity Usage 8.3

Defines the interface for the service managing top-level source entities.

Hierarchy

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_usage
View 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') ?: [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityUsageSourceLevel::getBottomLevelEntityTypes public static function Returns all entity type names that are defined as bottom-level (targets). Overrides EntityUsageSourceLevelInterface::getBottomLevelEntityTypes
EntityUsageSourceLevel::getMiddleLevelEntityTypes public static function Returns all entity type names that are defined as middle-level. Overrides EntityUsageSourceLevelInterface::getMiddleLevelEntityTypes
EntityUsageSourceLevel::getTopLevelEntityTypes public static function Returns all entity type names that are defined as top-level (sources). Overrides EntityUsageSourceLevelInterface::getTopLevelEntityTypes
EntityUsageSourceLevel::isBottomLevel public static function Checks whether an entity is a bottom-level entity. Overrides EntityUsageSourceLevelInterface::isBottomLevel
EntityUsageSourceLevel::isMiddleLevel public static function Checks whether an entity is a middle-level entity. Overrides EntityUsageSourceLevelInterface::isMiddleLevel
EntityUsageSourceLevel::isTopLevel public static function Checks whether an entity is a top-level entity. Overrides EntityUsageSourceLevelInterface::isTopLevel
EntityUsageSourceLevel::TOP_LEVEL_TYPES constant Lists entity types we consider top-level.