You are here

public function IngredientSettingsForm::buildForm in Recipe 8.2

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

modules/ingredient/src/Form/IngredientSettingsForm.php, line 64

Class

IngredientSettingsForm
Configure ingredient settings for this site.

Namespace

Drupal\ingredient\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('ingredient.settings');
  $form['ingredient_name_normalize'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Ingredient name normalization'),
    '#default_value' => $config
      ->get('ingredient_name_normalize'),
    '#options' => [
      $this
        ->t('Leave as entered'),
      $this
        ->t('Convert to lowercase'),
    ],
    '#description' => $this
      ->t('If enabled, the names of <em>new</em> ingredients will be converted to lowercase when they are entered. The names of registered trademarks, any ingredient name containing the &reg; symbol, will be excluded from normalization.'),
    '#required' => TRUE,
  ];
  if ($this->moduleHandler
    ->moduleExists('language')) {
    $form['default_ingredient_language'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Ingredients language'),
      '#open' => TRUE,
    ];
    $form['default_ingredient_language']['default_language'] = [
      '#type' => 'language_configuration',
      '#entity_information' => [
        'entity_type' => 'ingredient',
        'bundle' => 'ingredient',
      ],
      '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('ingredient', 'ingredient'),
    ];
  }
  return parent::buildForm($form, $form_state);
}