You are here

class FlagHookDeriver in Drupal 7 to 8/9 Module Upgrader 8

Hierarchy

Expanded class hierarchy of FlagHookDeriver

File

src/Plugin/DMU/Analyzer/FlagHookDeriver.php, line 9

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer
View source
class FlagHookDeriver extends DeriverBase {

  /**
   * @var array
   */
  protected $config;
  public function __construct(TranslationInterface $translator, array $config) {
    parent::__construct($translator);
    $this->config = $config;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('string_translation'), $container
      ->get('config.factory')
      ->get('drupalmoduleupgrader.hooks')
      ->get('definitions'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_definition) {
    $derivatives = [];
    foreach ($this->config as $key => $info) {
      if (empty($info['hook'])) {
        $info['hook'] = [
          $key,
        ];
      }
      foreach ($info['hook'] as $hook) {
        $variables = [
          '@hook' => 'hook_' . $hook . '()',
        ];
        $derivative = array_merge($base_definition, $info);
        $derivative['hook'] = $hook;
        $derivative['message'] = $this
          ->t($info['message'], $variables);
        $derivative['description'] = $this
          ->t('Analyzes implementations of @hook.', $variables);
        foreach ($derivative['documentation'] as &$doc) {
          $doc['title'] = $this
            ->t($doc['title'], $variables);
        }
        $derivatives[$hook] = $derivative;
      }
    }
    return $derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
FlagHookDeriver::$config protected property
FlagHookDeriver::create public static function Creates a new class instance. Overrides DeriverBase::create
FlagHookDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
FlagHookDeriver::__construct public function Overrides DeriverBase::__construct
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.