You are here

public function CommandSubscriber::onExecute in Update helper 2.x

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

Handles execute for configuration update generation to create update hook.

Parameters

\Drupal\update_helper\Events\CommandExecuteEvent $execute_event: Command execute event.

File

src/Events/CommandSubscriber.php, line 49

Class

CommandSubscriber
Subscriber for "generate:configuration:update" command.

Namespace

Drupal\update_helper\Events

Code

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');
}