EntityLoad.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Functions/EntityLoad.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Pharborist\Functions\FunctionCallNode;
use Pharborist\Objects\ClassMethodCallNode;
use Pharborist\Types\ArrayNode;
class EntityLoad extends FunctionCallModifier {
public function rewrite(FunctionCallNode $call, TargetInterface $target) {
$arguments = $call
->getArguments();
if (sizeof($arguments) == 3) {
$this
->buildFixMe('To reset the entity cache, use EntityStorageInterface::resetCache().')
->insertBefore($call);
}
$rewritten = ClassMethodCallNode::create('\\Drupal', 'entityTypeManager')
->appendMethodCall('getStorage')
->appendArgument(clone $arguments[0]);
if (sizeof($arguments) > 2) {
return $rewritten
->appendMethodCall('loadByProperties')
->appendArgument(clone $arguments[2]);
}
else {
$rewritten
->appendMethodCall('load');
if (sizeof($arguments) > 1 && $arguments[1] instanceof ArrayNode) {
$rewritten
->appendArgument(clone $arguments[1]);
}
return $rewritten;
}
}
}
Classes
Name |
Description |
EntityLoad |
Plugin annotation
@Converter(
id = "entity_load",
description = @Translation("Rewrites calls to entity_load().")
) |