You are here

public function TermDevelGenerate::settingsForm in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::settingsForm()
  2. 8 devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::settingsForm()
  3. 8.2 devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::settingsForm()

Returns the form for the plugin.

Return value

array The array of default setting values, keyed by setting names.

Overrides DevelGenerateBase::settingsForm

File

devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php, line 132

Class

TermDevelGenerate
Provides a TermDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $options = [];
  foreach ($this->vocabularyStorage
    ->loadMultiple() as $vocabulary) {
    $options[$vocabulary
      ->id()] = $vocabulary
      ->label();
  }

  // Sort by vocabulary label.
  asort($options);

  // Set default to 'tags' only if it exists as a vocabulary.
  $default_vids = array_key_exists('tags', $options) ? 'tags' : '';
  $form['vids'] = [
    '#type' => 'select',
    '#multiple' => TRUE,
    '#title' => $this
      ->t('Vocabularies'),
    '#required' => TRUE,
    '#default_value' => $default_vids,
    '#options' => $options,
    '#description' => $this
      ->t('Restrict terms to these vocabularies.'),
  ];
  $form['num'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Number of terms'),
    '#default_value' => $this
      ->getSetting('num'),
    '#required' => TRUE,
    '#min' => 0,
  ];
  $form['title_length'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum number of characters in term names'),
    '#default_value' => $this
      ->getSetting('title_length'),
    '#required' => TRUE,
    '#min' => 2,
    '#max' => 255,
  ];
  $form['minimum_depth'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Minimum depth for new terms in the vocabulary hierarchy'),
    '#description' => $this
      ->t('Enter a value from 1 to 20.'),
    '#default_value' => $this
      ->getSetting('minimum_depth'),
    '#min' => 1,
    '#max' => 20,
  ];
  $form['maximum_depth'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum depth for new terms in the vocabulary hierarchy'),
    '#description' => $this
      ->t('Enter a value from 1 to 20.'),
    '#default_value' => $this
      ->getSetting('maximum_depth'),
    '#min' => 1,
    '#max' => 20,
  ];
  $form['kill'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete existing terms in specified vocabularies before generating new terms.'),
    '#default_value' => $this
      ->getSetting('kill'),
  ];

  // Add the language and translation options.
  $form += $this
    ->getLanguageForm('terms');
  return $form;
}