3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Objects\ClassMethodCallNode;
12 * description = @Translation("Rewrites calls to node_load()."),
13 * fixme = @Translation("node_load() is now EntityStorageInterface::load().")
16 class NodeLoad extends FunctionCallModifier {
21 public function rewrite(FunctionCallNode $call, TargetInterface $target) {
22 $arguments = $call->getArguments();
24 // If there were three arguments, the call is affecting the internal
25 // node_load() cache. Unfortunately, it's pretty much impossible to
26 // reliably determine whether or not they wanted to reset the cache,
27 // so let's just leave a FIXME.
28 if (sizeof($arguments) == 3) {
29 $this->buildFixMe('To reset the node cache, use EntityStorageInterface::resetCache().')->insertBefore($call);
32 $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager')
33 ->appendMethodCall('getStorage')
34 ->appendArgument('node');
36 // If there's more than one argument, a revision ID was passed, which
37 // means we call loadRevision($nid). Otherwise, call load($nid).
38 if (sizeof($arguments) > 1) {
40 ->appendMethodCall('loadRevision')
41 ->appendArgument(clone $arguments[1]);
45 ->appendMethodCall('load')
46 ->appendArgument(clone $arguments[0]);