57d2915e9041d0c5432b7f286411c0b803eb247c
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / LoadMultiple.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 = "_load_multiple",
12  *  deriver = "\Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions\LoadMultipleDeriver"
13  * )
14  */
15 class LoadMultiple extends FunctionCallModifier {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function rewrite(FunctionCallNode $call, TargetInterface $target) {
21     $arguments = $call->getArguments();
22
23     // If there were three arguments, the call is affecting the internal
24     // entity cache. Unfortunately, it's pretty much impossible to reliably
25     // determine whether or not they wanted to reset the cache, so let's just
26     // leave a FIXME.
27     if (sizeof($arguments) == 3) {
28       $variables = [
29         '!entity_type' => $this->pluginDefinition['entity_type'],
30       ];
31       $this->buildFixMe('To reset the !entity_type cache, use EntityStorageInterface::resetCache().', $variables)->insertBefore($call);
32     }
33
34     $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager')
35       ->appendMethodCall('getStorage')
36       ->appendArgument($this->pluginDefinition['entity_type']);
37
38     // If there's more than one argument, conditions were passed (not a
39     // recommended practice, but modules might have done it anyway), in which
40     // case we need to use loadByProperties(). Otherwise, loadMultiple().
41     if (sizeof($arguments) > 1) {
42       return $rewritten
43         ->appendMethodCall('loadByProperties')
44         ->appendArgument(clone $arguments[1]);
45     }
46     else {
47       return $rewritten
48         ->appendMethodCall('loadMultiple')
49         ->appendArgument(clone $arguments[0]);
50     }
51   }
52
53 }