You are here

protected function OptionsLimitWebformHandler::getElements in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php \Drupal\webform_options_limit\Plugin\WebformHandler\OptionsLimitWebformHandler::getElements()

Get key/value array of webform options or boolean elements.

Return value

array A key/value array of webform options or boolean elements.

1 call to OptionsLimitWebformHandler::getElements()
OptionsLimitWebformHandler::buildConfigurationForm in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Form constructor.

File

modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php, line 1081

Class

OptionsLimitWebformHandler
Webform options and boolean (boolean) limit handler.

Namespace

Drupal\webform_options_limit\Plugin\WebformHandler

Code

protected function getElements() {
  $webform = $this
    ->getWebform();
  $elements = $webform
    ->getElementsInitializedAndFlattened();
  $options = [];
  foreach ($elements as $element) {
    $webform_element = $this->elementManager
      ->getElementInstance($element);
    $is_options_element = $webform_element
      ->hasProperty('options');
    $is_entity_options_element = $webform_element instanceof WebformElementEntityOptionsInterface;
    $is_boolean_element = $webform_element instanceof BooleanBase;
    if ($is_options_element || $is_entity_options_element || $is_boolean_element) {
      $webform_key = $element['#webform_key'];
      $t_args = [
        '@title' => $webform_element
          ->getAdminLabel($element),
        '@type' => $webform_element
          ->getPluginLabel(),
      ];
      $options[$webform_key] = $this
        ->t('@title (@type)', $t_args);
    }
  }

  // Exclude elements being used by other options limit handlers.
  $handlers = $webform
    ->getHandlers();
  foreach ($handlers as $handler) {
    if ($handler instanceof WebformOptionsLimitHandlerInterface && $handler
      ->getHandlerId() !== $this
      ->getHandlerId()) {
      $element_key = $handler
        ->getSetting('element_key');
      unset($options[$element_key]);
    }
  }
  return $options;
}