class CommandGcuSubscriber in Update helper 2.x
Same name and namespace in other branches
- 8 modules/update_helper_checklist/src/Events/CommandGcuSubscriber.php \Drupal\update_helper_checklist\Events\CommandGcuSubscriber
Subscriber for "generate:configuration:update" command.
Hierarchy
- class \Drupal\update_helper_checklist\Events\CommandGcuSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of CommandGcuSubscriber
1 string reference to 'CommandGcuSubscriber'
- drush.services.yml in modules/
update_helper_checklist/ drush.services.yml - modules/update_helper_checklist/drush.services.yml
1 service uses CommandGcuSubscriber
- update_helper_checklist.command_gcu_subscriber in modules/
update_helper_checklist/ drush.services.yml - Drupal\update_helper_checklist\Events\CommandGcuSubscriber
File
- modules/
update_helper_checklist/ src/ Events/ CommandGcuSubscriber.php, line 18
Namespace
Drupal\update_helper_checklist\EventsView source
class CommandGcuSubscriber implements EventSubscriberInterface {
/**
* Key for update version option.
*
* @var string
*/
protected static $updateVersionName = 'update_version';
/**
* Key for update description.
*
* @var string
*/
protected static $updateDescription = 'update_description';
/**
* Key for success message command option.
*
* @var string
*/
protected static $successMessageName = 'success_message';
/**
* Key for failure message command option.
*
* @var string
*/
protected static $failureMessageName = 'failure_message';
/**
* Update checklist service.
*
* @var \Drupal\update_helper_checklist\UpdateChecklist
*/
protected $updateChecklist;
/**
* Drupal\Core\Extension\ModuleHandler definition.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected $moduleHandler;
/**
* CommandGcuSubscriber constructor.
*
* @param \Drupal\update_helper_checklist\UpdateChecklist $update_checklist
* Update checklist service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(UpdateChecklist $update_checklist, ModuleHandlerInterface $module_handler) {
$this->updateChecklist = $update_checklist;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
UpdateHelperEvents::COMMAND_GCU_INTERACT => [
[
'onInteract',
10,
],
],
UpdateHelperEvents::COMMAND_GCU_EXECUTE => [
[
'onExecute',
10,
],
],
];
}
/**
* Handle on interactive mode for getting command options.
*
* @param \Drupal\update_helper\Events\CommandInteractEvent $interact_event
* Event.
*/
public function onInteract(CommandInteractEvent $interact_event) {
$update_versions = $this->updateChecklist
->getUpdateVersions($interact_event
->getVars()['module']);
// Set internal pointer to end, to get last update version.
end($update_versions);
$questions[static::$updateVersionName] = new Question('Please enter a update version for checklist collection', empty($update_versions) ? '8.x-1.0' : current($update_versions));
$questions[static::$updateDescription] = new Question('Please enter a detailed update description that will be used for checklist', 'This configuration update will update site configuration to newly provided configuration');
$questions[static::$successMessageName] = new Question('Please enter a detailed update description that will be used for checklist', 'Configuration is successfully updated.');
$questions[static::$failureMessageName] = new Question('Please enter a message that will be displayed in checklist entry when the update has failed', 'Update of configuration has failed.');
$interact_event
->setQuestions($questions);
}
/**
* Handles configuration update generation.
*
* @param \Drupal\update_helper\Events\CommandExecuteEvent $execute_event
* Event.
*/
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');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandGcuSubscriber:: |
protected static | property | Key for failure message command option. | |
CommandGcuSubscriber:: |
protected | property | Drupal\Core\Extension\ModuleHandler definition. | |
CommandGcuSubscriber:: |
protected static | property | Key for success message command option. | |
CommandGcuSubscriber:: |
protected | property | Update checklist service. | |
CommandGcuSubscriber:: |
protected static | property | Key for update description. | |
CommandGcuSubscriber:: |
protected static | property | Key for update version option. | |
CommandGcuSubscriber:: |
public static | function | ||
CommandGcuSubscriber:: |
public | function | Handles configuration update generation. | |
CommandGcuSubscriber:: |
public | function | Handle on interactive mode for getting command options. | |
CommandGcuSubscriber:: |
public | function | CommandGcuSubscriber constructor. |