getArguments(); // If there were three arguments, the call is affecting the internal // entity 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) == 3) { $variables = [ '!entity_type' => $this->pluginDefinition['entity_type'], ]; $this->buildFixMe('To reset the !entity_type cache, use EntityStorageInterface::resetCache().', $variables)->insertBefore($call); } $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager') ->appendMethodCall('getStorage') ->appendArgument($this->pluginDefinition['entity_type']); // If there's more than one argument, conditions were passed (not a // recommended practice, but modules might have done it anyway), in which // case we need to use loadByProperties(). Otherwise, loadMultiple(). if (sizeof($arguments) > 1) { return $rewritten ->appendMethodCall('loadByProperties') ->appendArgument(clone $arguments[1]); } else { return $rewritten ->appendMethodCall('loadMultiple') ->appendArgument(clone $arguments[0]); } } }