You are here

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

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

Handles configuration update generation.

Parameters

\Drupal\update_helper\Events\CommandExecuteEvent $execute_event: Event.

File

modules/update_helper_checklist/src/Events/CommandGcuSubscriber.php, line 113

Class

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

Namespace

Drupal\update_helper_checklist\Events

Code

public function onExecute(CommandExecuteEvent $execute_event) {
  $vars = $execute_event
    ->getVars();
  $module_path = $this->moduleHandler
    ->getModule($vars['module'])
    ->getPath();
  $checklist_file = $module_path . DIRECTORY_SEPARATOR . UpdateChecklist::$updateChecklistFileName;
  $update_versions = $this->updateChecklist
    ->getUpdateVersions($vars['module']);
  end($update_versions);
  $last_update_version = current($update_versions);
  $vars['update_hook_name'] = ConfigurationUpdate::getUpdateFunctionName($vars['module'], $vars['update-n']);
  $vars['update_version'] = $vars[static::$updateVersionName] === $last_update_version ? '' : $vars[static::$updateVersionName];
  $vars['file_exists'] = file_exists($checklist_file);

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