You are here

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

Same name and namespace in other branches
  1. 8 src/CshsOptionsFromHelper.php \Drupal\cshs\CshsOptionsFromHelper::formElement()
  2. 8.2 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 {
  $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),
    // The `parent` may be `null` after saving the form with no selection.
    '#options' => $this
      ->getOptions((int) ($settings['parent'] ?? 0), $max_depth),
    '#multiple' => $settings['save_lineage'],
    '#none_label' => $this
      ->getTranslatedNoneLabel(),
    '#default_value' => CshsElement::NONE_VALUE,
    '#force_deepest' => $settings['force_deepest'],
    '#required_depth' => $settings['required_depth'],
  ];
}