View source
<?php
namespace Drupal\prod_check\Plugin\ProdCheck\Modules;
use Drupal;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\prod_check\Plugin\ProdCheck\ProdCheckBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModuleList extends ProdCheckBase {
protected $moduleHandler;
private $moduleList;
private $moduleListRefreshed;
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);
}
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'));
}
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;
}
public function state() {
return $this->moduleListRefreshed;
}
public function severity() {
return $this->processor
->error();
}
public function successMessages() {
return [
'value' => $this
->t('List of modules successfully refreshed'),
'description' => $this
->t('The list of modules has successfully been refreshed.'),
];
}
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.'),
];
}
}