You are here

public function StickynavSettingsForm::buildForm in Sticky Navigation 8

Form constructor.

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 The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/StickynavSettingsForm.php, line 32

Class

StickynavSettingsForm
Build Sticky Navigation settings form.

Namespace

Drupal\stickynav\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $theme = '') {
  $config = $this
    ->config('stickynav.settings.' . $theme);
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable'),
    '#default_value' => $config
      ->get('enabled') ? $config
      ->get('enabled') : FALSE,
  );
  $states = array(
    'visible' => array(
      ':input[name="enabled"]' => array(
        'checked' => TRUE,
      ),
    ),
    'invisible' => array(
      ':input[name="enabled"]' => array(
        'checked' => FALSE,
      ),
    ),
  );

  // Selector is only visible when you activate sticky nav for the theme.
  $form['selector'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Selector'),
    '#description' => $this
      ->t('Place your selector for your menu that will be sticky on your theme. Use jquery format.'),
    '#default_value' => $config
      ->get('selector') ? $config
      ->get('selector') : '',
    '#states' => $states,
  );
  $form['offset'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Offset Selector'),
    '#description' => $this
      ->t('Element to use as an offset. For multiple elements on the page separate them with a comma. Use jquery format.'),
    '#default_value' => $config
      ->get('offset') ? $config
      ->get('offset') : '',
    '#states' => $states,
  );
  $form['custom_offset'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Custom offset'),
    '#description' => $this
      ->t('Custom offset in pixels. This will be added to the elements offsets if they are set.'),
    '#default_value' => $config
      ->get('custom_offset') ? $config
      ->get('custom_offset') : '',
    '#states' => $states,
  );
  $role_options = array();
  $roles = user_roles();
  foreach ($roles as $role) {
    $role_options[$role
      ->id()] = $role
      ->label();
  }
  $form['roles'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Excluded Roles'),
    '#description' => $this
      ->t("Exclude specific roles from using sticky navigation."),
    '#options' => $role_options,
    '#default_value' => $config
      ->get('roles') ? $config
      ->get('roles') : array(),
    '#states' => $states,
  );
  $form['theme'] = [
    '#type' => 'value',
    '#value' => $theme,
  ];
  return parent::buildForm($form, $form_state);
}