You are here

public function Mini::buildConfigurationForm in Pagerer 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/pagerer/Mini.php \Drupal\pagerer\Plugin\pagerer\Mini::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PagererStyleBase::buildConfigurationForm

File

src/Plugin/pagerer/Mini.php, line 35

Class

Mini
Pager style to display current page/item in a direct entry textbox.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $config = parent::buildConfigurationForm($form, $form_state);

  // Reset pager display mode options specifically for mini.
  unset($config['display_container']['display_mode']['#options']['normal']);
  $config['display_container']['display_mode']['#options']['none'] = $this
    ->t('Not displayed.');
  $config['display_container']['display_mode']['#options']['widget'] = $this
    ->t('Input box. Users can enter directly a page/item number to go to.');

  // Remove 'item_ranges' display option.
  unset($config['display']['#options']['item_ranges']);
  $config['display']['#description'] = $this
    ->t("Select whether to display pages or items.");

  // No need for separators in mini.
  unset($config['separators_container']);

  // Add widget resizing option specific for mini.
  $config['plugin'] = [
    '#type' => 'details',
    '#title' => $this
      ->t("Input box"),
    '#description' => $this
      ->t("Input box options."),
  ];
  $config['plugin']['widget_resize'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Automatic width adjustment"),
    '#default_value' => $this->configuration['widget_resize'],
    '#description' => $this
      ->t("If set, the input box width will be adjusted dynamically based on the total number of pages/items. When unset, CSS styling will prevail."),
  ];
  $options = [
    'no',
    'yes',
    'auto',
  ];
  $options = array_combine($options, $options);
  $config['plugin']['widget_button'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Trigger button"),
    '#options' => $options,
    '#default_value' => $this->configuration['widget_button'],
    '#description' => $this
      ->t("Select whether to add a clickable navigation button to the input box. Options are 'no' (page relocation will only occur by pressing the 'return' key on the keyboard), 'yes' (button is shown, and styled via CSS), 'auto' (button height is automatically resized to match the input box height)."),
    '#required' => TRUE,
  ];
  return $config;
}