function ReflectionFactory::getInstanceArguments

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php \Drupal\Component\Plugin\Factory\ReflectionFactory::getInstanceArguments()
  2. 8.9.x core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php \Drupal\Component\Plugin\Factory\ReflectionFactory::getInstanceArguments()
  3. 10 core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php \Drupal\Component\Plugin\Factory\ReflectionFactory::getInstanceArguments()

Inspects the plugin class and build a list of arguments for the constructor.

This is provided as a helper method so factories extending this class can replace this and insert their own reflection logic.

Parameters

\ReflectionClass $reflector: The reflector object being used to inspect the plugin class.

string $plugin_id: The identifier of the plugin implementation.

mixed $plugin_definition: The definition associated with the plugin_id.

array $configuration: An array of configuration that may be passed to the instance.

Return value

array An array of arguments to be passed to the constructor.

1 call to ReflectionFactory::getInstanceArguments()
ReflectionFactory::createInstance in core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php
Creates a plugin instance based on the provided ID and configuration.

File

core/lib/Drupal/Component/Plugin/Factory/ReflectionFactory.php, line 52

Class

ReflectionFactory
A plugin factory that maps instance configuration to constructor arguments.

Namespace

Drupal\Component\Plugin\Factory

Code

protected function getInstanceArguments(\ReflectionClass $reflector, $plugin_id, $plugin_definition, array $configuration) {
    $arguments = [];
    foreach ($reflector->getMethod('__construct')
        ->getParameters() as $param) {
        $param_name = $param->getName();
        if ($param_name == 'plugin_id') {
            $arguments[] = $plugin_id;
        }
        elseif ($param_name == 'plugin_definition') {
            $arguments[] = $plugin_definition;
        }
        elseif ($param_name == 'configuration') {
            $arguments[] = $configuration;
        }
        elseif (\array_key_exists($param_name, $configuration)) {
            $arguments[] = $configuration[$param_name];
        }
        elseif ($param->isDefaultValueAvailable()) {
            $arguments[] = $param->getDefaultValue();
        }
        else {
            $arguments[] = NULL;
        }
    }
    return $arguments;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.