You are here

private function LayouterForm::buildResponseHtml in Layouter - WYSIWYG layout templates 8

Builds HTML that will be added to textarea.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Return value

null Content for output.

1 call to LayouterForm::buildResponseHtml()
LayouterForm::ajaxResponse in src/Form/LayouterForm.php
Ajax callback prints rebuilded form.

File

src/Form/LayouterForm.php, line 335

Class

LayouterForm
Provides multistep ajax form for an layout choice.

Namespace

Drupal\layouter\Form

Code

private function buildResponseHtml(FormStateInterface $form_state) {
  $content = [
    '#theme' => $this->templates[$form_state
      ->get('type')]['theme'],
  ];
  $fields = $form_state
    ->get('fields');
  foreach ($fields as $field_name => $fiels_params) {
    switch ($fiels_params['type']) {
      case 'image':
        $image_fid = $form_state
          ->getValue($field_name)[0];
        $image = File::load($image_fid);
        $image
          ->setPermanent();
        $image
          ->save();
        $image_style = $form_state
          ->getValue($field_name . '_style');
        if ($image_style == 'none') {
          $image_content = [
            '#theme' => 'image',
          ];
        }
        else {
          $image_content = [
            '#theme' => 'image_style',
            '#style_name' => $image_style,
          ];
        }
        $image_content['#uri'] = $image
          ->getFileUri();
        $image_content['#alt'] = $form_state
          ->getValue($field_name . '_alt');
        $content['#' . $field_name] = render($image_content);
        break;
      case 'text':
        $content['#' . $field_name] = $form_state
          ->getValue($field_name);
        break;
    }
  }
  return render($content);
}