You are here

abstract class OptionsBase in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/OptionsBase.php \Drupal\webform\Plugin\WebformElement\OptionsBase

Provides a base 'options' element.

Hierarchy

Expanded class hierarchy of OptionsBase

5 files declare their use of OptionsBase
OptionsLimitWebformHandler.php in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
WebformButtons.php in modules/webform_jqueryui_buttons/src/Plugin/WebformElement/WebformButtons.php
WebformButtonsOther.php in modules/webform_jqueryui_buttons/src/Plugin/WebformElement/WebformButtonsOther.php
WebformSubmissionForm.php in src/WebformSubmissionForm.php
WebformToggles.php in modules/webform_toggles/src/Plugin/WebformElement/WebformToggles.php

File

src/Plugin/WebformElement/OptionsBase.php, line 21

Namespace

Drupal\webform\Plugin\WebformElement
View source
abstract class OptionsBase extends WebformElementBase {
  use TextBaseTrait;

  /**
   * Export delta for multiple options.
   *
   * @var bool
   */
  protected $exportDelta = FALSE;

  /**
   * The other option base element type.
   *
   * @var string
   */
  protected $otherOptionType;

  /**
   * {@inheritdoc}
   */
  protected function defineDefaultProperties() {
    $properties = [
      // Options settings.
      'options' => [],
      'options_randomize' => FALSE,
    ] + parent::defineDefaultProperties();

    // Add other properties to elements that include the other text field.
    if ($this
      ->isOptionsOther()) {
      $properties += [
        'other__option_label' => $this
          ->t('Other…'),
        'other__type' => 'textfield',
        'other__title' => '',
        'other__placeholder' => $this
          ->t('Enter other…'),
        'other__description' => '',
        // Text field or textarea.
        'other__size' => '',
        'other__maxlength' => '',
        'other__field_prefix' => '',
        'other__field_suffix' => '',
        // Textarea.
        'other__rows' => '',
        // Number.
        'other__min' => '',
        'other__max' => '',
        'other__step' => '',
        // Counter.
        'other__counter_type' => '',
        'other__counter_minimum' => '',
        'other__counter_minimum_message' => '',
        'other__counter_maximum' => '',
        'other__counter_maximum_message' => '',
        // Wrapper.
        'wrapper_type' => 'fieldset',
      ];
    }
    return $properties;
  }

  /****************************************************************************/

  /**
   * {@inheritdoc}
   */
  public function isMultiline(array $element) {
    $items_format = $this
      ->getItemsFormat($element);
    if (strpos($items_format, 'checklist:') === 0) {
      return TRUE;
    }
    else {
      return parent::isMultiline($element);
    }
  }

  /**
   * Determine if the element plugin type includes an other option text field.
   *
   * @return bool
   *   TRUE if the element plugin type includes an other option text field.
   */
  protected function isOptionsOther() {
    return $this
      ->getOptionsOtherType() ? TRUE : FALSE;
  }

  /**
   * Get the other option base element type.
   *
   * @return string|null
   *   The base element type (select|radios|checkboxes|buttons).
   */
  protected function getOptionsOtherType() {
    if (isset($this->otherOptionType)) {
      return $this->otherOptionType;
    }
    if (preg_match('/webform_(select|radios|checkboxes|buttons)_other$/', $this
      ->getPluginId(), $match)) {
      $this->otherOptionType = $match[1];
    }
    else {
      $this->otherOptionType = FALSE;
    }
    return $this->otherOptionType;
  }

  /**
   * {@inheritdoc}
   */
  protected function defineTranslatableProperties() {
    return array_merge(parent::defineTranslatableProperties(), [
      'options',
      'empty_option',
      'option_label',
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getRelatedTypes(array $element) {
    $related_types = parent::getRelatedTypes($element);

    // Remove entity reference elements.
    $elements = $this->elementManager
      ->getInstances();
    foreach ($related_types as $type => $related_type) {
      $element_instance = $elements[$type];
      if ($element_instance instanceof WebformElementEntityReferenceInterface) {
        unset($related_types[$type]);
      }
    }
    return $related_types;
  }

  /**
   * {@inheritdoc}
   */
  public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
    $is_wrapper_fieldset = in_array($element['#type'], [
      'checkboxes',
      'radios',
      'webform_entity_checkboxes',
      'webform_entity_radios',
      'webform_term_checkboxes',
      'webform_toggles',
      'webform_buttons',
    ]);
    if ($is_wrapper_fieldset) {

      // Issue #2396145: Option #description_display for webform element fieldset
      // is not changing anything.
      // @see core/modules/system/templates/fieldset.html.twig
      $is_description_display = isset($element['#description_display']) ? TRUE : FALSE;
      $has_description = !empty($element['#description']) ? TRUE : FALSE;
      if ($is_description_display && $has_description) {
        $description = WebformElementHelper::convertToString($element['#description']);
        switch ($element['#description_display']) {
          case 'before':
            $element += [
              '#field_prefix' => '',
            ];
            $element['#field_prefix'] = '<div class="description">' . $description . '</div>' . $element['#field_prefix'];
            unset($element['#description']);
            unset($element['#description_display']);
            break;
          case 'tooltip':
            $element += [
              '#field_suffix' => '',
            ];
            $element['#field_suffix'] .= '<div class="description visually-hidden">' . $description . '</div>';

            // @see \Drupal\Core\Render\Element\CompositeFormElementTrait
            // @see \Drupal\webform\Plugin\WebformElementBase::prepare
            $element['#attributes']['class'][] = 'js-webform-tooltip-element';
            $element['#attributes']['class'][] = 'webform-tooltip-element';
            $element['#attached']['library'][] = 'webform/webform.tooltip';
            unset($element['#description']);
            unset($element['#description_display']);
            break;
          case 'invisible':
            $element += [
              '#field_suffix' => '',
            ];
            $element['#field_suffix'] .= '<div class="description visually-hidden">' . $description . '</div>';
            unset($element['#description']);
            unset($element['#description_display']);
            break;
        }
      }
    }
    parent::prepare($element, $webform_submission);

    // Randomize options.
    if (isset($element['#options']) && !empty($element['#options_randomize'])) {
      $element['#options'] = WebformElementHelper::randomize($element['#options']);
    }

    // Options description display must be set to trigger the description display.
    if ($this
      ->hasProperty('options_description_display') && empty($element['#options_description_display'])) {
      $element['#options_description_display'] = $this
        ->getDefaultProperty('options_description_display');
    }

    // Options display must be set to trigger the options display.
    if ($this
      ->hasProperty('options_display') && empty($element['#options_display'])) {
      $element['#options_display'] = $this
        ->getDefaultProperty('options_display');
    }

    // Make sure submitted value is not lost if the element's #options were
    // altered after the submission was completed.
    // This only applies to the main webforom element with a #webform_key
    // and not a webform composite's sub elements.
    $is_completed = $webform_submission && $webform_submission
      ->isCompleted();
    $has_default_value = isset($element['#default_value']) && $element['#default_value'] !== '' && $element['#default_value'] !== NULL;
    if ($is_completed && $has_default_value && !$this
      ->isOptionsOther() && isset($element['#webform_key'])) {
      if ($element['#default_value'] === $webform_submission
        ->getElementData($element['#webform_key'])) {
        $options = OptGroup::flattenOptions($element['#options']);
        $default_values = (array) $element['#default_value'];
        foreach ($default_values as $default_value) {
          if (!isset($options[$default_value])) {
            $element['#options'][$default_value] = $default_value;
          }
        }
      }
    }

    // If the element is #required and the #default_value is an empty string
    // we need to unset the #default_value to prevent the below error.
    // 'An illegal choice has been detected'.
    if (!empty($element['#required']) && isset($element['#default_value']) && $element['#default_value'] === '') {
      unset($element['#default_value']);
    }

    // Process custom options properties.
    if ($this
      ->hasProperty('options__properties')) {
      $this
        ->setElementDefaultCallback($element, 'process');
      $element['#process'][] = [
        get_class($this),
        'processOptionsProperties',
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareElementValidateCallbacks(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
    if ($this
      ->hasMultipleValues($element)) {
      $element['#element_validate'][] = [
        get_class($this),
        'validateMultipleOptions',
      ];
    }
    parent::prepareElementValidateCallbacks($element, $webform_submission);
  }

  /**
   * Processes options (custom) properties.
   */
  public static function processOptionsProperties(&$element, FormStateInterface $form_state, &$complete_form) {
    if (empty($element['#options__properties'])) {
      return $element;
    }
    foreach ($element['#options__properties'] as $option_key => $options__properties) {
      if (!isset($element[$option_key]) || !is_array($options__properties)) {
        continue;
      }

      // Remove ignored properties.
      $options__properties = WebformElementHelper::removeIgnoredProperties($options__properties);
      foreach ($options__properties as $property => $value) {
        $option_element =& $element[$option_key];
        if (in_array($property, [
          '#attributes',
          '#wrapper_attributes',
          '#label_attributes',
        ])) {

          // Apply attributes.
          $option_element += [
            $property => [],
          ];
          foreach ($value as $attribute_name => $attribute_value) {

            // Merge attributes class.
            if ($attribute_name === 'class' && isset($element[$option_key][$property][$attribute_name])) {
              $option_element[$property][$attribute_name] = array_merge($element[$option_key][$property][$attribute_name], $attribute_value);
            }
            else {
              $option_element[$property][$attribute_name] = $attribute_value;
            }
          }
        }
        else {
          $option_element[$property] = $value;
        }
      }
    }
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function hasMultipleWrapper() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function setDefaultValue(array &$element) {
    if (!isset($element['#default_value'])) {
      return;
    }

    // Compensate for #default_value not being an array, for elements that
    // allow for multiple #options to be selected/checked.
    if ($this
      ->hasMultipleValues($element) && !is_array($element['#default_value'])) {
      $element['#default_value'] = [
        $element['#default_value'],
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
    $value = $this
      ->getValue($element, $webform_submission, $options);
    $format = $this
      ->getItemFormat($element);
    switch ($format) {
      case 'raw':
        return $value;
      case 'description':
        if (isset($element['#options'])) {
          $options_description = $this
            ->hasProperty('options_description_display');
          if ($options_description) {
            $description = WebformOptionsHelper::getOptionDescription($value, $element['#options'], $options_description);
            return [
              '#markup' => $description,
            ];
          }
        }
        return '';
      case 'value':
      default:
        if (isset($element['#options'])) {
          $options_description = $this
            ->hasProperty('options_description_display');
          $value = WebformOptionsHelper::getOptionText($value, $element['#options'], $options_description);
        }

        // Build a render array that uses #plain_text so that
        // HTML characters are escaped.
        // @see \Drupal\Core\Render\Renderer::ensureMarkupIsSafe
        if ($value === '0') {

          // Issue #2765609: #plain_text doesn't render empty-like values
          // (e.g. 0 and "0").
          // Workaround: Use #markup until this issue is fixed.
          // @todo Remove workaround once only Drupal 8.7.x is supported.
          $build = [
            '#markup' => $value,
          ];
        }
        else {
          $build = [
            '#plain_text' => $value,
          ];
        }
        $options += [
          'prefixing' => TRUE,
        ];
        if ($options['prefixing']) {
          if (isset($element['#field_prefix'])) {
            $build['#prefix'] = $element['#field_prefix'];
          }
          if (isset($element['#field_suffix'])) {
            $build['#suffix'] = $element['#field_suffix'];
          }
        }
        return $build;
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
    $value = $this
      ->getValue($element, $webform_submission, $options);
    $format = $this
      ->getItemFormat($element);
    switch ($format) {
      case 'raw':
        return $value;
      case 'description':
        if (isset($element['#options'])) {
          $options_description = $this
            ->hasProperty('options_description_display');
          if ($options_description) {
            $description = WebformOptionsHelper::getOptionDescription($value, $element['#options'], $options_description);
            if ($description) {
              return MailFormatHelper::htmlToText($description);
            }
          }
        }
        return '';
      case 'value':
      default:
        if (isset($element['#options'])) {
          $options_description = $this
            ->hasProperty('options_description_display');
          $value = WebformOptionsHelper::getOptionText($value, $element['#options'], $options_description);
        }
        $options += [
          'prefixing' => TRUE,
        ];
        if ($options['prefixing']) {
          if (isset($element['#field_prefix'])) {
            $value = strip_tags($element['#field_prefix']) . $value;
          }
          if (isset($element['#field_suffix'])) {
            $value .= strip_tags($element['#field_suffix']);
          }
        }
        return $value;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getItemFormats() {
    return parent::getItemFormats() + [
      'description' => $this
        ->t('Option description'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getItemsDefaultFormat() {
    return 'comma';
  }

  /**
   * {@inheritdoc}
   */
  protected function formatHtmlItems(array &$element, WebformSubmissionInterface $webform_submission, array $options = []) {
    $format = $this
      ->getItemsFormat($element);
    if (strpos($format, 'checklist:') === 0) {

      // Get checked/unchecked icons.
      list(, $checked_type) = explode(':', $format);
      switch ($checked_type) {
        case 'crosses':
          $checked = '✖ ';
          $unchecked = '⚬ ';
          break;
        default:
        case 'boxes':
          $checked = Markup::create('<span style="font-size: 1.4em; line-height: 1em">☑</span> ');
          $unchecked = Markup::create('<span style="font-size: 1.4em; line-height: 1em">☐</span> ');
          break;
      }
      $value = (array) $this
        ->getValue($element, $webform_submission, $options);
      $values = array_combine($value, $value);

      // Build list of checked and unchecked options.
      $build = [];
      $options_description = $this
        ->hasProperty('options_description_display');
      $flattened_options = OptGroup::flattenOptions($element['#options']);
      foreach ($flattened_options as $option_value => $option_text) {
        if ($options_description && WebformOptionsHelper::hasOptionDescription($option_text)) {
          list($option_text) = WebformOptionsHelper::splitOption($option_text);
        }
        $build[$option_value] = [
          '#prefix' => isset($values[$option_value]) ? $checked : $unchecked,
          '#markup' => $option_text,
          '#suffix' => '<br/>',
        ];
        unset($values[$option_value]);
      }

      // Append all remaining option values.
      foreach ($values as $value) {
        $build[$value] = [
          '#prefix' => $checked,
          '#markup' => $value,
          '#suffix' => '<br/>',
        ];
      }
      return $build;
    }
    else {
      return parent::formatHtmlItems($element, $webform_submission, $options);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function formatTextItems(array &$element, WebformSubmissionInterface $webform_submission, array $options = []) {
    $format = $this
      ->getItemsFormat($element);
    if (strpos($format, 'checklist:') === 0) {

      // Get checked/unchecked icons.
      list(, $checked_type) = explode(':', $format);
      switch ($checked_type) {
        case 'crosses':
          $checked = '✖';
          $unchecked = '⚬';
          break;
        default:
        case 'boxes':
          $checked = '☑';
          $unchecked = '☐';
          break;
      }
      $value = (array) $this
        ->getValue($element, $webform_submission, $options);
      $values = array_combine($value, $value);

      // Build list of checked and unchecked options.
      $list = [];
      $options_description = $this
        ->hasProperty('options_description_display');
      $flattened_options = OptGroup::flattenOptions($element['#options']);
      foreach ($flattened_options as $option_value => $option_text) {
        if ($options_description && WebformOptionsHelper::hasOptionDescription($option_text)) {
          list($option_text) = WebformOptionsHelper::splitOption($option_text);
        }
        $list[] = (isset($values[$option_value]) ? $checked : $unchecked) . ' ' . $option_text;
        unset($values[$option_value]);
      }

      // Append all remaining option values.
      foreach ($values as $value) {
        $list[] = $checked . ' ' . $value;
      }
      return implode(PHP_EOL, $list);
    }
    else {
      return parent::formatTextItems($element, $webform_submission, $options);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getItemsFormats() {
    return parent::getItemsFormats() + [
      'checklist:boxes' => $this
        ->t('Checklist (☑/☐)'),
      'checklist:crosses' => $this
        ->t('Checklist (gi)'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function preview() {
    $element = parent::preview();
    if ($this
      ->hasProperty('options')) {
      $element['#options'] = [
        'one' => 'One',
        'two' => 'Two',
        'three' => 'Three',
      ];
    }
    if ($this
      ->hasProperty('options_display')) {
      $element['#options_display'] = 'side_by_side';
    }
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function getTableColumn(array $element) {
    $key = $element['#webform_key'];
    $columns = parent::getTableColumn($element);
    $columns['element__' . $key]['sort'] = !$this
      ->hasMultipleValues($element);
    return $columns;
  }

  /**
   * {@inheritdoc}
   */
  public function getExportDefaultOptions() {
    return [
      'options_single_format' => 'compact',
      'options_multiple_format' => 'compact',
      'options_item_format' => 'label',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildExportOptionsForm(array &$form, FormStateInterface $form_state, array $export_options) {
    parent::buildExportOptionsForm($form, $form_state, $export_options);
    if (isset($form['options'])) {
      return;
    }

    // Build format options with help.
    $options_format_options = [
      'compact' => $this
        ->t('Compact, with the option values delimited by commas in one column.') . WebformOptionsHelper::DESCRIPTION_DELIMITER . $this
        ->t('Compact options are more suitable for importing data into other systems.'),
      'separate' => $this
        ->t('Separate, with each possible option value in its own column.') . WebformOptionsHelper::DESCRIPTION_DELIMITER . $this
        ->t('Separate options are more suitable for building reports, graphs, and statistics in a spreadsheet application. Ranking will be included for sortable option elements.'),
    ];
    $form['options'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Select menu, radio buttons, and checkboxes options'),
      '#open' => TRUE,
      '#weight' => -10,
    ];
    $form['options']['options_single_format'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Options single value format'),
      '#description' => $this
        ->t('Elements that collect a single option value include select menus, radios, and buttons.'),
      '#options' => $options_format_options,
      '#options_description_display' => 'help',
      '#default_value' => $export_options['options_single_format'],
    ];
    $form['options']['options_multiple_format'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Options multiple values format'),
      '#description' => $this
        ->t('Elements that collect multiple option values include multi-select, checkboxes, and toggles.'),
      '#options' => $options_format_options,
      '#options_description_display' => 'help',
      '#default_value' => $export_options['options_multiple_format'],
    ];
    $form['options']['options_item_format'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Options item format'),
      '#options' => [
        'label' => $this
          ->t('Option labels, the human-readable value (label)'),
        'key' => $this
          ->t('Option values, the raw value stored in the database (key)'),
      ],
      '#default_value' => $export_options['options_item_format'],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildExportHeader(array $element, array $options) {
    $options_format = $element['#webform_multiple'] ? $options['options_multiple_format'] : $options['options_single_format'];
    if ($options_format === 'separate' && isset($element['#options'])) {
      $header = [];
      foreach ($element['#options'] as $option_value => $option_text) {

        // Note: If $option_text is an array (typically a tableselect row)
        // always use $option_value.
        $title = $options['options_item_format'] === 'key' || is_array($option_text) ? $option_value : $option_text;
        $header[] = $title;
      }

      // Add 'Other' option to header.
      if ($this instanceof WebformElementOtherInterface) {
        $header[] = $options['options_item_format'] === 'key' ? 'other' : $this
          ->t('Other');
      }
      return $this
        ->prefixExportHeader($header, $element, $options);
    }
    else {
      return parent::buildExportHeader($element, $options);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function buildExportRecord(array $element, WebformSubmissionInterface $webform_submission, array $export_options) {
    $element_options = isset($element['#options']) ? $element['#options'] : [];
    $options_format = $element['#webform_multiple'] ? $export_options['options_multiple_format'] : $export_options['options_single_format'];
    if ($options_format === 'separate') {
      $value = $this
        ->getRawValue($element, $webform_submission);
      $record = [];

      // Combine the values so that isset can be used instead of in_array().
      // http://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset
      $deltas = FALSE;
      if (is_array($value)) {
        $value = array_combine($value, $value);
        $deltas = $this->exportDelta ? array_flip(array_values($value)) : FALSE;
      }

      // Separate multiple values (i.e. options).
      foreach ($element_options as $option_value => $option_text) {
        if (is_array($value) && isset($value[$option_value])) {
          unset($value[$option_value]);
          $record[] = $deltas ? $deltas[$option_value] + 1 : 'X';
        }
        elseif ($value === $option_value) {
          $value = '';
          $record[] = $deltas ? $deltas[$option_value] + 1 : 'X';
        }
        else {
          $record[] = '';
        }
      }

      // Add 'Other' option to record.
      if ($this instanceof WebformElementOtherInterface) {
        $record[] = is_array($value) ? implode($export_options['multiple_delimiter'], $value) : $value;
      }
      return $record;
    }
    else {
      if ($export_options['options_item_format'] === 'key') {
        $element['#format'] = 'raw';
      }
      return parent::buildExportRecord($element, $webform_submission, $export_options);
    }
  }

  /**
   * Form API callback. Remove unchecked options from value array.
   */
  public static function validateMultipleOptions(array &$element, FormStateInterface $form_state, array &$completed_form) {
    $values = $element['#value'] ?: [];

    // Filter unchecked/unselected options whose value is 0.
    $values = array_filter($values, function ($value) {
      return $value !== 0;
    });
    $values = array_values($values);
    $form_state
      ->setValueForElement($element, $values);
  }

  /**
   * {@inheritdoc}
   */
  protected function getElementSelectorInputsOptions(array $element) {
    if ($other_type = $this
      ->getOptionsOtherType()) {
      list($type) = explode(' ', $this
        ->getPluginLabel());
      $title = $this
        ->getAdminLabel($element);
      $name = $other_type;
      $inputs = [];
      $inputs[$name] = $title . ' [' . $type . ']';
      $inputs['other'] = $title . ' [' . $this
        ->t('Other field') . ']';
      return $inputs;
    }
    else {
      return [];
    }
  }

  /**
   * {@inheritdoc}
   *
   * @see \Drupal\webform\Entity\Webform::getElementsSelectorOptions
   */
  public function getElementSelectorOptions(array $element) {
    if ($this
      ->hasMultipleValues($element) && $this
      ->hasMultipleWrapper()) {
      return [];
    }
    $plugin_id = $this
      ->getPluginId();
    $title = $this
      ->getAdminLabel($element) . ' [' . $this
      ->getPluginLabel() . ']';
    $name = $element['#webform_key'];
    if ($inputs = $this
      ->getElementSelectorInputsOptions($element)) {
      $selectors = [];
      foreach ($inputs as $input_name => $input_title) {
        $multiple = $this
          ->hasMultipleValues($element) && $input_name === 'select' ? '[]' : '';
        $selectors[":input[name=\"{$name}[{$input_name}]{$multiple}\"]"] = $input_title;
      }
      return [
        $title => $selectors,
      ];
    }
    else {
      $multiple = $this
        ->hasMultipleValues($element) && strpos($plugin_id, 'select') !== FALSE ? '[]' : '';
      return [
        ":input[name=\"{$name}{$multiple}\"]" => $title,
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getElementSelectorSourceValues(array $element) {
    if ($this
      ->hasMultipleValues($element) && $this
      ->hasMultipleWrapper()) {
      return [];
    }
    $plugin_id = $this
      ->getPluginId();
    $name = $element['#webform_key'];
    $options = OptGroup::flattenOptions($element['#options']);
    if ($this
      ->getElementSelectorInputsOptions($element)) {
      $other_type = $this
        ->getOptionsOtherType();
      $multiple = $this
        ->hasMultipleValues($element) && $other_type === 'select' ? '[]' : '';
      return [
        ":input[name=\"{$name}[{$other_type}]{$multiple}\"]" => $options,
      ];
    }
    else {
      $multiple = $this
        ->hasMultipleValues($element) && strpos($plugin_id, 'select') !== FALSE ? '[]' : '';
      return [
        ":input[name=\"{$name}{$multiple}\"]" => $options,
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getElementSelectorInputValue($selector, $trigger, array $element, WebformSubmissionInterface $webform_submission) {
    if ($this
      ->isOptionsOther()) {
      $input_name = WebformSubmissionConditionsValidator::getSelectorInputName($selector);
      $other_type = WebformSubmissionConditionsValidator::getInputNameAsArray($input_name, 1);
      $value = $this
        ->getRawValue($element, $webform_submission);

      // Handle edge case where the other element's value has
      // not been processed.
      // @see https://www.drupal.org/project/webform/issues/3000202

      /** @var \Drupal\webform\Element\WebformOtherBase $class */
      $class = $this
        ->getFormElementClassDefinition();
      $type = $class::getElementType();
      if (is_array($value) && count($value) === 2 && isset($value[$type]) && isset($value['other'])) {
        $value = $class::processValue($element, $value);
      }
      $options = OptGroup::flattenOptions($element['#options']);
      if ($other_type === 'other') {
        if ($this
          ->hasMultipleValues($element)) {
          $other_value = array_diff($value, array_keys($options));
          return $other_value ? implode(', ', $other_value) : NULL;
        }
        else {

          // Make sure other value is not valid option.
          return $value && !isset($options[$value]) ? $value : NULL;
        }
      }
      else {

        // If the trigger is 'filled or 'empty' then return the value.
        if ($trigger === 'filled' || $trigger === 'empty') {
          return $value;
        }
        if ($this
          ->hasMultipleValues($element)) {

          // Return array of valid #options.
          return array_intersect($value, array_keys($options));
        }
        else {

          // Return valid #option.
          return isset($options[$value]) ? $value : NULL;
        }
      }
    }
    else {
      return parent::getElementSelectorInputValue($selector, $trigger, $element, $webform_submission);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form['default']['default_value']['#description'] .= ' ' . $this
      ->t('The default value of the field identified by its key.');

    // Issue #2836374: Wrapper attributes are not supported by composite
    // elements, this includes radios, checkboxes, and buttons.
    if (preg_match('/(radios|checkboxes|buttons)/', $this
      ->getPluginId())) {
      $t_args = [
        '@name' => mb_strtolower($this
          ->getPluginLabel()),
        ':href' => 'https://www.drupal.org/node/2836364',
      ];
      $form['element_attributes']['#description'] = $this
        ->t('Please note: That the below custom element attributes will also be applied to the @name fieldset wrapper. (<a href=":href">Issue #2836374</a>)', $t_args);
    }

    // Options.
    $form['options'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Element options'),
      '#open' => TRUE,
    ];
    $form['options']['options'] = [
      '#type' => 'webform_element_options',
      '#title' => $this
        ->t('Options'),
      '#options_description' => $this
        ->hasProperty('options_description_display'),
      '#required' => TRUE,
    ];
    $form['options']['options_display_container'] = $this
      ->getFormInlineContainer();
    $form['options']['options_display_container']['options_display'] = [
      '#title' => $this
        ->t('Options display'),
      '#type' => 'select',
      '#options' => [
        'one_column' => $this
          ->t('One column'),
        'two_columns' => $this
          ->t('Two columns'),
        'three_columns' => $this
          ->t('Three columns'),
        'side_by_side' => $this
          ->t('Side by side'),
        'buttons' => $this
          ->t('Buttons - flexbox'),
        'buttons_horizontal' => $this
          ->t('Buttons - horizontal'),
        'buttons_vertical' => $this
          ->t('Buttons - vertical'),
      ],
    ];
    $form['options']['options_display_container']['options_description_display'] = [
      '#title' => $this
        ->t('Options description display'),
      '#type' => 'select',
      '#options' => [
        'description' => $this
          ->t('Description'),
        'help' => $this
          ->t('Help text'),
      ],
    ];
    $form['options']['empty_option'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Empty option label'),
      '#description' => $this
        ->t('The label to show for the initial option denoting no selection in a select element.'),
      '#states' => [
        'visible' => [
          ':input[name="properties[multiple][container][cardinality]"]' => [
            'value' => 'number',
          ],
          ':input[name="properties[multiple][container][cardinality_number]"]' => [
            'value' => 1,
          ],
        ],
      ],
    ];
    $default_empty_option = $this->configFactory
      ->get('webform.settings')
      ->get('element.default_empty_option');
    if ($default_empty_option) {
      $default_empty_option_required = $this->configFactory
        ->get('webform.settings')
        ->get('element.default_empty_option_required') ?: $this
        ->t('- Select -');
      $form['options']['empty_option']['#description'] .= '<br />' . $this
        ->t('Required elements defaults to: %required', [
        '%required' => $default_empty_option_required,
      ]);
      $default_empty_option_optional = $this->configFactory
        ->get('webform.settings')
        ->get('element.default_empty_option_optional') ?: $this
        ->t('- None -');
      $form['options']['empty_option']['#description'] .= '<br />' . $this
        ->t('Optional elements defaults to: %optional', [
        '%optional' => $default_empty_option_optional,
      ]);
    }
    $form['options']['empty_value'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Empty option value'),
      '#description' => $this
        ->t('The value for the initial option denoting no selection in a select element, which is used to determine whether the user submitted a value or not.'),
      '#states' => [
        'visible' => [
          ':input[name="properties[multiple][container][cardinality]"]' => [
            'value' => 'number',
          ],
          ':input[name="properties[multiple][container][cardinality_number]"]' => [
            'value' => 1,
          ],
        ],
      ],
    ];

    // Sort options (only applies to select menus).
    // @see template_preprocess_select()
    // @see webform_preprocess_select()
    $form['options']['sort_options'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Sort options'),
      '#description' => $this
        ->t('Sort the options by their (translated) labels.'),
      '#return_value' => TRUE,
    ];
    $form['options']['options_randomize'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Randomize options'),
      '#description' => $this
        ->t('Randomizes the order of the options when they are displayed in the webform.'),
      '#return_value' => TRUE,
    ];
    if ($this
      ->hasProperty('options_randomize') && $this
      ->hasProperty('sort_options')) {
      $form['options']['options_randomize']['#states']['visible'] = [
        ':input[name="properties[sort_options]"]' => [
          'checked' => FALSE,
        ],
      ];
    }

    // Other.
    $states_textfield_or_number = [
      'visible' => [
        [
          ':input[name="properties[other__type]"]' => [
            'value' => 'textfield',
          ],
        ],
        'or',
        [
          ':input[name="properties[other__type]"]' => [
            'value' => 'number',
          ],
        ],
      ],
    ];
    $states_textbase = [
      'visible' => [
        [
          ':input[name="properties[other__type]"]' => [
            'value' => 'textfield',
          ],
        ],
        'or',
        [
          ':input[name="properties[other__type]"]' => [
            'value' => 'textarea',
          ],
        ],
      ],
    ];
    $states_textarea = [
      'visible' => [
        ':input[name="properties[other__type]"]' => [
          'value' => 'textarea',
        ],
      ],
    ];
    $states_number = [
      'visible' => [
        ':input[name="properties[other__type]"]' => [
          'value' => 'number',
        ],
      ],
    ];
    $form['options_other'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Other option settings'),
    ];
    $form['options_other']['other__type'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Other type'),
      '#options' => [
        'textfield' => $this
          ->t('Text field'),
        'textarea' => $this
          ->t('Textarea'),
        'number' => $this
          ->t('Number'),
      ],
    ];
    $form['options_other']['other__option_label'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other option label'),
    ];
    $form['options_other']['other__title'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other title'),
    ];
    $form['options_other']['other__placeholder'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other placeholder'),
    ];
    $form['options_other']['other__description'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other description'),
    ];
    $form['options_other']['other__field_container'] = $this
      ->getFormInlineContainer();
    $form['options_other']['other__field_container']['other__field_prefix'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other field prefix'),
      '#description' => $this
        ->t('Text or code that is placed directly in front of the input. This can be used to prefix an input with a constant string. Examples: $, #, -.'),
      '#size' => 10,
      '#states' => $states_textfield_or_number,
    ];
    $form['options_other']['other__field_container']['other__field_suffix'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Other field suffix'),
      '#description' => $this
        ->t('Text or code that is placed directly after the input. This can be used to add a unit to an input. Examples: lb, kg, %.'),
      '#size' => 10,
      '#states' => $states_textfield_or_number,
    ];
    $form['options_other']['other__size_container'] = $this
      ->getFormInlineContainer();
    $form['options_other']['other__size_container']['other__size'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other size'),
      '#description' => $this
        ->t('Leaving blank will use the default size.'),
      '#min' => 1,
      '#size' => 4,
      '#states' => $states_textfield_or_number,
    ];
    $form['options_other']['other__size_container']['other__maxlength'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other maxlength'),
      '#description' => $this
        ->t('Leaving blank will use the default maxlength.'),
      '#min' => 1,
      '#size' => 4,
      '#states' => $states_textfield_or_number,
    ];
    $form['options_other']['other__size_container']['other__rows'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other rows'),
      '#description' => $this
        ->t('Leaving blank will use the default rows.'),
      '#min' => 1,
      '#size' => 4,
      '#states' => $states_textarea,
    ];
    $form['options_other']['other__number_container'] = $this
      ->getFormInlineContainer();
    $form['options_other']['other__number_container']['other__min'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other minimum'),
      '#description' => $this
        ->t('Specifies the minimum value.'),
      '#step' => 'any',
      '#size' => 4,
      '#states' => $states_number,
    ];
    $form['options_other']['other__number_container']['other__max'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other maximum'),
      '#description' => $this
        ->t('Specifies the maximum value.'),
      '#step' => 'any',
      '#size' => 4,
      '#states' => $states_number,
    ];
    $form['options_other']['other__number_container']['other__step'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Other steps'),
      '#description' => $this
        ->t('Specifies the legal number intervals. Leave blank to support any number interval.'),
      '#step' => 'any',
      '#size' => 4,
      '#states' => $states_number,
    ];
    $form['options_other']['other__textbase_container'] = [
      '#type' => 'container',
      '#states' => $states_textbase,
    ] + $this
      ->buildCounterForm('other__', 'Other count');

    // Add hide/show #format_items based on #multiple.
    if ($this
      ->supportsMultipleValues() && $this
      ->hasProperty('multiple')) {
      $form['display']['format_items']['#states'] = [
        'visible' => [
          [
            ':input[name="properties[multiple]"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
      ];
    }
    $form['options_properties'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Options (custom) properties'),
      '#access' => $this
        ->hasProperty('options__properties') && $this->currentUser
        ->hasPermission('edit webform source'),
    ];
    $form['options_properties']['options__properties'] = [
      '#type' => 'webform_codemirror',
      '#mode' => 'yaml',
      '#title' => $this
        ->t('Options properties'),
      '#description' => $this
        ->t("Custom options properties must include the 'Option value' followed by option (element) properties prepended with a hash (#) character.") . "<pre>option_value:\n  '#wrapper_attributes':\n    class:\n      - disabled\n  '#disabled': true</pre>" . '<br /><br />' . $this
        ->t('These properties and callbacks are not allowed: @properties', [
        '@properties' => WebformArrayHelper::toString(WebformArrayHelper::addPrefix(WebformElementHelper::$ignoredProperties)),
      ]),
    ];
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
OptionsBase::$exportDelta protected property Export delta for multiple options. 2
OptionsBase::$otherOptionType protected property The other option base element type.
OptionsBase::buildExportHeader public function Build an element's export header. Overrides WebformElementBase::buildExportHeader
OptionsBase::buildExportOptionsForm public function Get an element's export options webform. Overrides WebformElementBase::buildExportOptionsForm
OptionsBase::buildExportRecord public function Build an element's export row. Overrides WebformElementBase::buildExportRecord
OptionsBase::defineDefaultProperties protected function Define an element's default properties. Overrides WebformElementBase::defineDefaultProperties 7
OptionsBase::defineTranslatableProperties protected function Define an element's translatable properties. Overrides WebformElementBase::defineTranslatableProperties 2
OptionsBase::form public function Gets the actual configuration webform array to be built. Overrides WebformElementBase::form 2
OptionsBase::formatHtmlItem protected function Format an element's value as HTML. Overrides WebformElementBase::formatHtmlItem 1
OptionsBase::formatHtmlItems protected function Format an element's items as HTML. Overrides WebformElementBase::formatHtmlItems
OptionsBase::formatTextItem protected function Format an element's value as text. Overrides WebformElementBase::formatTextItem 1
OptionsBase::formatTextItems protected function Format an element's items as text. Overrides WebformElementBase::formatTextItems
OptionsBase::getElementSelectorInputsOptions protected function Get an element's (sub)inputs selectors as options. Overrides WebformElementBase::getElementSelectorInputsOptions 3
OptionsBase::getElementSelectorInputValue public function Get an element's (sub)input selector value. Overrides WebformElementBase::getElementSelectorInputValue 1
OptionsBase::getElementSelectorOptions public function Overrides WebformElementBase::getElementSelectorOptions 4
OptionsBase::getElementSelectorSourceValues public function Get an element's selectors source values. Overrides WebformElementBase::getElementSelectorSourceValues 2
OptionsBase::getExportDefaultOptions public function Get an element's default export options. Overrides WebformElementBase::getExportDefaultOptions
OptionsBase::getItemFormats public function Get an element's available single value formats. Overrides WebformElementBase::getItemFormats 1
OptionsBase::getItemsDefaultFormat public function Get an element's default multiple value format name. Overrides WebformElementBase::getItemsDefaultFormat 1
OptionsBase::getItemsFormats public function Get an element's available multiple value formats. Overrides WebformElementBase::getItemsFormats 1
OptionsBase::getOptionsOtherType protected function Get the other option base element type.
OptionsBase::getRelatedTypes public function Get related element types. Overrides WebformElementBase::getRelatedTypes 1
OptionsBase::getTableColumn public function Get element's table column(s) settings. Overrides WebformElementBase::getTableColumn
OptionsBase::hasMultipleWrapper public function Checks if the element uses the 'webform_multiple' element. Overrides WebformElementBase::hasMultipleWrapper
OptionsBase::isMultiline public function Checks if the element value could contain multiple lines. Overrides WebformElementBase::isMultiline
OptionsBase::isOptionsOther protected function Determine if the element plugin type includes an other option text field.
OptionsBase::prepare public function Prepare an element to be rendered within a webform. Overrides WebformElementBase::prepare 2
OptionsBase::prepareElementValidateCallbacks protected function Prepare an element's validation callbacks. Overrides WebformElementBase::prepareElementValidateCallbacks
OptionsBase::preview public function Generate a renderable preview of the element. Overrides WebformElementBase::preview 2
OptionsBase::processOptionsProperties public static function Processes options (custom) properties.
OptionsBase::setDefaultValue public function Set an element's default value using saved data. Overrides WebformElementBase::setDefaultValue 1
OptionsBase::validateMultipleOptions public static function Form API callback. Remove unchecked options from value array.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TextBaseTrait::buildCounterForm public function Build counter widget used by text elements and other element.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.
WebformCompositeFormElementTrait::preRenderWebformCompositeFormElement public static function Adds form element theming to an element if its title or description is set. 1
WebformElementBase::$configFactory protected property The configuration factory.
WebformElementBase::$currentUser protected property The current user.
WebformElementBase::$defaultProperties protected property An associative array of an element's default properties names and values.
WebformElementBase::$elementInfo protected property A element info manager.
WebformElementBase::$elementManager protected property The webform element manager.
WebformElementBase::$entityTypeManager protected property The entity type manager.
WebformElementBase::$librariesManager protected property The webform libraries manager.
WebformElementBase::$logger protected property A logger instance.
WebformElementBase::$submissionStorage protected property The webform submission storage.
WebformElementBase::$tokenManager protected property The token manager.
WebformElementBase::$translatableProperties protected property An indexed array of an element's translated properties.
WebformElementBase::alterForm public function Alter an element's associated form. Overrides WebformElementInterface::alterForm 1
WebformElementBase::build protected function Build an element as text or HTML. 4
WebformElementBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 3
WebformElementBase::buildConfigurationFormTabs protected function Build configuration form tabs. 1
WebformElementBase::buildHtml public function Build an element as HTML element. Overrides WebformElementInterface::buildHtml 2
WebformElementBase::buildText public function Build an element as text element. Overrides WebformElementInterface::buildText 1
WebformElementBase::checkAccessRule protected function Checks an access rule against a user account's roles and id.
WebformElementBase::checkAccessRules public function Check element access (rules). Overrides WebformElementInterface::checkAccessRules
WebformElementBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 2
WebformElementBase::defineDefaultBaseProperties protected function Define default base properties used by all elements. 4
WebformElementBase::defineDefaultMultipleProperties protected function Define default multiple properties used by most elements. 1
WebformElementBase::displayDisabledWarning public function Display element disabled warning. Overrides WebformElementInterface::displayDisabledWarning 1
WebformElementBase::finalize public function Finalize an element to be rendered within a webform. Overrides WebformElementInterface::finalize 1
WebformElementBase::format protected function Format an element's value as HTML or plain text. 2
WebformElementBase::formatCustomItem protected function Format an element's item using custom HTML or plain text. 2
WebformElementBase::formatCustomItems protected function Format an element's items using custom HTML or plain text.
WebformElementBase::formatHtml public function Format an element's value as HTML. Overrides WebformElementInterface::formatHtml 2
WebformElementBase::formatTableColumn public function Format an element's table column value. Overrides WebformElementInterface::formatTableColumn 4
WebformElementBase::formatText public function Format an element's value as plain text. Overrides WebformElementInterface::formatText 2
WebformElementBase::getAdminLabel public function Get an element's admin label (#admin_title, #title or #webform_key). Overrides WebformElementInterface::getAdminLabel
WebformElementBase::getConfigurationFormProperties public function Get an associative array of element properties from configuration webform. Overrides WebformElementInterface::getConfigurationFormProperties 3
WebformElementBase::getConfigurationFormProperty protected function Get configuration property value. 1
WebformElementBase::getDefaultBaseProperties Deprecated protected function Get default base properties used by all elements.
WebformElementBase::getDefaultKey public function Gets the element's default key. Overrides WebformElementInterface::getDefaultKey 1
WebformElementBase::getDefaultMultipleProperties Deprecated protected function Get default multiple properties used by most elements.
WebformElementBase::getDefaultProperties public function Get default properties. Overrides WebformElementInterface::getDefaultProperties
WebformElementBase::getDefaultProperty public function Get an element's default property value. Overrides WebformElementInterface::getDefaultProperty
WebformElementBase::getElementInfoDefaultProperty protected function Get a render element's default property.
WebformElementBase::getElementProperty public function Get an element's property value. Overrides WebformElementInterface::getElementProperty
WebformElementBase::getElementStateOptions public function Get an element's supported states as options. Overrides WebformElementInterface::getElementStateOptions 1
WebformElementBase::getFormElementClassDefinition public function Get the Webform element's form element class definition. Overrides WebformElementInterface::getFormElementClassDefinition
WebformElementBase::getFormInlineContainer protected function Get form--inline container which is used for side-by-side element layout.
WebformElementBase::getInfo public function Retrieves the default properties for the defined element type. Overrides WebformElementInterface::getInfo
WebformElementBase::getItemDefaultFormat public function Get an element's default single value format name. Overrides WebformElementInterface::getItemDefaultFormat 23
WebformElementBase::getItemFormat public function Get element's single value format name by looking for '#format' property, global settings, and finally default settings. Overrides WebformElementInterface::getItemFormat 1
WebformElementBase::getItemsFormat public function Get element's multiple value format name by looking for '#format' property, global settings, and finally default settings. Overrides WebformElementInterface::getItemsFormat
WebformElementBase::getKey public function Get an element's key/name. Overrides WebformElementInterface::getKey
WebformElementBase::getLabel public function Get an element's label (#title or #webform_key). Overrides WebformElementInterface::getLabel
WebformElementBase::getOffCanvasWidth public function Get configuration form's off-canvas width. Overrides WebformElementInterface::getOffCanvasWidth 1
WebformElementBase::getPluginApiLink public function Get link to element's API documentation. Overrides WebformElementInterface::getPluginApiLink
WebformElementBase::getPluginApiUrl public function Get the URL for the element's API documentation. Overrides WebformElementInterface::getPluginApiUrl
WebformElementBase::getPluginCategory public function Gets the category of the plugin instance. Overrides WebformElementInterface::getPluginCategory
WebformElementBase::getPluginDescription public function Gets the description of the plugin instance. Overrides WebformElementInterface::getPluginDescription
WebformElementBase::getPluginLabel public function Gets the label of the plugin instance. Overrides WebformElementInterface::getPluginLabel 3
WebformElementBase::getRawValue public function Get an element's submission raw value. Overrides WebformElementInterface::getRawValue
WebformElementBase::getTestValues public function Get test values for an element. Overrides WebformElementInterface::getTestValues 23
WebformElementBase::getTranslatableProperties public function Get translatable properties. Overrides WebformElementInterface::getTranslatableProperties
WebformElementBase::getTypeName public function Gets the type name (aka id) of the plugin instance with the 'webform_' prefix. Overrides WebformElementInterface::getTypeName
WebformElementBase::getValue public function Get an element's submission value. Overrides WebformElementInterface::getValue 1
WebformElementBase::hasCompositeFormElementWrapper protected function Determine if the element has a composite field wrapper.
WebformElementBase::hasManagedFiles public function Determine if the element is or includes a managed_file upload element. Overrides WebformElementInterface::hasManagedFiles 2
WebformElementBase::hasMultipleValues public function Checks if the element value has multiple values. Overrides WebformElementInterface::hasMultipleValues 6
WebformElementBase::hasProperty public function Determine if the element supports a specified property. Overrides WebformElementInterface::hasProperty
WebformElementBase::hasValue public function Determine if an element's has a submission value. Overrides WebformElementInterface::hasValue 2
WebformElementBase::hasWrapper public function Checks if the element has a wrapper. Overrides WebformElementInterface::hasWrapper
WebformElementBase::hiddenElementAfterBuild public static function Webform element #after_build callback.
WebformElementBase::initialize public function Initialize an element to be displayed, rendered, or exported. Overrides WebformElementInterface::initialize 8
WebformElementBase::isComposite public function Checks if the element is a composite element. Overrides WebformElementInterface::isComposite
WebformElementBase::isContainer public function Checks if the element is a container that can contain elements. Overrides WebformElementInterface::isContainer 9
WebformElementBase::isDisabled public function Checks if the element is disabled. Overrides WebformElementInterface::isDisabled
WebformElementBase::isEmptyExcluded public function Checks if an empty element is excluded. Overrides WebformElementInterface::isEmptyExcluded 1
WebformElementBase::isEnabled public function Checks if the element is enabled. Overrides WebformElementInterface::isEnabled 1
WebformElementBase::isExcluded public function Checks if the element is excluded via webform.settings. Overrides WebformElementInterface::isExcluded
WebformElementBase::isHidden public function Checks if the element is hidden. Overrides WebformElementInterface::isHidden 2
WebformElementBase::isInput public function Checks if the element carries a value. Overrides WebformElementInterface::isInput 11
WebformElementBase::isRoot public function Checks if the element is a root element. Overrides WebformElementInterface::isRoot 3
WebformElementBase::postCreate public function Acts on a webform submission element after it is created. Overrides WebformElementInterface::postCreate 1
WebformElementBase::postDelete public function Delete any additional value associated with an element. Overrides WebformElementInterface::postDelete 5
WebformElementBase::postLoad public function Acts on loaded webform submission. Overrides WebformElementInterface::postLoad 1
WebformElementBase::postSave public function Acts on a saved webform submission element before the insert or update hook is invoked. Overrides WebformElementInterface::postSave 5
WebformElementBase::preCreate public function Changes the values of an entity before it is created. Overrides WebformElementInterface::preCreate 1
WebformElementBase::preDelete public function 1
WebformElementBase::prefixExportHeader protected function Prefix an element's export header.
WebformElementBase::prepareCompositeFormElement protected function Replace Core's composite #pre_render with Webform's composite #pre_render.
WebformElementBase::prepareElementPreRenderCallbacks protected function Prepare an element's pre render callbacks. 3
WebformElementBase::prepareMultipleWrapper protected function Set multiple element wrapper. 1
WebformElementBase::prepareWrapper protected function Set an elements #states and flexbox wrapper. 1
WebformElementBase::preRenderFixFlexboxWrapper public static function Fix flexbox wrapper.
WebformElementBase::preRenderFixStatesWrapper public static function Fix state wrapper.
WebformElementBase::preSave public function Acts on a webform submission element before the presave hook is invoked. Overrides WebformElementInterface::preSave 4
WebformElementBase::replaceTokens public function Replace tokens for all element properties. Overrides WebformElementInterface::replaceTokens
WebformElementBase::setConfigurationFormDefaultValue protected function Set an element's configuration webform element default value. 2
WebformElementBase::setConfigurationFormDefaultValueRecursive protected function Set configuration webform default values recursively.
WebformElementBase::setElementDefaultCallback protected function Set element's default callback.
WebformElementBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
WebformElementBase::supportsMultipleValues public function Checks if the element supports multiple values. Overrides WebformElementInterface::supportsMultipleValues 8
WebformElementBase::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks 1
WebformElementBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 6
WebformElementBase::validateMinlength public static function Form API callback. Validate element #minlength value.
WebformElementBase::validateMultiple public static function Form API callback. Validate element #multiple > 1 value.
WebformElementBase::validateUnique public static function Form API callback. Validate element #unique value.
WebformElementBase::validateUniqueMultiple public static function Form API callback. Validate element #unique multiple values.
WebformElementBase::__construct public function Constructs a WebformElementBase object. Overrides PluginBase::__construct 2
WebformEntityInjectionTrait::$webform protected property The webform.
WebformEntityInjectionTrait::$webformSubmission protected property The webform submission.
WebformEntityInjectionTrait::getWebform public function Get the webform that this handler is attached to.
WebformEntityInjectionTrait::getWebformSubmission public function Set webform and webform submission entity.
WebformEntityInjectionTrait::resetEntities public function Reset webform and webform submission entity.
WebformEntityInjectionTrait::setEntities public function
WebformEntityInjectionTrait::setWebform public function Set the webform that this is handler is attached to.
WebformEntityInjectionTrait::setWebformSubmission public function Get the webform submission that this handler is handling.