ImageEffectEditForm example

/** * Tests that validation errors are passed from the plugin to the parent form. */
  public function testEffectFormValidationErrors() {
    $form_builder = $this->container->get('form_builder');

    /** @var \Drupal\image\ImageStyleInterface $image_style */
    $image_style = ImageStyle::create(['name' => 'foo']);
    $effect_id = $image_style->addImageEffect(['id' => 'image_scale']);
    $image_style->save();

    $form = new ImageEffectEditForm();
    $form_state = (new FormState())->setValues([
      'data' => ['width' => '', 'height' => ''],
    ]);
    $form_builder->submitForm($form$form_state$image_style$effect_id);

    $errors = $form_state->getErrors();
    $this->assertCount(1, $errors);
    $error = reset($errors);
    $this->assertEquals('Width and height can not both be blank.', $error);
  }

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