X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FHookEntityTypeView.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FHookEntityTypeView.php;h=8bfb9b37e86661d9568675a15d2a217440ec7d4b;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityTypeView.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityTypeView.php new file mode 100644 index 000000000..8bfb9b37e --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityTypeView.php @@ -0,0 +1,54 @@ +rewriters = $rewriters; + } + + public function convert(TargetInterface $target) { + $indexer = $target->getIndexer('function'); + + $hooks = array_filter($this->pluginDefinition['hook'], [$indexer, 'has']); + foreach ($hooks as $hook) { + /** @var \Pharborist\Functions\FunctionDeclarationNode $function */ + $function = $indexer->get($hook); + $function->prependParameter(ParameterNode::create('build')->setTypeHint('array')->setReference(TRUE)); + + // Extract the entity type from the hook name (e.g. 'hook_node_view'). + preg_match('/^hook_(.+)_view$/', $hook, $matches); + $entity_type = $matches[1]; + $rewriter = $this->rewriters->createInstance('_rewriter:' . $entity_type); + $this->rewriteFunction($rewriter, $function->getParameterAtIndex(1), $target); + } + } + +}