getByFields example

$violations = [];
    foreach ($this->entityViolationOffsets as $offset) {
      $violations[] = $this->get($offset);
    }
    return new static($this->entity, $violations);
  }

  /** * {@inheritdoc} */
  public function getByField($field_name) {
    return $this->getByFields([$field_name]);
  }

  /** * {@inheritdoc} */
  public function getByFields(array $field_names) {
    $this->groupViolationOffsets();
    $violations = [];
    foreach (array_intersect_key($this->violationOffsetsByField, array_flip($field_names)) as $offsets) {
      foreach ($offsets as $offset) {
        $violations[] = $this->get($offset);
      }
/** * {@inheritdoc} */
  protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {
    // Manually flag violations of fields not handled by the form display. This     // is necessary as entity form displays only flag violations for fields     // contained in the display.     $field_names = [
      'label',
      'id',
    ];
    foreach ($violations->getByFields($field_names) as $violation) {
      [$field_name] = explode('.', $violation->getPropertyPath(), 2);
      $form_state->setErrorByName($field_name$violation->getMessage());
    }
    parent::flagViolations($violations$form$form_state);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $workspace = $this->entity;
    
    // is necessary as entity form displays only flag violations for fields     // contained in the display.     $field_names = [
      'name',
      'pass',
      'mail',
      'timezone',
      'langcode',
      'preferred_langcode',
      'preferred_admin_langcode',
    ];
    foreach ($violations->getByFields($field_names) as $violation) {
      [$field_name] = explode('.', $violation->getPropertyPath(), 2);
      $form_state->setErrorByName($field_name$violation->getMessage());
    }
    parent::flagViolations($violations$form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

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