public function TestTextColorBehavior::validateBehaviorForm

Validates the behavior fields form.

This method is responsible for validating the data in the behavior fields form and displaying validation messages.

Parameters

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ParagraphsBehaviorBase::validateBehaviorForm

File

paragraphs/tests/modules/paragraphs_test/src/Plugin/paragraphs/Behavior/TestTextColorBehavior.php, line 79

Class

TestTextColorBehavior
Provides a test feature plugin.

Namespace

Drupal\paragraphs_test\Plugin\paragraphs\Behavior

Code

public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('text_color') != 'blue' && $form_state
    ->getValue('text_color') != 'red') {
    $form_state
      ->setError($form, 'The only allowed values are blue and red.');
  }
}