protected function BetterMessagesSettingsForm::buildVisibility in Better Messages 8
Generate form elements for visibility controls.
Parameters
array $form: Form array chunk where the genreated visibility controls will be embedded
\Drupal\Core\Form\FormStateInterface $form_state: Form state that corresponds to $form
Return value
array Form elements for visibility controls
1 call to BetterMessagesSettingsForm::buildVisibility()
- BetterMessagesSettingsForm::buildForm in src/
Form/ BetterMessagesSettingsForm.php - Form constructor.
File
- src/
Form/ BetterMessagesSettingsForm.php, line 316
Class
- BetterMessagesSettingsForm
- Admin settings form of the module.
Namespace
Drupal\better_messages\FormCode
protected function buildVisibility($form, FormStateInterface $form_state) {
$form['#tree'] = TRUE;
$form['visibility_tabs'] = [
'#type' => 'vertical_tabs',
'#title' => $this
->t('Visibility'),
'#parents' => [
'visibility_tabs',
],
];
$visibility = $this
->config($this
->getEditableConfigNames()[0])
->get('visibility');
foreach ($this->conditionManager
->getDefinitionsForContexts($form_state
->getTemporaryValue('gathered_contexts')) as $condition_id => $definition) {
/** @var \Drupal\Core\Condition\ConditionInterface $condition */
$condition = $this->conditionManager
->createInstance($condition_id, isset($visibility[$condition_id]) ? $visibility[$condition_id] : []);
$form_state
->set([
'conditions',
$condition_id,
], $condition);
$condition_form = $condition
->buildConfigurationForm([], $form_state);
$condition_form['#type'] = 'details';
$condition_form['#title'] = $condition
->getPluginDefinition()['label'];
$condition_form['#group'] = 'visibility_tabs';
$form[$condition_id] = $condition_form;
}
// The "current_theme" condition is very raw, and has bugs:
// https://www.drupal.org/node/2787529 and
// https://www.drupal.org/node/2787529
// so we prefer to ditch it.
unset($form['current_theme']);
if (isset($form['request_path'])) {
$form['request_path']['#title'] = $this
->t('Pages');
$form['request_path']['negate']['#type'] = 'radios';
$form['request_path']['negate']['#default_value'] = (int) $form['request_path']['negate']['#default_value'];
$form['request_path']['negate']['#title_display'] = 'invisible';
$form['request_path']['negate']['#options'] = [
$this
->t('Show for the listed pages'),
$this
->t('Hide for the listed pages'),
];
}
return $form;
}