class DeletedWorkspaceConstraintValidator

Same name in other branches
  1. 9 core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator
  2. 8.9.x core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator
  3. 11.x core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator

Checks if data still exists for a deleted workspace ID.

Hierarchy

Expanded class hierarchy of DeletedWorkspaceConstraintValidator

File

core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php, line 14

Namespace

Drupal\workspaces\Plugin\Validation\Constraint
View source
class DeletedWorkspaceConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
    
    /**
     * The state service.
     *
     * @var \Drupal\Core\State\StateInterface
     */
    protected $state;
    
    /**
     * Creates a new DeletedWorkspaceConstraintValidator instance.
     *
     * @param \Drupal\Core\State\StateInterface $state
     *   The state service.
     */
    public function __construct(StateInterface $state) {
        $this->state = $state;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('state'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function validate($value, Constraint $constraint) {
        
        /** @var \Drupal\Core\Field\FieldItemListInterface $value */
        // This constraint applies only to newly created workspace entities.
        if (!isset($value) || !$value->getEntity()
            ->isNew()) {
            return;
        }
        $deleted_workspace_ids = $this->state
            ->get('workspace.deleted', []);
        if (isset($deleted_workspace_ids[$value->getEntity()
            ->id()])) {
            $this->context
                ->addViolation($constraint->message);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DeletedWorkspaceConstraintValidator::$state protected property The state service.
DeletedWorkspaceConstraintValidator::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DeletedWorkspaceConstraintValidator::validate public function
DeletedWorkspaceConstraintValidator::__construct public function Creates a new DeletedWorkspaceConstraintValidator instance.

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