You are here

public function FaqFieldItem::fieldSettingsForm in FAQ Field 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldType/FaqFieldItem.php \Drupal\faqfield\Plugin\Field\FieldType\FaqFieldItem::fieldSettingsForm()

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::fieldSettingsForm

File

src/Plugin/Field/FieldType/FaqFieldItem.php, line 78

Class

FaqFieldItem
Plugin implementation of the 'faqfield' field type.

Namespace

Drupal\faqfield\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $element = [];

  // Get a list of formats that the current user has access to.
  $formats = filter_formats();
  $filter_options = [];
  foreach ($formats as $format) {
    $filter_options[$format
      ->get('format')] = $format
      ->get('name');
  }

  // Format select input for field settings.
  $element['default_format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default text format'),
    '#default_value' => $this
      ->getSetting('default_format'),
    '#options' => $filter_options,
    '#access' => count($formats) > 1,
    '#required' => TRUE,
    '#description' => $this
      ->t('Default text format to filter FAQ field answer content.'),
  ];
  return $element;
}