class CommandSubscriber in Update helper 2.x
Same name and namespace in other branches
- 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'
1 service uses CommandSubscriber
File
- src/
Events/ CommandSubscriber.php, line 13
Namespace
Drupal\update_helper\EventsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandSubscriber:: |
protected | property | The module handler service. | |
CommandSubscriber:: |
public static | function | ||
CommandSubscriber:: |
public | function | Handles execute for configuration update generation to create update hook. | |
CommandSubscriber:: |
public | function | Command subscriber class. |