public static function LegalAdminTermsForm::previewForm in Legal 8
Same name and namespace in other branches
- 2.0.x src/Form/LegalAdminTermsForm.php \Drupal\legal\Form\LegalAdminTermsForm::previewForm()
Form elements to be displayed as a preview of the T&C form.
Parameters
int $style: Style that T&Cs should be displayed as.
array $conditions: 'value' = T&C conditions content. 'format' = Format to render content with.
array $extras: Each item of array to be displayed as label of a checkbox.
bool $modal: Display target of Page Link option as new window or a modal overlay.
Return value
array Returns the contents of the preview form element.
1 call to LegalAdminTermsForm::previewForm()
- LegalAdminTermsForm::preview in src/
Form/ LegalAdminTermsForm.php - Preview section wrapper.
File
- src/
Form/ LegalAdminTermsForm.php, line 518
Class
- LegalAdminTermsForm
- Settings form for administering content of Terms & Conditions.
Namespace
Drupal\legal\FormCode
public static function previewForm($style, array $conditions, array $extras, $modal) {
switch ($style) {
// Scroll box (CSS).
case 1:
$form['#attached']['library'][] = 'legal/css-scroll';
$form['conditions'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'legal-terms',
'legal-terms-scroll',
],
],
];
$form['conditions']['content'] = [
'#type' => 'processed_text',
'#text' => $conditions['value'],
'#format' => isset($conditions['format']) ? $conditions['format'] : filter_default_format(),
];
$accept_label = legal_accept_label();
break;
// HTML.
case 2:
$form['legal_accept']['#title'] = t('<strong>Accept</strong> Terms & Conditions of Use');
$form['conditions'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'legal-terms',
],
],
];
$form['conditions']['content'] = [
'#type' => 'processed_text',
'#text' => $conditions['value'],
'#format' => isset($conditions['format']) ? $conditions['format'] : filter_default_format(),
];
$accept_label = legal_accept_label();
break;
// Page Link.
case 3:
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['#attached']['library'][] = 'core/drupal.ajax';
$form['#attached']['library'][] = 'core/jquery.form';
$form['conditions'] = [
'#markup' => '',
];
$accept_label = legal_accept_label(TRUE, $modal);
break;
// Scroll box (HTML).
default:
$form['conditions'] = [
'#id' => 'preview',
'#name' => 'preview',
'#type' => 'textarea',
'#title' => t('Terms & Conditions'),
'#value' => PlainTextOutput::renderFromHtml($conditions['value']),
'#parents' => [
'legal',
],
'#rows' => 10,
'#attributes' => [
'readonly' => 'readonly',
],
];
$accept_label = legal_accept_label();
}
// Override additional checkboxes in preview.
if (!empty($extras)) {
foreach ($extras as $key => $label) {
if (!empty($label)) {
$form[$key] = [
'#type' => 'checkbox',
'#title' => Xss::filter($label),
];
}
}
}
$form['legal_accept'] = [
'#type' => 'checkbox',
'#title' => $accept_label,
'#default_value' => 0,
'#weight' => 50,
'#required' => TRUE,
];
return $form;
}