Commit 191439b9 authored by syeda-farheen's avatar syeda-farheen Committed by Gaurav Kapoor
Browse files

Issue #3257401 by syeda-farheen, gaurav.kapoor, dineshreddymathuku: Add a...

Issue #3257401 by syeda-farheen, gaurav.kapoor, dineshreddymathuku: Add a plugin to fetch information for all the modules installed in the website
parent afe70d4c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@ plugins:
  - 'taxonomy_vocabulary'
  - 'user_role'
  - 'view'
  - 'enabled_modules'
+104 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\documentation_generator\Plugin\DocumentationGeneratorChapter;

use Drupal\Core\Url;
use Drupal\documentation_generator\Plugin\DocumentationGeneratorChapterBase;

/**
 * Enabled Modules Documentation Generator chapter.
 *
 * Implements Documentation Generator Chapter plugin for Modules.
 *
 * @DocumentationGeneratorChapter(
 *   id = "enabled_modules",
 *   label = @Translation("Modules")
 * )
 */
class EnabledModules extends DocumentationGeneratorChapterBase {

  /**
   * {@inheritdoc}
   */
  public function moduleDependencies() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function pluginElements() {
    $enabledModules = $this->moduleHandler
      ->getModuleList();

    return $enabledModules;
  }

  /**
   * {@inheritdoc}
   */
  public function elements() {
    $elements = [];

    $elements[] = [
      'type' => 'title',
      'level' => 1,
      'value' => $this->t('Modules')->render(),
    ];

    $url = Url::fromUserInput('/admin/modules')->setAbsolute()->toString();
    $elements[] = [
      'type' => 'paragraph',
      'level' => 2,
      'value' => $this->t('This section provides information about enabled modules : @parameter')->render(),
      'parameters' => [
        0 => [
          'type' => 'link',
          'text' => $url,
          'src' => $url,
        ],
      ],
    ];

    $enabledModules = $this->pluginElements();
    $this->removeDisabledElements($enabledModules);
    $info = $this->extensionList->getAllInstalledInfo();

    foreach (array_keys($enabledModules) as $module) {
      $helpUrl = $url = Url::fromUserInput('/admin/help/' . $module)->setAbsolute()->toString();

      $description = $info[$module]['description'];

      $elements[] = [
        'type' => 'title',
        'level' => 2,
        'value' => $this->moduleHandler->getName($module),
      ];

      $elements[] = [
        'type' => 'paragraph',
        'level' => 3,
        'value' => $description,
      ];

      $elements[] = [
        'type' => 'paragraph',
        'level' => 3,
        'value' => $this->t(
            'More about @type at : @parameter', [
              '@type' => $this->moduleHandler->getName($module),
            ]
        )->render(),
        'parameters' => [
          0 => [
            'type' => 'link',
            'text' => $helpUrl,
            'src' => $helpUrl,
          ],
        ],
      ];
    }
    return $elements;
  }

}
+15 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Extension\ExtensionList;

/**
 * Base class for Documentation Generator Chapter plugins.
@@ -46,6 +47,13 @@ abstract class DocumentationGeneratorChapterBase extends PluginBase implements D
   */
  protected $configFactory;

  /**
   * The Module Extension List .
   *
   * @var \Drupal\Core\Extension\ExtensionList
   */
  protected $extensionList;

  /**
   * The constructor.
   *
@@ -63,6 +71,8 @@ abstract class DocumentationGeneratorChapterBase extends PluginBase implements D
   *   The module handler.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config factory.
   * @param \Drupal\Core\Extension\ExtensionList $extensionList
   *   The module extension list.
   */
  public function __construct(
    array $configuration,
@@ -71,7 +81,8 @@ abstract class DocumentationGeneratorChapterBase extends PluginBase implements D
    EntityTypeManagerInterface $entityTypeManager,
    EntityfieldManagerInterface $entityFieldManager,
    ModuleHandlerInterface $moduleHandler,
    ConfigFactoryInterface $configFactory
    ConfigFactoryInterface $configFactory,
    ExtensionList $extensionList,
  ) {
    parent::__construct(
      $configuration,
@@ -83,6 +94,7 @@ abstract class DocumentationGeneratorChapterBase extends PluginBase implements D
    $this->entityFieldManager = $entityFieldManager;
    $this->moduleHandler = $moduleHandler;
    $this->configFactory = $configFactory;
    $this->extensionList = $extensionList;
  }

  /**
@@ -101,7 +113,8 @@ abstract class DocumentationGeneratorChapterBase extends PluginBase implements D
      $container->get('entity_type.manager'),
      $container->get('entity_field.manager'),
      $container->get('module_handler'),
      $container->get('config.factory')
      $container->get('config.factory'),
      $container->get('extension.list.module')
    );
  }

+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Drupal\documentation_generator\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Traversable;

/**
 * Provides the Documentation Generator Chapter plugin manager.
@@ -24,7 +23,7 @@ class DocumentationGeneratorChapterManager extends DefaultPluginManager {
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(
    Traversable $namespaces,
    \Traversable $namespaces,
    CacheBackendInterface $cache_backend,
    ModuleHandlerInterface $module_handler
  ) {
+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Drupal\documentation_generator\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Traversable;

/**
 * Provides the Documentation Generator Render plugin manager.
@@ -24,7 +23,7 @@ class DocumentationGeneratorRenderManager extends DefaultPluginManager {
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(
    Traversable $namespaces,
    \Traversable $namespaces,
    CacheBackendInterface $cache_backend,
    ModuleHandlerInterface $module_handler
  ) {