public function LinkClassFieldWidget::settingsForm in Link class 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldWidget/LinkClassFieldWidget.php \Drupal\link_class\Plugin\Field\FieldWidget\LinkClassFieldWidget::settingsForm()
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 LinkWidget::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ LinkClassFieldWidget.php, line 36
Class
- LinkClassFieldWidget
- Plugin implementation of the 'link_class_field_widget' widget.
Namespace
Drupal\link_class\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$field_name = $this->fieldDefinition
->getName();
$element['link_class_mode'] = [
'#type' => 'radios',
'#title' => $this
->t('Method for adding class'),
'#options' => $this
->getModeOptions(),
'#default_value' => $this
->getSetting('link_class_mode'),
'#description' => $this
->t('Select the method you want to use for adding class.'),
];
$element['link_class_force'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link classes'),
'#default_value' => $this
->getSetting('link_class_force'),
'#description' => $this
->t('Set the classes to add on each link. Classes must be separated by a space.'),
'#attributes' => [
'placeholder' => 'btn btn-default',
],
'#size' => '30',
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][link_class_mode]"]' => [
'value' => 'force_class',
],
],
],
];
$element['link_class_select'] = [
'#type' => 'textarea',
'#title' => $this
->t('Define possibles classes'),
'#default_value' => $this
->getSetting('link_class_select'),
'#description' => $this
->selectClassDescription(),
'#attributes' => [
'placeholder' => 'btn btn-default|Default button' . PHP_EOL . 'btn btn-primary|Primary button',
],
'#size' => '30',
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][link_class_mode]"]' => [
'value' => 'select_class',
],
],
],
];
return $element;
}