Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / L.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
4
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Objects\ClassMethodCallNode;
8 use Pharborist\Parser;
9 use Pharborist\Types\StringNode;
10
11 /**
12  * @Converter(
13  *  id = "l",
14  *  description = @Translation("Rewrites calls to l()."),
15  *  fixme = @Translation("l() expects a Url object, created from a route name or external URI."),
16  *  dependencies = { "router.route_provider" }
17  * )
18  */
19 class L extends URL {
20
21   /**
22    * {@inheritdoc}
23    */
24   public function rewrite(FunctionCallNode $call, TargetInterface $target) {
25     $arguments = $call->getArguments();
26     if ($arguments[1] instanceof StringNode) {
27       // Create a call to url() and let the parent class rewrite it like normal,
28       // so we don't have to duplicate that code.
29       $url = Parser::parseSnippet('url(' . $arguments[1] . ');')->firstChild();
30       $url_rewritten = parent::rewrite($url, $target);
31       if ($url_rewritten) {
32         return ClassMethodCallNode::create('\Drupal', 'l')
33           ->appendArgument($arguments[0])
34           ->appendArgument($url_rewritten);
35       }
36     }
37   }
38
39 }