You are here

public function TextOverlayImageEffect::validateConfigurationForm in Image Effects 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::validateConfigurationForm()
  2. 8.2 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::validateConfigurationForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides ConfigurableImageEffectBase::validateConfigurationForm

File

src/Plugin/ImageEffect/TextOverlayImageEffect.php, line 668

Class

TextOverlayImageEffect
Overlays text on the image, defining text font, size and positioning.

Namespace

Drupal\image_effects\Plugin\ImageEffect

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);

  // @todo the array syntax for $form_state->getValue([...]) fails code
  // style checking, but this is quite inconvenient. See if sniff gets
  // adjusted or a different way to access nested keys will be available.
  // @codingStandardsIgnoreStart
  // Get x-y position from the anchor element.
  list($x_pos, $y_pos) = explode('-', $form_state
    ->getValue([
    'layout',
    'position',
    'placement',
  ]));
  $this->configuration = [
    'font' => [
      'name' => $form_state
        ->hasValue([
        'font',
        'uri',
      ]) ? $this->fontSelector
        ->getDescription($form_state
        ->getValue([
        'font',
        'uri',
      ])) : NULL,
      'uri' => $form_state
        ->getValue([
        'font',
        'uri',
      ]),
      'size' => $form_state
        ->getValue([
        'font',
        'size',
      ]),
      'angle' => $form_state
        ->getValue([
        'font',
        'angle',
      ]),
      'color' => $form_state
        ->getValue([
        'font',
        'color',
      ]),
      'stroke_mode' => $form_state
        ->getValue([
        'font',
        'stroke',
        'mode',
      ]),
      'stroke_color' => $form_state
        ->getValue([
        'font',
        'stroke',
        'color',
      ]),
      'outline_top' => $form_state
        ->getValue([
        'font',
        'stroke',
        'top',
      ]),
      'outline_right' => $form_state
        ->getValue([
        'font',
        'stroke',
        'right',
      ]),
      'outline_bottom' => $form_state
        ->getValue([
        'font',
        'stroke',
        'bottom',
      ]),
      'outline_left' => $form_state
        ->getValue([
        'font',
        'stroke',
        'left',
      ]),
      'shadow_x_offset' => $form_state
        ->getValue([
        'font',
        'stroke',
        'x_offset',
      ]),
      'shadow_y_offset' => $form_state
        ->getValue([
        'font',
        'stroke',
        'y_offset',
      ]),
      'shadow_width' => $form_state
        ->getValue([
        'font',
        'stroke',
        'width',
      ]),
      'shadow_height' => $form_state
        ->getValue([
        'font',
        'stroke',
        'height',
      ]),
    ],
    'layout' => [
      'padding_top' => $form_state
        ->getValue([
        'layout',
        'padding',
        'top',
      ]),
      'padding_right' => $form_state
        ->getValue([
        'layout',
        'padding',
        'right',
      ]),
      'padding_bottom' => $form_state
        ->getValue([
        'layout',
        'padding',
        'bottom',
      ]),
      'padding_left' => $form_state
        ->getValue([
        'layout',
        'padding',
        'left',
      ]),
      'x_pos' => $x_pos,
      'y_pos' => $y_pos,
      'x_offset' => $form_state
        ->getValue([
        'layout',
        'position',
        'x_offset',
      ]),
      'y_offset' => $form_state
        ->getValue([
        'layout',
        'position',
        'y_offset',
      ]),
      'overflow_action' => $form_state
        ->getValue([
        'layout',
        'position',
        'overflow_action',
      ]),
      'extended_color' => $form_state
        ->getValue([
        'layout',
        'position',
        'extended_color',
      ]),
      'background_color' => $form_state
        ->getValue([
        'layout',
        'background_color',
      ]),
    ],
    'text' => [
      'strip_tags' => (bool) $form_state
        ->getValue([
        'text_default',
        'strip_tags',
      ]),
      'decode_entities' => (bool) $form_state
        ->getValue([
        'text_default',
        'decode_entities',
      ]),
      'maximum_width' => $form_state
        ->getValue([
        'text',
        'maximum_width',
      ]),
      'fixed_width' => $form_state
        ->getValue([
        'text',
        'fixed_width',
      ]),
      'align' => $form_state
        ->getValue([
        'text',
        'align',
      ]),
      'case_format' => $form_state
        ->getValue([
        'text',
        'case_format',
      ]),
      'line_spacing' => $form_state
        ->getValue([
        'text',
        'line_spacing',
      ]),
      'maximum_chars' => $form_state
        ->getValue([
        'text',
        'maximum_chars',
      ]),
      'excess_chars_text' => $form_state
        ->getValue([
        'text',
        'excess_chars_text',
      ]),
    ],
    'text_string' => $form_state
      ->getValue([
      'text_default',
      'text_string',
    ]),
  ];

  // @codingStandardsIgnoreEnd
  // Save the updated configuration in a FormState value to enable Ajax
  // preview generation.
  $form_state
    ->setValue([
    'ajax_config',
  ], $this->configuration);
  $form_state
    ->setValue([
    'ajax_config',
    'preview_bar',
    'debug_visuals',
  ], $form_state
    ->getValue([
    'preview_bar',
    'debug_visuals',
  ]));
}