UserAccess.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Functions/UserAccess.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\Objects\ObjectMethodCallNode;
use Pharborist\Variables\VariableNode;
class UserAccess extends FunctionCallModifier {
public function rewrite(FunctionCallNode $call, TargetInterface $target) {
$arguments = $call
->getArguments();
if (isset($arguments[1]) && $arguments[1] instanceof VariableNode) {
$rewritten = ObjectMethodCallNode::create(clone $arguments[1], 'hasPermission');
}
else {
$rewritten = ClassMethodCallNode::create('\\Drupal', 'currentUser')
->appendMethodCall('hasPermission');
}
return $rewritten
->appendArgument(clone $arguments[0]);
}
}
Classes
Name |
Description |
UserAccess |
Plugin annotation
@Converter(
id = "user_access",
description = @Translation("Rewrites calls to user_access().")
) |