Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / NodeLoad.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
9 /**
10  * @Converter(
11  *  id = "node_load",
12  *  description = @Translation("Rewrites calls to node_load()."),
13  *  fixme = @Translation("node_load() is now EntityStorageInterface::load().")
14  * )
15  */
16 class NodeLoad extends FunctionCallModifier {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function rewrite(FunctionCallNode $call, TargetInterface $target) {
22     $arguments = $call->getArguments();
23
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);
30     }
31
32     $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager')
33       ->appendMethodCall('getStorage')
34       ->appendArgument('node');
35
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) {
39       return $rewritten
40         ->appendMethodCall('loadRevision')
41         ->appendArgument(clone $arguments[1]);
42     }
43     else {
44       return $rewritten
45         ->appendMethodCall('load')
46         ->appendArgument(clone $arguments[0]);
47     }
48   }
49
50 }