3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Objects\ClassMethodCallNode;
8 use Pharborist\Types\ArrayNode;
13 * description = @Translation("Rewrites calls to entity_load().")
16 class EntityLoad 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 // entity cache. Unfortunately, it's pretty much impossible to reliably
26 // determine whether or not they wanted to reset the cache, so let's just
28 if (sizeof($arguments) == 3) {
29 $this->buildFixMe('To reset the entity cache, use EntityStorageInterface::resetCache().')->insertBefore($call);
32 $rewritten = ClassMethodCallNode::create('\Drupal', 'entityManager')
33 ->appendMethodCall('getStorage')
34 ->appendArgument(clone $arguments[0]);
36 // If there's a third argument, conditions were passed. Not a recommended
37 // practice, but certain modules might have done it anyway. If we detect
38 // conditions, use loadByProperties().
39 if (sizeof($arguments) > 2) {
41 ->appendMethodCall('loadByProperties')
42 ->appendArgument(clone $arguments[2]);
45 $rewritten->appendMethodCall('load');
47 if (sizeof($arguments) > 1 && $arguments[1] instanceof ArrayNode) {
48 $rewritten->appendArgument(clone $arguments[1]);