You are here

class AdminToolbarToolsHelper in Admin Toolbar 8.2

Same name and namespace in other branches
  1. 3.x admin_toolbar_tools/src/AdminToolbarToolsHelper.php \Drupal\admin_toolbar_tools\AdminToolbarToolsHelper

Admin Toolbar Tools helper service.

Hierarchy

Expanded class hierarchy of AdminToolbarToolsHelper

1 string reference to 'AdminToolbarToolsHelper'
admin_toolbar_tools.services.yml in admin_toolbar_tools/admin_toolbar_tools.services.yml
admin_toolbar_tools/admin_toolbar_tools.services.yml
1 service uses AdminToolbarToolsHelper
admin_toolbar_tools.helper in admin_toolbar_tools/admin_toolbar_tools.services.yml
Drupal\admin_toolbar_tools\AdminToolbarToolsHelper

File

admin_toolbar_tools/src/AdminToolbarToolsHelper.php, line 10

Namespace

Drupal\admin_toolbar_tools
View source
class AdminToolbarToolsHelper {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Create an AdminToolbarToolsHelper object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Gets a list of content entities.
   *
   * @return array
   *   An array of metadata about content entities.
   */
  public function getBundleableEntitiesList() {
    $entity_types = $this->entityTypeManager
      ->getDefinitions();
    $content_entities = [];
    foreach ($entity_types as $key => $entity_type) {
      if ($entity_type
        ->getBundleEntityType() && $entity_type
        ->get('field_ui_base_route') != '') {
        $content_entities[$key] = [
          'content_entity' => $key,
          'content_entity_bundle' => $entity_type
            ->getBundleEntityType(),
        ];
      }
    }
    return $content_entities;
  }

  /**
   * Gets an array of entity types that should trigger a menu rebuild.
   *
   * @return array
   *   An array of entity machine names.
   */
  public function getRebuildEntityTypes() {
    $types = [
      'menu',
    ];
    $content_entities = $this
      ->getBundleableEntitiesList();
    $types = array_merge($types, array_column($content_entities, 'content_entity_bundle'));
    return $types;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminToolbarToolsHelper::$entityTypeManager protected property The entity type manager.
AdminToolbarToolsHelper::getBundleableEntitiesList public function Gets a list of content entities.
AdminToolbarToolsHelper::getRebuildEntityTypes public function Gets an array of entity types that should trigger a menu rebuild.
AdminToolbarToolsHelper::__construct public function Create an AdminToolbarToolsHelper object.