You are here

public function TimeFieldStandardWidget::settingsForm in Timefield 1.0.x

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

File

src/Plugin/Field/FieldWidget/TimeFieldStandardWidget.php, line 156

Class

TimeFieldStandardWidget
Plugin implementation of the 'timefield_standard_widget' widget.

Namespace

Drupal\timefield\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $library = $this->libraryDiscovery
    ->getLibraryByName('timefield', 'timepicker');
  if (empty($library)) {
    $this
      ->messenger()
      ->addWarning($this
      ->t("You will not have enhanced time input widget without downloading the plugin. %link", [
      '%link' => Link::fromTextAndUrl("Read installation instructions here.", Url::fromUserInput('http://drupalcode.org/project/timefield.git/blob_plain/HEAD:/README.txt')),
    ]));
  }
  $elements['disable_plugin'] = [
    '#title' => $this
      ->t('Disable jQuery Timepicker plugin.'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('disable_plugin'),
    '#description' => $this
      ->t('Do not use jQuery Timepicker plugin for input.'),
    '#disabled' => empty($library),
    '#attributes' => [
      'name' => 'disable_plugin',
    ],
  ];
  $elements['separator'] = [
    '#title' => $this
      ->t('Hour and Minute Separator'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('separator'),
    '#size' => 10,
    '#description' => $this
      ->t('The character to use to separate hours and minutes.'),
  ];
  $elements['showLeadingZero'] = [
    '#title' => $this
      ->t('Show Leading Zero for Hour'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('showLeadingZero'),
    '#description' => $this
      ->t('Whether or not to show a leading zero for hours < 10.'),
  ];
  $elements['showPeriod'] = [
    '#title' => $this
      ->t('Show AM/PM Label'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('showPeriod'),
    '#description' => $this
      ->t('Whether or not to show AM/PM on the input textfield both on the widget and in the text field after selecting the time with the widget.'),
  ];
  $elements['periodSeparator'] = [
    '#title' => $this
      ->t('What character should appear between the time and the Period (AM/PM)'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('periodSeparator'),
    '#size' => 10,
    '#description' => $this
      ->t('The character to use to separate the time from the time period (AM/PM).'),
  ];
  $elements['am_text'] = [
    '#title' => $this
      ->t('AM text'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('am_text'),
    '#size' => 10,
  ];
  $elements['pm_text'] = [
    '#title' => $this
      ->t('PM text'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('pm_text'),
    '#size' => 10,
  ];
  $elements['showCloseButton'] = [
    '#title' => $this
      ->t('Show a Button to Close the Picker Widget'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('showCloseButton'),
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['closeButtonText'] = [
    '#title' => $this
      ->t('Close Button text'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('closeButtonText'),
    '#size' => 10,
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['showNowButton'] = [
    '#title' => $this
      ->t('Show a Button to Select the Current Time'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('showNowButton'),
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['nowButtonText'] = [
    '#title' => $this
      ->t('Now Button text'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('nowButtonText'),
    '#size' => 10,
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['showDeselectButton'] = [
    '#title' => $this
      ->t('Show a Button to Deselect the time in the Picker Widget'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('showDeselectButton'),
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['deselectButtonText'] = [
    '#title' => $this
      ->t('Deselect Button text'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('deselectButtonText'),
    '#size' => 10,
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['myPosition'] = [
    '#title' => $this
      ->t('my Position'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('myPosition'),
    '#options' => array_combine([
      'left top',
      'left center',
      'left bottom',
      'center top',
      'center center',
      'center bottom',
      'right top',
      'right center',
      'right bottom',
    ], [
      'left top',
      'left center',
      'left bottom',
      'center top',
      'center center',
      'center bottom',
      'right top',
      'right center',
      'right bottom',
    ]),
    '#description' => $this
      ->t('Corner of the timpicker widget dialog to position. See !jquery_info for more info.', [
      '!jquery_info' => Link::fromTextAndUrl($this
        ->t("jQuery UI Position documentation"), Url::fromUri('http://jqueryui.com/demos/position')),
    ]),
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $elements['atPosition'] = [
    '#title' => $this
      ->t('at Position'),
    '#type' => 'select',
    '#options' => array_combine([
      'left top',
      'left center',
      'left bottom',
      'center top',
      'center center',
      'center bottom',
      'right top',
      'right center',
      'right bottom',
    ], [
      'left top',
      'left center',
      'left bottom',
      'center top',
      'center center',
      'center bottom',
      'right top',
      'right center',
      'right bottom',
    ]),
    '#default_value' => $this
      ->getSetting('atPosition'),
    '#description' => $this
      ->t('Where to position "my Position" relative to input widget textfield See !jquery_info for more info.', [
      '!jquery_info' => Link::fromTextAndUrl($this
        ->t("jQuery UI Position documentation"), Url::fromUri('http://jqueryui.com/demos/position')),
    ]),
    '#states' => [
      'invisible' => [
        ':input[name=disable_plugin]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $elements;
}