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); } } }