You are here

public function SidrTrigger::blockForm in Sidr: Accessible Mobile Menus 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Block/SidrTrigger.php \Drupal\sidr\Plugin\Block\SidrTrigger::blockForm()
  2. 8.2 src/Plugin/Block/SidrTrigger.php \Drupal\sidr\Plugin\Block\SidrTrigger::blockForm()

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/SidrTrigger.php, line 125

Class

SidrTrigger
Provides a trigger button with Sidr integration.

Namespace

Drupal\sidr\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $conf = $this
    ->getConfiguration();
  $settings = $this->configFactory
    ->get('sidr.settings');

  // Basic settings.
  $form['basic'] = [
    '#title' => $this
      ->t('Basic settings'),
    '#type' => 'fieldset',
  ];
  $form['basic']['trigger_text'] = [
    '#title' => $this
      ->t('Trigger text'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('Text to display on the trigger. Example: @example', [
      '@example' => 'Menu',
    ]),
    '#rows' => 3,
    '#maxlength' => 255,
    '#default_value' => $conf['trigger_text'],
  ];
  $form['basic']['sidr_source'] = [
    '#title' => $this
      ->t('Source'),
    '#type' => 'textarea',
    '#description' => $this
      ->t('A jQuery selector, a URL or a callback function.'),
    '#required' => TRUE,
    '#maxlength' => 255,
    '#default_value' => $conf['sidr_source'],
  ];
  $form['basic']['sidr_side'] = [
    '#title' => $this
      ->t('Location'),
    '#type' => 'radios',
    '#options' => [
      'left' => $this
        ->t('Left'),
      'right' => $this
        ->t('Right'),
    ],
    '#default_value' => $conf['sidr_side'],
  ];
  $form['basic']['theme'] = [
    '#title' => 'Theme',
    '#type' => 'textfield',
    '#description' => $this
      ->t('To modify the global sidr theme, visit the <a href="@sidr-settings">Sidr settings</a> page.', [
      '@sidr-settings' => Url::fromRoute('sidr.settings')
        ->toString(),
    ]),
    '#disabled' => TRUE,
    '#default_value' => $settings
      ->get('sidr_theme'),
  ];

  // Advanced settings.
  $form['advanced'] = [
    '#title' => $this
      ->t('Advanced settings'),
    '#type' => 'details',
    '#description' => $this
      ->t('For more information about various Sidr options, see the <a href="@sidr-documentation">Sidr documentation</a> page.', [
      '@sidr-documentation' => 'https://www.berriart.com/sidr/',
    ]),
    '#open' => FALSE,
  ];
  $form['advanced']['trigger_icon'] = [
    '#title' => $this
      ->t('Trigger icon'),
    '#type' => 'textarea',
    '#description' => $this
      ->t('Icon to display on the trigger. Example: @example', [
      '@example' => '<span class="icon-hamburger"></span>',
    ]),
    '#maxlength' => 255,
    '#default_value' => $conf['trigger_icon'],
  ];
  $form['advanced']['sidr_name'] = [
    '#title' => $this
      ->t('Unique ID'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('A unique DOM ID for the sidr instance. Example: @example', [
      '@example' => 'sidr-left',
    ]),
    '#maxlength' => 255,
    '#default_value' => $conf['sidr_name'],
  ];
  $form['advanced']['sidr_method'] = [
    '#title' => $this
      ->t('Trigger action'),
    '#type' => 'select',
    '#options' => [
      'toggle' => $this
        ->t('Toggle'),
      'open' => $this
        ->t('Open'),
      'close' => $this
        ->t('Close'),
    ],
    '#default_value' => $conf['sidr_method'],
  ];
  $form['advanced']['sidr_speed'] = [
    '#title' => $this
      ->t('Animation speed'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('Examples: @example', [
      '@example' => 'slow, fast, 400',
    ]),
    '#default_value' => $conf['sidr_speed'],
  ];
  $form['advanced']['sidr_timing'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Animation timing function'),
    '#description' => $this
      ->t('Examples: @example', [
      '@example' => 'linear, ease, cubic-bezier(...)',
    ]),
    '#maxlength' => 32,
    '#default_value' => $conf['sidr_timing'],
  ];
  $form['advanced']['sidr_renaming'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Rename elements?'),
    '#description' => $this
      ->t('Rename classes and IDs of source elements when filling the Sidr with existing content.'),
    '#default_value' => $conf['sidr_renaming'],
  ];
  $form['advanced']['sidr_displace'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Displace content?'),
    '#description' => $this
      ->t('Whether to displace page content during open and close animations.'),
    '#default_value' => $conf['sidr_displace'],
  ];
  $form['advanced']['sidr_body'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Element to displace'),
    '#description' => $this
      ->t('The element to be displaced during open / close animations instead of the @body element.', [
      '@body' => 'BODY',
    ]),
    '#default_value' => $conf['sidr_body'],
    '#maxlength' => 255,
    '#states' => [
      'visible' => [
        ':input[name="settings[advanced][sidr_displace]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}