EntityTypeConstraint.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
  2. 10 core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php

Namespace

Drupal\Core\Entity\Plugin\Validation\Constraint

File

core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraint.php

View source
<?php

namespace Drupal\Core\Entity\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;

/**
 * Checks if a value is a valid entity type.
 *
 * @Constraint(
 *   id = "EntityType",
 *   label = @Translation("Entity type", context = "Validation"),
 *   type = { "entity", "entity_reference" }
 * )
 */
class EntityTypeConstraint extends Constraint {
    
    /**
     * The default violation message.
     *
     * @var string
     */
    public $message = 'The entity must be of type %type.';
    
    /**
     * The entity type option.
     *
     * @var string
     */
    public $type;
    
    /**
     * {@inheritdoc}
     */
    public function getDefaultOption() {
        return 'type';
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRequiredOptions() {
        return [
            'type',
        ];
    }

}

Classes

Title Deprecated Summary
EntityTypeConstraint Checks if a value is a valid entity type.

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