You are here

public function IngredientFormatter::settingsForm in Recipe 8.2

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. 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 elements for the formatter settings.

Overrides FormatterBase::settingsForm

1 call to IngredientFormatter::settingsForm()
IngredientRecipeMLFormatter::settingsForm in src/Plugin/Field/FieldFormatter/IngredientRecipeMLFormatter.php
Returns a form to configure settings for the formatter.
1 method overrides IngredientFormatter::settingsForm()
IngredientRecipeMLFormatter::settingsForm in src/Plugin/Field/FieldFormatter/IngredientRecipeMLFormatter.php
Returns a form to configure settings for the formatter.

File

modules/ingredient/src/Plugin/Field/FieldFormatter/IngredientFormatter.php, line 101

Class

IngredientFormatter
Plugin implementation of the 'ingredient_default' formatter.

Namespace

Drupal\ingredient\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element['fraction_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Fractions display string'),
    '#default_value' => $this
      ->getSetting('fraction_format'),
    '#size' => 35,
    '#maxlength' => 255,
    '#description' => $this
      ->t('How fractions should be displayed. Leave blank to display as decimals.<br />Each incidence of %d will be replaced by the whole number, the numerator, and the denominator in that order.<br />Anything between curly braces will not be displayed when the whole number is equal to 0.<br />Recommended settings are "{%d }%d&amp;frasl;%d" or "{%d }&lt;sup&gt;%d&lt;/sup&gt;/&lt;sub&gt;%d&lt;/sub&gt;"'),
  ];
  $element['unit_display'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Ingredient unit display'),
    '#default_value' => $this
      ->getSetting('unit_display'),
    '#options' => $this
      ->getUnitDisplayOptions(),
    '#description' => $this
      ->t('Display ingredient units like Tbsp or Tablespoon.'),
    '#required' => TRUE,
  ];
  $element['link'] = [
    '#title' => $this
      ->t('Link name to the referenced ingredient'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('link'),
  ];
  return $element;
}