3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Objects\ClassMethodCallNode;
11 * id = "_load_multiple",
12 * deriver = "\Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions\LoadMultipleDeriver"
15 class LoadMultiple extends FunctionCallModifier {
20 public function rewrite(FunctionCallNode $call, TargetInterface $target) {
21 $arguments = $call->getArguments();
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
27 if (sizeof($arguments) == 3) {
29 '!entity_type' => $this->pluginDefinition['entity_type'],
31 $this->buildFixMe('To reset the !entity_type cache, use EntityStorageInterface::resetCache().', $variables)->insertBefore($call);
34 $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager')
35 ->appendMethodCall('getStorage')
36 ->appendArgument($this->pluginDefinition['entity_type']);
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) {
43 ->appendMethodCall('loadByProperties')
44 ->appendArgument(clone $arguments[1]);
48 ->appendMethodCall('loadMultiple')
49 ->appendArgument(clone $arguments[0]);