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

Breadcrumb

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

function EntityReferenceSupportedNewEntitiesConstraintValidator::validate

Overrides ConstraintValidatorInterface::validate

File

core/modules/workspaces/src/Plugin/Validation/Constraint/EntityReferenceSupportedNewEntitiesConstraintValidator.php, line 62

Class

EntityReferenceSupportedNewEntitiesConstraintValidator
Checks if new entities created for entity reference fields are supported.

Namespace

Drupal\workspaces\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) : void {
    // The validator should run only if we are in a active workspace context.
    if (!$this->workspaceManager
        ->hasActiveWorkspace()) {
        return;
    }
    $target_entity_type_id = $value->getFieldDefinition()
        ->getFieldStorageDefinition()
        ->getSetting('target_type');
    $target_entity_type = $this->entityTypeManager
        ->getDefinition($target_entity_type_id);
    if ($value->hasNewEntity() && !$this->workspaceInfo
        ->isEntityTypeSupported($target_entity_type)) {
        $this->context
            ->addViolation($constraint->message, [
            '%collection_label' => $target_entity_type->getCollectionLabel(),
        ]);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal