validateForm() does not adhere to definition of ContentEntityFormInterface's validateForm()

Created on 15 February 2022, over 3 years ago
Updated 21 June 2024, 11 months ago

We had a bug on our website and it turns out it was linked to Sheduled Transitions not following an interface it implements.

ScheduledTransitionAddForm's validateForm() implements ContentEntityFormInterface's validateForm() but it does not return a ContentEntityInterface, as ContentEntityFormInterface's validateForm() dictates it should. Rather, it returns nothing.

In my opinion validateForm() should be:

public function validateForm(array &$form, FormStateInterface $form_state): ContentEntityInterface {
  $entity = parent::validateForm($form, $form_state);

  if (empty($form_state->getValue('revision'))) {
    $form_state->setError($form['scheduled_transitions']['revision'], $this->t('Revision must be selected.'));
  }

  return $entity;
}

instead of just:

public function validateForm(array &$form, FormStateInterface $form_state): void {
  if (empty($form_state->getValue('revision'))) {
    $form_state->setError($form['scheduled_transitions']['revision'], $this->t('Revision must be selected.'));
  }
}
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium Jeroen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024