You are here

public static function LegalAdminTermsForm::preview in Legal 8

Same name and namespace in other branches
  1. 2.0.x src/Form/LegalAdminTermsForm.php \Drupal\legal\Form\LegalAdminTermsForm::preview()

Preview section wrapper.

Parameters

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

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

Return value

array Returns the preview section form element.

File

src/Form/LegalAdminTermsForm.php, line 458

Class

LegalAdminTermsForm
Settings form for administering content of Terms & Conditions.

Namespace

Drupal\legal\Form

Code

public static function preview(array &$form, FormStateInterface $form_state) {
  $conditions = $form_state
    ->getValue('conditions');
  $extra_checkboxes = $form_state
    ->getValue('extras');
  $element['preview_section']['preview'] = [
    '#type' => 'container',
    '#tree' => TRUE,
    '#attributes' => [
      'id' => [
        'legal-preview',
      ],
    ],
  ];

  // Preview the registration form.
  $element['preview_section']['preview']['registration']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Registration'),
  ];
  $style = $form_state
    ->getValue('registration_terms_style');
  $modal = $form_state
    ->getValue('registration_modal_terms');
  $element['preview_section']['preview']['registration']['form'] = LegalAdminTermsForm::previewForm($style, $conditions, $extra_checkboxes, $modal);

  // Override accept checkbox requirement on preview.
  $element['preview_section']['preview']['registration']['form']['legal_accept']['#required'] = FALSE;

  // Preview the login form.
  $element['preview_section']['preview']['login']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => t('Login'),
  ];
  $style = $form_state
    ->getValue('login_terms_style');
  $modal = $form_state
    ->getValue('login_modal_terms');
  $element['preview_section']['preview']['login']['form'] = LegalAdminTermsForm::previewForm($style, $conditions, $extra_checkboxes, $modal);

  // Override accept checkbox requirement on preview.
  $element['preview_section']['preview']['login']['form']['legal_accept']['#required'] = FALSE;
  return $element;
}