You are here

protected function OptionsLimitWebformHandler::getOptionsLimits 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::getOptionsLimits()

Get an associative array of options limits.

Parameters

array $values: Optional array of values to get options limit.

Return value

array An associative array of options limits keyed by option value and including the option's limit, total, remaining, and status.

3 calls to OptionsLimitWebformHandler::getOptionsLimits()
OptionsLimitWebformHandler::alterElement in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Alter webform element.
OptionsLimitWebformHandler::buildSummaryTable in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Build summary table.
OptionsLimitWebformHandler::validateOptionsElement in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Validate an options element with limit(s).

File

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

Class

OptionsLimitWebformHandler
Webform options and boolean (boolean) limit handler.

Namespace

Drupal\webform_options_limit\Plugin\WebformHandler

Code

protected function getOptionsLimits(array $values = []) {
  $default_limit = isset($this->configuration['limits'][WebformOptionsLimitHandlerInterface::DEFAULT_LIMIT]) ? $this->configuration['limits'][WebformOptionsLimitHandlerInterface::DEFAULT_LIMIT] : NULL;
  $totals = $this
    ->getOptionsTotals($values);
  $options = $this
    ->getElementOptions();
  if ($values) {
    $options = array_intersect_key($options, array_combine($values, $values));
  }
  $limits = [];
  foreach ($options as $option_key => $option_label) {
    $limit = isset($this->configuration['limits'][$option_key]) ? $this->configuration['limits'][$option_key] : $default_limit;
    $total = isset($totals[$option_key]) ? $totals[$option_key] : 0;
    $limits[$option_key] = $this
      ->getLimitInformation($option_label, $limit, $total);
  }
  return $limits;
}