You are here

class ModuleList in Production check & Production monitor 8

Returns a list of installed modules (and their updates).

Plugin annotation


@ProdCheck(
  id = "modulelist",
  title = @Translation("Module List"),
  category = "modules",
)

Hierarchy

Expanded class hierarchy of ModuleList

File

src/Plugin/ProdCheck/Modules/ModuleList.php, line 28
Contains \Drupal\prod_check\Plugin\ProdCheck\Modules\ModuleList.

Namespace

Drupal\prod_check\Plugin\ProdCheck\Modules
View source
class ModuleList extends ProdCheckBase {

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The list of installed modules and their updates.
   *
   * @var array
   */
  private $moduleList;

  /**
   * Indicates if the list of installed modules and their updates has been
   * refreshed.
   *
   * @var bool
   */
  private $moduleListRefreshed;

  /**
   * DatabaseUpdates constructor.
   *
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @param \Drupal\Core\Routing\RedirectDestinationInterface $destination
   * @param \Drupal\Core\Utility\LinkGeneratorInterface $generator
   * @param \Drupal\Core\Config\ConfigFactoryInterface $factory
   * @param \Drupal\Core\Datetime\DateFormatter $formatter
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $handler
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $destination, LinkGeneratorInterface $generator, ConfigFactoryInterface $factory, DateFormatter $formatter, ModuleHandlerInterface $handler) {
    $this->moduleHandler = $handler;
    parent::__construct($configuration, $plugin_id, $plugin_definition, $destination, $generator, $factory, $formatter, $handler);
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @return static
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('redirect.destination'), $container
      ->get('link_generator'), $container
      ->get('config.factory'), $container
      ->get('date.formatter'), $container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function init() {
    $build = array(
      '#theme' => 'update_report',
    );
    if (!function_exists('update_get_available')) {
      return $build;
    }
    if ($available = update_get_available(TRUE)) {
      $this->moduleHandler
        ->loadInclude('update', 'compare.inc');
      $private_key = Drupal::service('private_key')
        ->get();
      $build['#data'] = [
        'projects' => update_calculate_project_data($available),
        'site_key' => $private_key,
        'last_update' => (int) $_SERVER['REQUEST_TIME'],
      ];
      $this->moduleListRefreshed = TRUE;
      $this->moduleList = $build['#data'];
    }
    return $build;
  }
  public function data() {
    return $this->moduleList;
  }

  /**
   * Calculates the state for the check.
   *
   * @return bool
   *   TRUE if the check passed
   *   FALSE otherwise
   */
  public function state() {
    return $this->moduleListRefreshed;
  }

  /**
   * {@inheritdoc}
   */
  public function severity() {
    return $this->processor
      ->error();
  }

  /**
   * Returns the success messages for the check.
   *
   * @return array
   *   An associative array containing the following keys
   *     - value: the value of the check
   *     - description: the description of the check
   */
  public function successMessages() {
    return [
      'value' => $this
        ->t('List of modules successfully refreshed'),
      'description' => $this
        ->t('The list of modules has successfully been refreshed.'),
    ];
  }

  /**
   * Returns the fail messages for the check
   *
   * @return array
   *   An associative array containing the following keys
   *     - value: the value of the check
   *     - description: the description of the check
   */
  public function failMessages() {
    return [
      'value' => $this
        ->t('List of modules failed to refresh'),
      'description' => $this
        ->t('An error occurred while refreshing the list of modules.'),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
ModuleList::$moduleHandler protected property Overrides ProdCheckBase::$moduleHandler
ModuleList::$moduleList private property The list of installed modules and their updates.
ModuleList::$moduleListRefreshed private property Indicates if the list of installed modules and their updates has been refreshed.
ModuleList::create public static function Overrides ProdCheckBase::create
ModuleList::data public function Returns the extra data of the check. Overrides ProdCheckBase::data
ModuleList::failMessages public function Returns the fail messages for the check Overrides ProdCheckInterface::failMessages
ModuleList::init public function Initializes the check plugin. Overrides ProdCheckBase::init
ModuleList::severity public function Defines the severity of the check. Overrides ProdCheckBase::severity
ModuleList::state public function Calculates the state for the check. Overrides ProdCheckInterface::state
ModuleList::successMessages public function Returns the success messages for the check. Overrides ProdCheckInterface::successMessages
ModuleList::__construct public function DatabaseUpdates constructor. Overrides ProdCheckBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ProdCheckBase::$configFactory protected property The config factory
ProdCheckBase::$dateFormatter protected property The date formatter service
ProdCheckBase::$destination protected property The redirect destination service.
ProdCheckBase::$linkGenerator protected property The link generator service.
ProdCheckBase::$processor protected property The prod check processor plugin manager.
ProdCheckBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 3
ProdCheckBase::calculateDependencies public function
ProdCheckBase::category public function Returns the title of the check Overrides ProdCheckInterface::category
ProdCheckBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 3
ProdCheckBase::generateDescription protected function Helper function to generate generic 'settings OK' description.
ProdCheckBase::generateLinkArray protected function Helper function to generate link array to pass to the t() function
ProdCheckBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ProdCheckBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ProdCheckBase::setProcessor public function Sets the processor
ProdCheckBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 3
ProdCheckBase::title public function Returns the title of the plugin. Overrides ProdCheckInterface::title
ProdCheckBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
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.