function legal_display_fields in Legal 8
Same name and namespace in other branches
- 5 legal.module \legal_display_fields()
- 6.8 legal.module \legal_display_fields()
- 6.7 legal.module \legal_display_fields()
- 7.2 legal.module \legal_display_fields()
- 7 legal.module \legal_display_fields()
- 2.0.x legal.module \legal_display_fields()
Form elements for displaying T&Cs to users.
Parameters
array $form: An associative array containing the structure of the form.
array $conditions: Terms & Conditions to be displayed.
string $action: What user action the form is being used for.
3 calls to legal_display_fields()
- LegalLogin::buildForm in src/
Form/ LegalLogin.php - Form constructor.
- legal_form_user_form_alter in ./
legal.module - Implements hook_form_FORM_ID_alter().
- legal_form_user_register_form_alter in ./
legal.module - Implements hook_form_FORM_ID_alter().
File
- ./
legal.module, line 55 - Module file for Legal.
Code
function legal_display_fields(array &$form, array $conditions, $action) {
$settings = \Drupal::config('legal.settings');
switch ($action) {
case 'registration':
$legal_display = $settings
->get('registration_terms_style');
$legal_display_container = $settings
->get('registration_container');
$modal_terms = $settings
->get('registration_modal_terms');
break;
case 'login':
$legal_display = $settings
->get('login_terms_style');
$legal_display_container = $settings
->get('login_container');
$modal_terms = $settings
->get('login_modal_terms');
break;
}
$form['current_id'] = [
'#type' => 'value',
'#value' => $conditions['version'],
];
$form['language_value'] = [
'#type' => 'value',
'#value' => $conditions['language'],
];
$form['revision_id'] = [
'#type' => 'value',
'#value' => $conditions['revision'],
];
$form['current_date'] = [
'#type' => 'value',
'#value' => $conditions['date'],
];
$form['display'] = [
'#type' => 'value',
'#value' => $legal_display,
];
$form['legal'] = [
'#type' => $legal_display_container ? 'details' : 'markup',
'#title' => $legal_display_container ? t('Terms and Conditions of Use') : '',
'#weight' => 29,
'#open' => TRUE,
];
switch ($legal_display) {
// Scroll box (CSS).
case 1:
$form['#attached']['library'][] = 'legal/css-scroll';
$form['legal']['content'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'legal-terms',
'legal-terms-scroll',
],
],
];
$form['legal']['content']['terms'] = [
'#type' => 'processed_text',
'#text' => $conditions['conditions'],
'#format' => isset($conditions['format']) ? $conditions['format'] : filter_default_format(),
];
$accept_label = legal_accept_label();
break;
// HTML.
case 2:
$form['legal']['legal_accept']['#title'] = t('<strong>Accept</strong> Terms & Conditions of Use');
$form['legal']['conditions'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => [
'legal-terms',
],
],
];
$form['legal']['conditions']['terms'] = [
'#type' => 'processed_text',
'#text' => $conditions['conditions'],
'#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['legal']['conditions'] = [
'#markup' => '',
];
$accept_label = legal_accept_label(TRUE, $modal_terms);
break;
// Scroll box (HTML).
default:
$form['legal']['conditions'] = [
'#type' => 'textarea',
'#title' => t('Terms & Conditions'),
'#default_value' => PlainTextOutput::renderFromHtml($conditions['conditions']),
'#value' => PlainTextOutput::renderFromHtml($conditions['conditions']),
'#rows' => 10,
'#weight' => 0,
'#attributes' => [
'readonly' => 'readonly',
],
];
$accept_label = legal_accept_label();
}
if (!empty($conditions['extras'])) {
foreach ($conditions['extras'] as $key => $label) {
if (!empty($label)) {
$form['legal'][$key] = [
'#type' => 'checkbox',
'#title' => Xss::filter($label),
'#default_value' => 0,
'#weight' => 2,
'#required' => TRUE,
];
}
}
}
$form['legal']['legal_accept'] = [
'#type' => 'checkbox',
'#title' => $accept_label,
'#default_value' => 0,
'#weight' => 50,
'#required' => TRUE,
];
}