You are here

class ExtensionDataCollector in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/DataCollector/ExtensionDataCollector.php \Drupal\webprofiler\DataCollector\ExtensionDataCollector
  2. 8.2 webprofiler/src/DataCollector/ExtensionDataCollector.php \Drupal\webprofiler\DataCollector\ExtensionDataCollector
  3. 4.x webprofiler/src/DataCollector/ExtensionDataCollector.php \Drupal\webprofiler\DataCollector\ExtensionDataCollector

Defines a data collector for the extension system.

Hierarchy

Expanded class hierarchy of ExtensionDataCollector

1 string reference to 'ExtensionDataCollector'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses ExtensionDataCollector
webprofiler.drupal_extensions in webprofiler/webprofiler.services.yml
Drupal\webprofiler\DataCollector\ExtensionDataCollector

File

webprofiler/src/DataCollector/ExtensionDataCollector.php, line 16

Namespace

Drupal\webprofiler\DataCollector
View source
class ExtensionDataCollector extends DataCollector implements DrupalDataCollectorInterface {
  use StringTranslationTrait, DrupalDataCollectorTrait;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

  /**
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   * @param string $root
   *   The app root.
   */
  public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, $root) {
    $this->moduleHandler = $module_handler;
    $this->themeHandler = $theme_handler;
    $this->root = $root;
    $this->data['drupal_extension']['modules'] = [];
    $this->data['drupal_extension']['themes'] = [];
  }

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = NULL) {
    $modules = $this->moduleHandler
      ->getModuleList();
    $themes = $this->themeHandler
      ->listInfo();
    $this->data['drupal_extension']['count'] = count($modules) + count($themes);
    $this->data['drupal_extension']['modules'] = $modules;
    $this->data['drupal_extension']['themes'] = $themes;
    $this->data['drupal_extension']['installation_path'] = $this->root . '/';
  }

  /**
   * Returns the total number of active extensions.
   *
   * @return int
   */
  public function getExtensionsCount() {
    return isset($this->data['drupal_extension']['count']) ? $this->data['drupal_extension']['count'] : 0;
  }

  /**
   * Returns the total number of active modules.
   *
   * @return int
   */
  public function getModulesCount() {
    return count($this->data['drupal_extension']['modules']);
  }

  /**
   * Returns the total number of active themes.
   *
   * @return int
   */
  public function getThemesCount() {
    return count($this->data['drupal_extension']['themes']);
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'drupal_extension';
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->t('Extensions');
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this
      ->t('Total: @extensions', [
      '@extensions' => $this
        ->getExtensionsCount(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAcCAYAAABh2p9gAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8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H0TiMtwFg5EgvnQXHIFmibfUGrgeaghTdBIxAoYR2u9EWAgQIABAKKeRzEX0gXIAAAAAElFTkSuQmCC';
  }

  /**
   * {@inheritdoc}
   */
  public function getData() {
    $data = $this->data;

    // Copy protected properties over public ones to
    // let json_encode to find them.
    $this
      ->copyToPublic($data['drupal_extension']['modules']);
    $this
      ->copyToPublic($data['drupal_extension']['themes']);
    return $data;
  }

  /**
   * Copies protected properties to public ones.
   *
   * @param \Drupal\Core\Extension\Extension[] $extensions
   */
  private function copyToPublic($extensions) {
    foreach ($extensions as &$extension) {
      $extension->public_type = $extension
        ->getType();
      $extension->public_name = $extension
        ->getName();
      $extension->public_path = $extension
        ->getPath();
      $extension->public_pathname = $extension
        ->getPathname();
      $extension->public_filename = $extension
        ->getFilename();
      $extension->public_extension_pathname = $extension
        ->getExtensionPathname();
      $extension->public_extension_filename = $extension
        ->getExtensionFilename();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDataCollectorInterface::getDrupalSettings public function 1
DrupalDataCollectorInterface::getLibraries public function Returns the libraries needed in detail panel. 2
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
ExtensionDataCollector::$moduleHandler protected property The module handler.
ExtensionDataCollector::$root protected property The app root.
ExtensionDataCollector::$themeHandler protected property The theme handler.
ExtensionDataCollector::collect public function Collects data for the given Request and Response.
ExtensionDataCollector::copyToPublic private function Copies protected properties to public ones.
ExtensionDataCollector::getData public function Overrides DrupalDataCollectorInterface::getData
ExtensionDataCollector::getExtensionsCount public function Returns the total number of active extensions.
ExtensionDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
ExtensionDataCollector::getModulesCount public function Returns the total number of active modules.
ExtensionDataCollector::getName public function Returns the name of the collector. Overrides DrupalDataCollectorInterface::getName
ExtensionDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
ExtensionDataCollector::getThemesCount public function Returns the total number of active themes.
ExtensionDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
ExtensionDataCollector::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.