class ConstraintFactory
Same name in other branches
- 9 core/lib/Drupal/Core/Validation/ConstraintFactory.php \Drupal\Core\Validation\ConstraintFactory
- 10 core/lib/Drupal/Core/Validation/ConstraintFactory.php \Drupal\Core\Validation\ConstraintFactory
Constraint plugin factory.
Symfony Constraint plugins are created as Drupal plugins, but the default plugin constructor is not compatible.
Hierarchy
- class \Drupal\Component\Plugin\Factory\DefaultFactory implements \Drupal\Component\Plugin\Factory\FactoryInterface
- class \Drupal\Core\Plugin\Factory\ContainerFactory extends \Drupal\Component\Plugin\Factory\DefaultFactory
- class \Drupal\Core\Validation\ConstraintFactory extends \Drupal\Core\Plugin\Factory\ContainerFactory
- class \Drupal\Core\Plugin\Factory\ContainerFactory extends \Drupal\Component\Plugin\Factory\DefaultFactory
Expanded class hierarchy of ConstraintFactory
File
-
core/
lib/ Drupal/ Core/ Validation/ ConstraintFactory.php, line 15
Namespace
Drupal\Core\ValidationView source
class ConstraintFactory extends ContainerFactory {
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = []) {
$plugin_definition = $this->discovery
->getDefinition($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition, $this->interface);
// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, ContainerFactoryPluginInterface::class)) {
return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
}
// If the plugin is a Symfony Constraint, use the correct constructor.
if (is_subclass_of($plugin_class, Constraint::class)) {
return new $plugin_class($configuration);
}
// Otherwise, create the plugin as normal.
return new $plugin_class($configuration, $plugin_id, $plugin_definition);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ConstraintFactory::createInstance | public | function | Overrides ContainerFactory::createInstance | ||
DefaultFactory::$discovery | protected | property | The object that retrieves the definitions of the plugins that this factory instantiates. | ||
DefaultFactory::$interface | protected | property | Defines an interface each plugin should implement. | ||
DefaultFactory::getPluginClass | public static | function | Finds the class relevant for a given plugin. | 1 | |
DefaultFactory::__construct | public | function | Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.