Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / FlagHookDeriver.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
4
5 use Drupal\Core\StringTranslation\TranslationInterface;
6 use Drupal\drupalmoduleupgrader\DeriverBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 class FlagHookDeriver extends DeriverBase {
10
11   /**
12    * @var array
13    */
14   protected $config;
15
16   public function __construct(TranslationInterface $translator, array $config) {
17     parent::__construct($translator);
18     $this->config = $config;
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public static function create(ContainerInterface $container, $base_plugin_id) {
25     return new static(
26       $container->get('string_translation'),
27       $container->get('config.factory')->get('drupalmoduleupgrader.hooks')->get('definitions')
28     );
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getDerivativeDefinitions($base_definition) {
35     $derivatives = [];
36
37     foreach ($this->config as $key => $info) {
38       if (empty($info['hook'])) {
39         $info['hook'] = [$key];
40       }
41
42       foreach ($info['hook'] as $hook) {
43         $variables = ['@hook' => 'hook_' . $hook . '()'];
44
45         $derivative = array_merge($base_definition, $info);
46         $derivative['hook'] = $hook;
47         $derivative['message'] = $this->t($info['message'], $variables);
48         $derivative['description'] = $this->t('Analyzes implementations of @hook.', $variables);
49         foreach ($derivative['documentation'] as &$doc) {
50           $doc['title'] = $this->t($doc['title'], $variables);
51         }
52
53         $derivatives[$hook] = $derivative;
54       }
55     }
56
57     return $derivatives;
58   }
59
60 }