CToolsGetPlugins.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Functions/CToolsGetPlugins.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\StringNode;
class CToolsGetPlugins extends FunctionCallModifier {
public function canRewrite(FunctionCallNode $call, TargetInterface $target) {
$arguments = $call
->getArguments();
return $arguments[0] instanceof StringNode && $arguments[0]
->toValue() == $target
->id() && $arguments[1] instanceof StringNode;
}
public function rewrite(FunctionCallNode $call, TargetInterface $target) {
if (!$this
->canRewrite($call, $target)) {
return NULL;
}
$arguments = $call
->getArguments();
$plugin_owner = $arguments[0]
->toValue();
$plugin_type = $arguments[1]
->toValue();
$services = $target
->getServices();
$service_id = 'plugin.manager.' . $plugin_owner . '.' . $plugin_type;
$services
->set($service_id, [
'class' => 'Drupal\\Core\\Plugin\\DefaultPluginManager',
'arguments' => [
'Plugin/' . $plugin_owner . '/' . $plugin_type,
'@container.namespaces',
'@module_handler',
'Drupal\\Component\\Plugin\\PluginBase',
'Drupal\\Component\\Annotation\\Plugin',
],
]);
$this
->writeInfo($target, 'services', [
'services' => $services
->toArray(),
]);
return ClassMethodCallNode::create('\\Drupal', 'service')
->appendArgument($service_id)
->appendMethodCall('getDefinitions');
}
}
Classes
Name |
Description |
CToolsGetPlugins |
Plugin annotation
@Converter(
id = "ctools_get_plugins",
description = @Translation("Rewrites calls to ctools_get_plugins().")
) |