Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PluginExistsConstraint.php

class PluginExistsConstraint

Checks if a plugin exists and optionally implements a particular interface.

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Drupal\Core\Plugin\Plugin\Validation\Constraint\PluginExistsConstraint extends \Symfony\Component\Validator\Constraint implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface

Expanded class hierarchy of PluginExistsConstraint

File

core/lib/Drupal/Core/Plugin/Plugin/Validation/Constraint/PluginExistsConstraint.php, line 18

Namespace

Drupal\Core\Plugin\Plugin\Validation\Constraint
View source
class PluginExistsConstraint extends SymfonyConstraint implements ContainerFactoryPluginInterface {
    
    /**
     * The error message if a plugin does not exist.
     *
     * @var string
     */
    public string $unknownPluginMessage = "The '@plugin_id' plugin does not exist.";
    
    /**
     * The error message if a plugin does not implement the expected interface.
     *
     * @var string
     */
    public string $invalidInterfaceMessage = "The '@plugin_id' plugin must implement or extend @interface.";
    
    /**
     * The ID of the plugin manager service.
     *
     * @var string
     */
    protected string $manager;
    
    /**
     * Optional name of the interface that the plugin must implement.
     *
     * @var string|null
     */
    public ?string $interface = NULL;
    
    /**
     * Whether or not to consider fallback plugin IDs as valid.
     *
     * @var bool
     */
    public bool $allowFallback = FALSE;
    
    /**
     * Constructs a PluginExistsConstraint.
     *
     * @param \Drupal\Component\Plugin\PluginManagerInterface $pluginManager
     *   The plugin manager associated with the constraint.
     * @param mixed|null $options
     *   The options (as associative array) or the value for the default option
     *   (any other type).
     * @param array|null $groups
     *   An array of validation groups.
     * @param mixed|null $payload
     *   Domain-specific data attached to a constraint.
     */
    public function __construct(PluginManagerInterface $pluginManager, mixed $options = NULL, ?array $groups = NULL, mixed $payload = NULL) {
        parent::__construct($options, $groups, $payload);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        $plugin_manager_id = $configuration['manager'] ?? $configuration['value'] ?? NULL;
        if ($plugin_manager_id === NULL) {
            throw new MissingOptionsException(sprintf('The option "manager" must be set for constraint "%s".', static::class), [
                'manager',
            ]);
        }
        return new static($container->get($plugin_manager_id), $configuration);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDefaultOption() : ?string {
        return 'manager';
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRequiredOptions() : array {
        return [
            'manager',
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::ERROR_NAMES protected constant Maps error codes to the names of their constants. 59
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
PluginExistsConstraint::$allowFallback public property Whether or not to consider fallback plugin IDs as valid.
PluginExistsConstraint::$interface public property Optional name of the interface that the plugin must implement.
PluginExistsConstraint::$invalidInterfaceMessage public property The error message if a plugin does not implement the expected interface.
PluginExistsConstraint::$manager protected property The ID of the plugin manager service.
PluginExistsConstraint::$unknownPluginMessage public property The error message if a plugin does not exist.
PluginExistsConstraint::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PluginExistsConstraint::getDefaultOption public function Returns the name of the default option. Overrides Constraint::getDefaultOption
PluginExistsConstraint::getRequiredOptions public function Returns the name of the required options. Overrides Constraint::getRequiredOptions
PluginExistsConstraint::__construct public function Constructs a PluginExistsConstraint. Overrides Constraint::__construct
RSS feed
Powered by Drupal