You are here

class CommandSubscriber in Update helper 2.x

Same name and namespace in other branches
  1. 8 src/Events/CommandSubscriber.php \Drupal\update_helper\Events\CommandSubscriber

Subscriber for "generate:configuration:update" command.

Hierarchy

  • class \Drupal\update_helper\Events\CommandSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CommandSubscriber

1 string reference to 'CommandSubscriber'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses CommandSubscriber
update_helper_checklist.command_subscriber in ./drush.services.yml
Drupal\update_helper\Events\CommandSubscriber

File

src/Events/CommandSubscriber.php, line 13

Namespace

Drupal\update_helper\Events
View source
class CommandSubscriber implements EventSubscriberInterface {

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Command subscriber class.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler service.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      UpdateHelperEvents::COMMAND_GCU_EXECUTE => [
        [
          'onExecute',
          10,
        ],
      ],
    ];
  }

  /**
   * Handles execute for configuration update generation to create update hook.
   *
   * @param \Drupal\update_helper\Events\CommandExecuteEvent $execute_event
   *   Command execute event.
   */
  public function onExecute(CommandExecuteEvent $execute_event) {
    $vars = $execute_event
      ->getVars();
    $module_path = $this->moduleHandler
      ->getModule($vars['module'])
      ->getPath();
    $update_file = $module_path . '/' . $vars['module'] . '.install';
    $vars['update_hook_name'] = ConfigurationUpdate::getUpdateFunctionName($vars['module'], $vars['update-n']);
    $vars['file_exists'] = file_exists($update_file);

    // Add the update hook template.
    $asset = (new Asset())
      ->type('file')
      ->vars($vars)
      ->path($update_file)
      ->action('append')
      ->template('configuration_update_hook.php.twig');
    $execute_event
      ->addAsset($asset);
    $execute_event
      ->addTemplatePath(__DIR__ . '/../../templates');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandSubscriber::$moduleHandler protected property The module handler service.
CommandSubscriber::getSubscribedEvents public static function
CommandSubscriber::onExecute public function Handles execute for configuration update generation to create update hook.
CommandSubscriber::__construct public function Command subscriber class.