Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / UserLoad.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/UserLoad.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/Functions/UserLoad.php
new file mode 100644 (file)
index 0000000..7ff0973
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
+
+use Drupal\drupalmoduleupgrader\TargetInterface;
+use Pharborist\Functions\FunctionCallNode;
+use Pharborist\Objects\ClassMethodCallNode;
+
+/**
+ * @Converter(
+ *  id = "user_load",
+ *  description = @Translation("Rewrites calls to user_load()."),
+ *  fixme = @Translation("user_load() is now EntityStorageInterface::load().")
+ * )
+ */
+class UserLoad extends FunctionCallModifier {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function rewrite(FunctionCallNode $call, TargetInterface $target) {
+    $arguments = $call->getArguments();
+
+    // If there were three arguments, the call is affecting the internal
+    // user_load() 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) == 2) {
+      $this->buildFixMe('To reset the user cache, use EntityStorageInterface::resetCache().')->insertBefore($call);
+    }
+
+    return ClassMethodCallNode::create('\Drupal', 'entityManager')
+      ->appendMethodCall('getStorage')
+      ->appendArgument('user')
+      ->appendMethodCall('load')
+      ->appendArgument(clone $arguments[0]);
+  }
+
+}