You are here

public function L::rewrite in Drupal 7 to 8/9 Module Upgrader 8

Tries to rewrite the original function call.

Parameters

\Pharborist\Functions\FunctionCallNode $call: The original function call.

\Drupal\drupalmoduleupgrader\TargetInterface $target: The target module.

Return value

\Pharborist\Node|null If the original function call is returned (determined by object identity), the function call is not replaced. If a different node is returned, it will replace the original call. And if nothing is returned, the original call is commented out with a FIXME.

Overrides URL::rewrite

File

src/Plugin/DMU/Converter/Functions/L.php, line 24

Class

L
Plugin annotation @Converter( id = "l", description = @Translation("Rewrites calls to l()."), fixme = @Translation("l() expects a Url object, created from a route name or external URI."), dependencies = { "router.route_provider" } )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions

Code

public function rewrite(FunctionCallNode $call, TargetInterface $target) {
  $arguments = $call
    ->getArguments();
  if ($arguments[1] instanceof StringNode) {

    // Create a call to url() and let the parent class rewrite it like normal,
    // so we don't have to duplicate that code.
    $url = Parser::parseSnippet('url(' . $arguments[1] . ');')
      ->firstChild();
    $url_rewritten = parent::rewrite($url, $target);
    if ($url_rewritten) {
      return ClassMethodCallNode::create('\\Drupal\\Core\\Link', 'fromTextAndUrl')
        ->appendArgument($arguments[0])
        ->appendArgument($url_rewritten);
    }
  }
}