X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FFixer%2FImplementHook.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FFixer%2FImplementHook.php;h=165bf08284bed65c78cfc427ace48824357fd43f;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/ImplementHook.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/ImplementHook.php new file mode 100644 index 000000000..165bf0828 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/ImplementHook.php @@ -0,0 +1,62 @@ +moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('module_handler') + ); + } + + /** + * {@inheritdoc} + */ + 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); + } + +}