public function ParagraphsTypeForm::validateForm

File

paragraphs/src/Form/ParagraphsTypeForm.php, line 167

Class

ParagraphsTypeForm
Form controller for paragraph type forms.

Namespace

Drupal\paragraphs\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $paragraphs_type = $this->entity;
  $icon_file = $form_state
    ->getValue([
    'icon_file',
    '0',
  ]);

  // Set the icon file UUID and default value to the paragraph configuration.
  if (!empty($icon_file) && ($file = $this->entityTypeManager
    ->getStorage('file')
    ->load($icon_file))) {
    $paragraphs_type
      ->set('icon_uuid', $file
      ->uuid());
    $paragraphs_type
      ->set('icon_default', 'data:' . $file
      ->getMimeType() . ';base64,' . base64_encode(file_get_contents($file
      ->getFileUri())));
  }
  else {
    $paragraphs_type
      ->set('icon_uuid', NULL);
    $paragraphs_type
      ->set('icon_default', NULL);
  }
  if ($behavior_plugin_definitions = $this->paragraphsBehaviorManager
    ->getApplicableDefinitions($paragraphs_type)) {
    foreach ($behavior_plugin_definitions as $id => $behavior_plugin_definition) {

      // Only validate if the plugin is enabled and has settings.
      if (isset($form['behavior_plugins'][$id]['settings']) && $form_state
        ->getValue([
        'behavior_plugins',
        $id,
        'enabled',
      ])) {
        $subform_state = SubformState::createForSubform($form['behavior_plugins'][$id]['settings'], $form, $form_state);
        $behavior_plugin = $paragraphs_type
          ->getBehaviorPlugin($id);
        $behavior_plugin
          ->validateConfigurationForm($form['behavior_plugins'][$id]['settings'], $subform_state);
      }
    }
  }
}