You are here

public function WebformTermReferenceTrait::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformTermReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformTermReferenceTrait::form()

Overrides WebformEntityReferenceTrait::form

File

src/Plugin/WebformElement/WebformTermReferenceTrait.php, line 53

Class

WebformTermReferenceTrait
Provides an 'term_reference' trait.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['term_reference'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Term reference settings'),
    '#weight' => -40,
  ];
  $form['term_reference']['vocabulary'] = [
    '#type' => 'webform_entity_select',
    '#title' => $this
      ->t('Vocabulary'),
    '#target_type' => 'taxonomy_vocabulary',
    '#selection_handler' => 'default:taxonomy_vocabulary',
  ];
  $form['term_reference']['breadcrumb'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display term hierarchy using breadcrumbs'),
    '#return_value' => TRUE,
  ];
  $form['term_reference']['breadcrumb_delimiter'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Breadcrumb delimiter'),
    '#size' => 10,
    '#states' => [
      'visible' => [
        [
          ':input[name="properties[breadcrumb]"]' => [
            'checked' => TRUE,
          ],
        ],
        'or',
        [
          ':input[name="properties[format]"]' => [
            'value' => 'breadcrumb',
          ],
        ],
      ],
      'required' => [
        [
          ':input[name="properties[breadcrumb]"]' => [
            'checked' => TRUE,
          ],
        ],
        'or',
        [
          ':input[name="properties[format]"]' => [
            'value' => 'breadcrumb',
          ],
        ],
      ],
    ],
  ];
  $form['term_reference']['tree_delimiter'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Tree delimiter'),
    '#size' => 10,
    '#states' => [
      'visible' => [
        ':input[name="properties[breadcrumb]"]' => [
          'checked' => FALSE,
        ],
      ],
      'required' => [
        ':input[name="properties[breadcrumb]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['term_reference']['depth'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Limit term depth'),
    '#field_suffix' => $this
      ->t('level(s)'),
  ];
  $form['term_reference']['scroll'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow terms to be scrollable'),
    '#return_value' => TRUE,
  ];
  return $form;
}