getDefaultConstraints example

public function getClass() {
    // Derive list class from the field type.     $type_definition = \Drupal::service('plugin.manager.field.field_type')
      ->getDefinition($this->getType());
    return $type_definition['list_class'];
  }

  /** * {@inheritdoc} */
  public function getConstraints() {
    return \Drupal::typedDataManager()->getDefaultConstraints($this) + $this->constraints;
  }

  /** * {@inheritdoc} */
  public function getConstraint($constraint_name) {
    $constraints = $this->getConstraints();
    return $constraints[$constraint_name] ?? NULL;
  }

  /** * {@inheritdoc} */

  public function setSetting($setting_name$value) {
    $this->definition['settings'][$setting_name] = $value;
    return $this;
  }

  /** * {@inheritdoc} */
  public function getConstraints() {
    $constraints = $this->definition['constraints'] ?? [];
    $constraints += $this->getTypedDataManager()->getDefaultConstraints($this);
    return $constraints;
  }

  /** * {@inheritdoc} */
  public function getConstraint($constraint_name) {
    $constraints = $this->getConstraints();
    return $constraints[$constraint_name] ?? NULL;
  }

  
Home | Imprint | This part of the site doesn't use cookies.