You are here

public function CommentLoad::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 FunctionCallModifier::rewrite

File

src/Plugin/DMU/Converter/Functions/CommentLoad.php, line 21

Class

CommentLoad
Plugin annotation @Converter( id = "comment_load", description = @Translation("Rewrites calls to comment_load()."), fixme = @Translation("comment_load() is now EntityStorageInterface::load().") )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions

Code

public function rewrite(FunctionCallNode $call, TargetInterface $target) {
  $arguments = $call
    ->getArguments();

  // If there were three arguments, the call is affecting the internal
  // comment_load() cache. Unfortunately, it's pretty much impossible to
  // reliably determine whether or not they wanted to reset the cache,
  // so let's just leave a FIXME.
  if (sizeof($arguments) == 2) {
    $this
      ->buildFixMe('To reset the comment cache, use EntityStorageInterface::resetCache().')
      ->insertBefore($call);
  }
  return ClassMethodCallNode::create('\\Drupal', 'entityTypeManager')
    ->appendMethodCall('getStorage')
    ->appendArgument('comment')
    ->appendMethodCall('load')
    ->appendArgument(clone $arguments[0]);
}