You are here

protected function OptionsLimitWebformHandler::getOptionsLimitLabel in Webform 8.5

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

Get option limit label.

Parameters

string $label: An option's label.

array $limit: The option's limit information.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup|string An option's limit label.

1 call to OptionsLimitWebformHandler::getOptionsLimitLabel()
OptionsLimitWebformHandler::alterOptionsElementLabels in modules/webform_options_limit/src/Plugin/WebformHandler/OptionsLimitWebformHandler.php
Alter an options element's option labels recursively.

File

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

Class

OptionsLimitWebformHandler
Webform options and boolean (boolean) limit handler.

Namespace

Drupal\webform_options_limit\Plugin\WebformHandler

Code

protected function getOptionsLimitLabel($label, array $limit) {
  $message_display = $this->configuration['option_message_display'];
  if ($message_display === WebformOptionsLimitHandlerInterface::MESSAGE_DISPLAY_NONE) {
    return $label;
  }
  $message = $this
    ->getElementLimitStatusMessage($limit['status'], $limit);
  if (!$message) {
    return $label;
  }
  switch ($message_display) {
    case WebformOptionsLimitHandlerInterface::MESSAGE_DISPLAY_LABEL:
      $t_args = [
        '@label' => $label,
        '@message' => $message,
      ];
      return $this
        ->t('@label @message', $t_args);
    case WebformOptionsLimitHandlerInterface::MESSAGE_DISPLAY_DESCRIPTION:
      return $label . (!WebformOptionsHelper::hasOptionDescription($label) ? WebformOptionsHelper::DESCRIPTION_DELIMITER : '') . $message;
  }
}