public function ImplementHook::execute in Drupal 7 to 8/9 Module Upgrader 8
Executes the plugin.
Overrides ExecutableInterface::execute
File
- src/
Plugin/ DMU/ Fixer/ ImplementHook.php, line 41
Class
- ImplementHook
- Plugin annotation @Fixer( id = "implement_hook" )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\FixerCode
public function execute() {
$this->moduleHandler
->loadInclude($this->configuration['module'], 'php', 'api');
$hook = $this->configuration['hook'];
$function = FunctionDeclarationNode::create($this->target
->id() . '_' . $hook);
$function
->setDocComment(DocCommentNode::create('Implements hook_' . $hook));
$reflector = new \ReflectionFunction('hook_' . $hook);
$function
->matchReflector($reflector);
$module = $this->target
->getPath('.module');
$doc = $this->target
->open($module)
->append($function);
$this->target
->save($doc);
}