/**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $violations = [];
     $indexer = $target->getIndexer('function');
     if ($indexer->has('hook_form_alter')) {
         $violations[] = $indexer->get('hook_form_alter');
     }
     $id = $target->id() . '_form_%_alter';
     // Until kernel tests are run in PHPUnit, we need to check for
     // the existence of db_like().
     if (function_exists('db_like')) {
         $id = db_like($id);
     }
     $alter_hooks = $target->getIndexer('function')->getQuery()->condition('id', $id, 'LIKE')->execute();
     foreach ($alter_hooks as $alter_hook) {
         $violations[] = $target->open($alter_hook->file)->find(Filter::isFunction($alter_hook->id));
     }
     $issues = [];
     if ($violations) {
         $issue = $this->buildIssue($target);
         array_walk($violations, function (FunctionDeclarationNode $function) use($issue) {
             $issue->addViolation($function, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $total = 0;
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalWebTestCase')->countQuery()->execute();
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalUnitTestCase')->countQuery()->execute();
     $total += $target->getIndexer('class')->getQuery()->condition('parent', 'DrupalTestBase')->countQuery()->execute();
     if ($total) {
         $issues[] = $this->buildIssue($target);
     }
     return $issues;
 }
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
        $function = $target->getIndexer('function')->get('hook_user_login');
        // The $edit parameter is defunct in Drupal 8, but we'll leave it in
        // there as an empty array to prevent errors, and move it to the back
        // of the line.
        /** @var \Pharborist\Functions\ParameterNode $edit */
        $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(ArrayNode::create([]));
        $function->appendParameter($edit);
        // Slap a FIXME on the hook implementation, informing the developer that
        // $edit and $category are dead.
        $comment = $function->getDocComment();
        $comment_text = $comment ? $comment->getCommentText() : '';
        if ($comment_text) {
            $comment_text .= "\n\n";
        }
        $comment_text .= <<<'END'
@FIXME
The $edit parameter is gone in Drupal 8. It has been left here in order to
prevent 'undefined variable' errors, but it will never actually be passed to
this hook. You'll need to modify this function and remove every reference to it.
END;
        $function->setDocComment(DocCommentNode::create($comment_text));
        $rewriter = $this->rewriters->createInstance('_rewriter:user');
        $this->rewriteFunction($rewriter, $function->getParameterAtIndex(0), $target);
        $target->save($function);
    }
    /**
     * {@inheritdoc}
     */
    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);
            // The $edit parameter is defunct in Drupal 8, but we'll leave it in
            // there as an empty array to prevent errors, and move it to the back
            // of the line.
            /** @var \Pharborist\Functions\ParameterNode $edit */
            $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(NullNode::create());
            $function->appendParameter($edit);
            // Slap a FIXME on the hook implementation, informing the developer that
            // $edit and $category are dead.
            $comment = $function->getDocComment();
            $comment_text = $comment ? $comment->getCommentText() : '';
            if ($comment_text) {
                $comment_text .= "\n\n";
            }
            $comment_text .= <<<'END'
@FIXME
The $edit and $category parameters are gone in Drupal 8. They have been left
here in order to prevent 'undefined variable' errors, but they will never
actually be passed to this hook. You'll need to modify this function and
remove every reference to them.
END;
            $function->setDocComment(DocCommentNode::create($comment_text));
            $this->rewriteFunction($this->rewriter, $function->getParameterAtIndex(0), $target);
            $target->save($function);
        }
    }
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        $unit_tests = [];
        $test_files = $target->getIndexer('class')->getQuery(['file'])->condition('parent', 'DrupalUnitTestCase')->execute()->fetchCol();
        foreach ($test_files as $test_file) {
            /** @var \Pharborist\Objects\Classnode[] $tests */
            $tests = $target->open($test_file)->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))->toArray();
            foreach ($tests as $test) {
                if ((string) $test->getExtends() === 'DrupalUnitTestCase') {
                    $unit_tests[] = $test;
                }
            }
        }
        /** @var \Pharborist\Objects\ClassNode $unit_test */
        foreach ($unit_tests as $unit_test) {
            $unit_test->setExtends('\\Drupal\\Tests\\UnitTestCase');
            $comment_text = <<<END
@FIXME
Unit tests are now written for the PHPUnit framework. You will need to refactor
this test in order for it to work properly.
END;
            $comment = DocCommentNode::create($comment_text);
            $unit_test->setDocComment($comment);
            $ns = 'Drupal\\Tests\\' . $target->id() . '\\Unit';
            $doc = RootNode::create($ns)->getNamespace($ns)->append($unit_test->remove());
            WhitespaceNode::create("\n\n")->insertBefore($unit_test);
            $this->write($target, 'tests/src/Unit/' . $unit_test->getName() . '.php', "<?php\n\n{$doc}");
        }
    }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // Prevent stupid effing 'undefined index' notices.
     $function = @($this->pluginDefinition['function'] ?: $this->getPluginId());
     $function_calls = $target->getIndexer('function_call')->get($function);
     foreach ($function_calls as $function_call) {
         // If the function call is no longer attached to a tree, don't even
         // try to rewrite it. This could happen when there are two calls to
         // the same function in a single statement, and the first one has
         // been commented out -- the second one will be attached to an orphaned
         // sub-tree, and this will result in fatal errors.
         if (!$function_call->hasRoot()) {
             continue;
         }
         $rewritten = $this->rewrite($function_call, $target);
         if (empty($rewritten)) {
             $statement = $function_call->getStatement();
             $rewritten = $statement->toComment();
             $statement->replaceWith($rewritten);
             $this->buildFixMe()->insertBefore($rewritten);
         } elseif ($rewritten !== $function_call) {
             $function_call->replaceWith($rewritten);
         }
         $target->save($rewritten);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // If the hook implementation contains logic, we cannot convert it and
     // that's that. So we'll leave a FIXME and bail out.
     /** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
     $hook = $target->getIndexer('function')->get('hook_menu');
     if ($hook->is(new ContainsLogicFilter())) {
         $hook->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
         $target->save($hook);
         return;
     }
     $hook_menu = new HookMenu($target, $this->routeConverters);
     foreach ($hook_menu->getSourceRoutes() as $path => $route) {
         /** @var \Drupal\drupalmoduleupgrader\Routing\Drupal7\RouteWrapper $route */
         if ($route->containsKey('page callback')) {
             $plugin_id = $this->routeConverters->hasDefinition($route['page callback']) ? $route['page callback'] : 'default';
             /** @var \Drupal\drupalmoduleupgrader\Routing\RouteConverterInterface $converter */
             $this->routeConverters->createInstance($plugin_id)->buildRoute($target, $route);
         }
     }
     $routing = [];
     foreach ($hook_menu->getDestinationRoutes() as $name => $route) {
         $routing[$name] = ['path' => $route->getPath()->__toString(), 'defaults' => $route->getDefaults(), 'requirements' => $route->getRequirements()];
     }
     $this->writeInfo($target, 'routing', $routing);
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $indexer = $target->getIndexer('function');
     if ($indexer->hasExecutable('hook_permission')) {
         $issues[] = $this->buildIssue($target)->addViolation($indexer->get('hook_permission'), $this)->addFix('hook_to_YAML', ['hook' => 'permission', 'destination' => '~/' . $target->id() . '.permissions.yml']);
     }
     return $issues;
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $issues = [];
     $class_count = $target->getIndexer('class')->getQuery()->condition('type', 'Pharborist\\Objects\\ClassNode')->countQuery()->execute()->fetchField();
     if ($class_count > 0) {
         $issues[] = $this->buildIssue($target);
     }
     return $issues;
 }
 /**
  * Creates a FormConverter for a specific form.
  *
  * @param TargetInterface $target
  *  The module which defines the form.
  * @param string $form_id
  *  The original form ID.
  *
  * @return FormConverter
  *
  * @throws \BadMethodCallException if the target module doesn't define
  * the given form.
  */
 public function get(TargetInterface $target, $form_id)
 {
     $indexer = $target->getIndexer('function');
     if ($indexer->has($form_id)) {
         return new FormConverter($target, $form_id, $this->rewriter);
     } else {
         $message = $this->t('@target does not define form @form_id.', ['@target' => $target->id(), '@form_id' => $form_id]);
         throw new \BadMethodCallException($message);
     }
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $hook = 'hook_' . $this->pluginDefinition['hook'];
     $indexer = $target->getIndexer('function');
     if ($indexer->has($hook)) {
         return [$this->buildIssue($target)->addViolation($indexer->get($hook), $this)];
     } else {
         return [];
     }
 }
Esempio n. 12
0
 /**
  * Constructs a HookMenu object.
  *
  * @param \Drupal\drupalmoduleupgrader\TargetInterface $target
  *  The target module.
  * @param \Drupal\Component\Plugin\PluginManagerInterface $route_converters
  *   The route converters.
  */
 public function __construct(TargetInterface $target, PluginManagerInterface $route_converters)
 {
     $this->target = $target;
     $this->routeConverters = $route_converters;
     // If the hook_menu() implementation doesn't exist, get the implementation
     // from the indexer and eval it into existence. It's the calling code's
     // responsibility to ensure that the implementation doesn't contain anything
     // which will blow up on execution.
     $hook = $target->id() . '_menu';
     if (!function_exists($hook)) {
         eval($target->getIndexer('function')->get('hook_menu')->getText());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function_call');
     $issues = [];
     if ($indexer->has($this->pluginDefinition['function'])) {
         $issue = $this->buildIssue($target);
         $indexer->get($this->pluginDefinition['function'])->each(function (FunctionCallNode $function_call) use($issue) {
             $issue->addViolation($function_call, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function');
     // @FIXME This is not working (returns empty result set)...don't know why.
     $alter_hooks = $indexer->getQuery()->condition(db_or()->condition('id', $target->id() . '_form_alter')->condition('id', db_like($target->id() . '_form_%_alter'), 'LIKE'))->execute();
     foreach ($alter_hooks as $alter_hook) {
         /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
         $function = $indexer->get($alter_hook->id);
         $parameters = $function->getParameters();
         if (sizeof($parameters) > 1) {
             $parameters[1]->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
             $target->save($function);
         }
     }
 }
 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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
     $function = $target->getIndexer('function')->get('hook_node_prepare');
     // foo_node_prepare() --> foo_node_prepare_form().
     $function->setName($function->getName() . '_form');
     // The first parameter is a node, so rewrite the function accordingly.
     $this->rewriters->createInstance('_entity:node')->rewrite($function->getParameterAtIndex(0));
     // Create the $operation parameter.
     $function->appendParameter(ParameterNode::create('operation'));
     // Create the $form_state parameter.
     $form_state = ParameterNode::create('form_state')->setTypeHint('\\Drupal\\Core\\Form\\FormStateInterface');
     $function->appendParameter($form_state);
     $target->save($function);
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $function_calls = $target->getIndexer('function_call')->get($this->pluginDefinition['function'] ?: $this->getPluginId())->filter(function (FunctionCallNode $function_call) {
         $arguments = $function_call->getArguments();
         return $arguments[0] instanceof StringNode && in_array($arguments[0]->toValue(), self::$forbiddenTables);
     });
     $issues = [];
     if ($function_calls->count() > 0) {
         $issue = $this->buildIssue($target);
         $function_calls->each(function (FunctionCallNode $function_call) use($issue) {
             $issue->addViolation($function_call, $this);
         });
         $issues[] = $issue;
     }
     return $issues;
 }
 /**
  * {@inheritdoc}
  */
 public function analyze(TargetInterface $target)
 {
     $indexer = $target->getIndexer('function');
     $issues = [];
     if ($indexer->has('hook_uninstall')) {
         /** @var \Pharborist\NodeCollection $variable_del */
         $variable_del = $indexer->get('hook_uninstall')->find(Filter::isFunctionCall('variable_del'));
         if (sizeof($variable_del) > 0) {
             $issue = $this->buildIssue($target);
             $variable_del->each(function (FunctionCallNode $function_call) use($issue) {
                 $issue->addViolation($function_call, $this);
             });
             $issues[] = $issue;
         }
     }
     return $issues;
 }
 public function __construct(TargetInterface $target, $form_id, RewriterInterface $rewriter)
 {
     $indexer = $target->getIndexer('function');
     $this->target = $target;
     $this->formID = $form_id;
     $this->builder = $indexer->get($form_id);
     $validator = $form_id . '_validate';
     if ($indexer->has($validator)) {
         $this->validator = $indexer->get($validator);
     }
     $submit_handler = $form_id . '_submit';
     if ($indexer->has($submit_handler)) {
         $this->submitHandler = $indexer->get($submit_handler);
     }
     $this->isConfig = $this->builder->has(Filter::isFunctionCall('system_settings_form'));
     $this->formStateRewriter = $rewriter;
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $this->target = $target;
     $mapping = ['DrupalWebTestCase' => 'convertWeb', 'AJAXTestCase' => 'convertAjax'];
     foreach ($mapping as $parent_class => $convert_method) {
         $test_files = $target->getIndexer('class')->getQuery(['file'])->condition('parent', $parent_class)->execute()->fetchCol();
         foreach ($test_files as $test_file) {
             /** @var \Pharborist\Objects\Classnode[] $tests */
             $tests = $target->open($test_file)->find(Filter::isInstanceOf('\\Pharborist\\Objects\\SingleInheritanceNode'))->toArray();
             foreach ($tests as $test) {
                 if ((string) $test->getExtends() === $parent_class) {
                     $this->{$convert_method}($test);
                 }
             }
         }
     }
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     // If the hook implementation contains logic, we cannot convert it and
     // that's that. So we'll leave a FIXME and bail out.
     /** @var \Pharborist\Functions\FunctionDeclarationNode $hook */
     $hook = $target->getIndexer('function')->get('hook_menu');
     if ($hook->is(new ContainsLogicFilter())) {
         $hook->setDocComment(DocCommentNode::create($this->pluginDefinition['fixme']));
         $target->save($hook);
         return;
     }
     // Links are split out by group because there are separate config files
     // for each link type.
     $links = ['menu' => new LinkIndex(), 'task' => new LinkIndex(), 'action' => new LinkIndex(), 'contextual' => new LinkIndex()];
     $hook_menu = new HookMenu($target, $this->routeConverters);
     foreach ($hook_menu->getSourceRoutes()->getAllLinks() as $path => $source) {
         /** @var LinkBinding $binding */
         $binding = $this->linkBinding->create($source, $hook_menu->getDestinationRoute($path));
         // Skip if the converter wasn't able to find a destination.
         $destination = $binding->getDestination();
         if (empty($destination)) {
             continue;
         }
         if ($binding instanceof MenuLinkBinding) {
             $links['menu']->addBinding($binding);
         } elseif ($binding instanceof LocalTaskLinkBinding) {
             $links['task']->addBinding($binding);
         } elseif ($binding instanceof LocalActionLinkBinding) {
             $links['action']->addBinding($binding);
         } elseif ($source->isContextualLink()) {
             $links['contextual']->addBinding($binding);
         }
     }
     $links = array_map(function (LinkIndex $index) {
         return $index->build();
     }, $links);
     foreach ($links['contextual'] as $link) {
         $link['group'] = $target->id();
     }
     foreach ($links as $group => $data) {
         if ($data) {
             $this->writeInfo($target, 'links.' . $group, $data);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $target->getIndexer('function')->get($this->pluginDefinition['hook'])->setDocComment($this->buildFixMe(NULL, [], self::DOC_COMMENT));
     $render = ['#theme' => 'dmu_route_subscriber', '#module' => $target->id()];
     $this->writeClass($target, $this->parse($render));
     $alterable = ParameterNode::create('data');
     $alterable->setTypeHint('array')->setReference(TRUE);
     $parameter = clone $alterable;
     $this->implement($target, 'menu_links_discovered_alter')->appendParameter($parameter->setName('links'));
     $parameter = clone $alterable;
     $this->implement($target, 'menu_local_tasks_alter')->appendParameter($parameter->setName('data'))->appendParameter(ParameterNode::create('route_name'));
     $parameter = clone $alterable;
     $this->implement($target, 'menu_local_actions_alter')->appendParameter($parameter->setName('local_actions'));
     $parameter = clone $alterable;
     $items = clone $alterable;
     $function = $this->implement($target, 'contextual_links_view_alter')->appendParameter($parameter->setName('element'))->appendParameter($items->setName('items')->setReference(FALSE));
     $target->save($function);
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target, $hook = NULL, $index = 0, $rewriter_id = NULL)
 {
     $indexer = $target->getIndexer('function');
     if (isset($hook)) {
         if ($indexer->has($hook)) {
             if (empty($rewriter_id)) {
                 // Extract the entity type from the hook (e.g. 'hook_node_delete').
                 preg_match('/^hook_(.+)_[a-z]+$/', $hook, $matches);
                 $rewriter_id = '_rewriter:' . $matches[1];
             }
             $rewriter = $this->rewriters->createInstance($rewriter_id);
             $this->rewriteFunction($rewriter, $indexer->get($hook)->getParameterAtIndex($index), $target);
         }
     } else {
         $this->convert($target, 'hook_comment_delete');
         $this->convert($target, 'hook_comment_insert');
         $this->convert($target, 'hook_comment_presave');
         $this->convert($target, 'hook_comment_update');
         $this->convert($target, 'hook_node_access');
         $this->convert($target, 'hook_node_access', 2, '_rewriter:account');
         $this->convert($target, 'hook_node_access_records', 0, '_rewriter:node');
         $this->convert($target, 'hook_node_access_records_alter', 1, '_rewriter:node');
         $this->convert($target, 'hook_node_delete');
         $this->convert($target, 'hook_node_grants', 0, '_rewriter:account');
         $this->convert($target, 'hook_node_grants_alter', 1, '_rewriter:account');
         $this->convert($target, 'hook_node_insert');
         $this->convert($target, 'hook_node_presave');
         $this->convert($target, 'hook_node_revision_delete');
         $this->convert($target, 'hook_node_search_result');
         $this->convert($target, 'hook_node_submit');
         $this->convert($target, 'hook_node_submit', 2, 'form_state');
         $this->convert($target, 'hook_node_update');
         $this->convert($target, 'hook_node_update_index');
         $this->convert($target, 'hook_node_validate');
         $this->convert($target, 'hook_node_validate', 2, 'form_state');
         $this->convert($target, 'hook_taxonomy_term_delete');
         $this->convert($target, 'hook_taxonomy_term_insert');
         $this->convert($target, 'hook_taxonomy_term_presave');
         $this->convert($target, 'hook_taxonomy_term_update');
         $this->convert($target, 'hook_user_delete');
         $this->convert($target, 'hook_user_logout');
     }
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     foreach ($this->configuration['function_calls'] as $function => $replace_with) {
         $function_calls = $target->getIndexer('function_call')->get($function);
         foreach ($function_calls as $function_call) {
             $rewritten = str_ireplace($function, $replace_with, $function_call->getText());
             $node = Parser::parseExpression($rewritten);
             $function_call->replaceWith($node);
             $target->save($node);
         }
     }
     // Flush other open syntax trees to ensure that other plugins don't clobber
     // our changes later.
     $target->flush();
     foreach ($target->getFinder() as $file) {
         // Load in the entire contents of the module. This is criminally inefficient
         // and wasteful of memory and should eventually be refactored into something
         // a little more...I dunno, sustainable.
         /** @var \Symfony\Component\Finder\SplFileInfo $file */
         $search = array_keys($this->targets);
         $replace = array_values($this->targets);
         file_put_contents($file->getPathname(), str_replace($search, $replace, $file->getContents()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $hook = $target->getIndexer('function')->get($this->pluginDefinition['hook'])->before(DocCommentNode::create($this->pluginDefinition['fixme']));
     $target->save($hook);
 }
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $hook = $target->getIndexer('function')->get($this->pluginDefinition['hook'])->setName($target->id() . '_entity_bundle_create');
     $target->save($hook);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRouteDefinition(TargetInterface $target, Drupal7Route $route)
 {
     $indexer = $target->getIndexer('function');
     $definition = new CoreRoute('');
     $this->buildParameterMap($target, $route)->applyRoute($definition);
     $controller = $this->getController($target, $route)->getName()->getAbsolutePath();
     if ($route->containsKey('title')) {
         $definition->setDefault('_title', $route['title']);
     } elseif ($indexer->has($route['title callback'])) {
         $definition->setDefault('_title_callback', $controller . '::' . $route['title callback']);
     }
     if ($route->isAbsoluteAccess()) {
         $definition->setRequirement('_access', $route['access callback'] ? 'true' : 'false');
     } elseif ($route->isPermissionBased()) {
         $definition->setRequirement('_permission', $route['access arguments'][0]);
     } elseif ($indexer->has($route['access callback'])) {
         $definition->setRequirement('_custom_access', $controller . '::' . $route['access callback']);
     }
     if ($indexer->has($route['page callback'])) {
         $definition->setDefault('_controller', $controller . '::' . $route['page callback']);
     }
     return new Drupal8Route($this->getName($target, $route), $definition, $this->routeProvider);
 }
Esempio n. 28
0
 /**
  * {@inheritdoc}
  */
 public function convert(TargetInterface $target)
 {
     $target->getIndexer('class')->getAll()->each(function (ClassNode $class) use($target) {
         $this->writeClass($target, self::toPSR4($target, $class));
     });
 }
Esempio n. 29
0
 /**
  * Slaps a translated FIXME notice above a block-related hook.
  *
  * @param TargetInterface $target
  *  The target module.
  * @param string $hook
  *  The hook to put the FIXME on. It's up to the calling code to ensure
  *  that the hook actually exists.
  */
 private function addFixMe(TargetInterface $target, $hook)
 {
     $variables = ['!hook' => $hook];
     $function = $target->getIndexer('function')->get('hook_' . $hook)->setDocComment($this->buildFixMe(NULL, $variables, self::DOC_COMMENT));
     $target->save($function);
 }
 /**
  * Parametrically rewrites a function.
  *
  * @param \Drupal\drupalmoduleupgrader\RewriterInterface $rewriter
  *  A fully configured parametric rewriter.
  * @param \Pharborist\Functions\ParameterNode $parameter
  *  The parameter upon which to base the rewrite.
  * @param TargetInterface $target
  *  The target module.
  * @param boolean $recursive
  *  If TRUE, rewriting will recurse into called functions which are passed
  *  the rewritten parameter as an argument.
  */
 protected function rewriteFunction(RewriterInterface $rewriter, ParameterNode $parameter, TargetInterface $target, $recursive = TRUE)
 {
     $rewriter->rewrite($parameter);
     $target->save($parameter);
     // Find function calls within the rewritten function which are called
     // with the rewritten parameter.
     $indexer = $target->getIndexer('function');
     $next = $parameter->getFunction()->find(new FunctionCallArgumentFilter($parameter->getName()))->filter(function (FunctionCallNode $call) use($indexer) {
         return $indexer->has($call->getName()->getText());
     });
     /** @var \Pharborist\Functions\FunctionCallNode $call */
     foreach ($next as $call) {
         /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
         $function = $indexer->get($call->getName()->getText());
         foreach ($call->getArguments() as $index => $argument) {
             if ($argument instanceof VariableNode && $argument->getName() == $parameter->getName()) {
                 $this->rewriteFunction($rewriter, $function->getParameterAtIndex($index), $target, $recursive);
                 break;
             }
         }
     }
 }