You are here

public function CToolsGetPlugins::rewrite in Drupal 7 to 8/9 Module Upgrader 8

Tries to rewrite the original function call.

Parameters

\Pharborist\Functions\FunctionCallNode $call: The original function call.

\Drupal\drupalmoduleupgrader\TargetInterface $target: The target module.

Return value

\Pharborist\Node|null If the original function call is returned (determined by object identity), the function call is not replaced. If a different node is returned, it will replace the original call. And if nothing is returned, the original call is commented out with a FIXME.

Overrides FunctionCallModifier::rewrite

File

src/Plugin/DMU/Converter/Functions/CToolsGetPlugins.php, line 38

Class

CToolsGetPlugins
Plugin annotation @Converter( id = "ctools_get_plugins", description = @Translation("Rewrites calls to ctools_get_plugins().") )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions

Code

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');
}