You are here

public function CshsOptionsFromHelper::formElement in Client-side Hierarchical Select 8.2

Same name and namespace in other branches
  1. 8.3 src/CshsOptionsFromHelper.php \Drupal\cshs\CshsOptionsFromHelper::formElement()
  2. 8 src/CshsOptionsFromHelper.php \Drupal\cshs\CshsOptionsFromHelper::formElement()

Returns the form for a single widget.

Return value

array The form elements for a single widget.

2 calls to CshsOptionsFromHelper::formElement()
CshsTaxonomyIndex::valueForm in src/Plugin/views/filter/CshsTaxonomyIndex.php
CshsWidget::formElement in src/Plugin/Field/FieldWidget/CshsWidget.php
Returns the form for a single field widget.

File

src/CshsOptionsFromHelper.php, line 294

Class

CshsOptionsFromHelper
Defines a class for getting options for a cshs form element from vocabulary.

Namespace

Drupal\cshs

Code

public function formElement() : array {
  $vocabulary = $this
    ->getVocabulary();
  \assert($vocabulary !== NULL);
  $settings = $this
    ->getSettings();
  if (!empty($settings['force_deepest']) || ($max_depth = $settings['hierarchy_depth']) < 1) {
    $max_depth = NULL;
  }
  return [
    '#type' => CshsElement::ID,
    '#labels' => $this
      ->getTranslatedLevelLabels(FALSE),
    '#parent' => $settings['parent'],
    '#options' => $this
      ->getOptions($vocabulary
      ->id(), $settings['parent'], CshsElement::NONE_VALUE, $max_depth),
    '#multiple' => $settings['save_lineage'],
    '#vocabulary' => $vocabulary,
    '#none_value' => CshsElement::NONE_VALUE,
    '#none_label' => $this
      ->getTranslatedNoneLabel(),
    '#default_value' => CshsElement::NONE_VALUE,
    '#force_deepest' => $settings['force_deepest'],
    '#required_depth' => $settings['required_depth'],
  ];
}