You are here

protected function WebformDevelSchema::getOptionsMaxlength in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_devel/src/WebformDevelSchema.php \Drupal\webform_devel\WebformDevelSchema::getOptionsMaxlength()

Get element options maxlength from option values.

Parameters

array $element: An element.

Return value

int An element options maxlength from option values.

1 call to WebformDevelSchema::getOptionsMaxlength()
WebformDevelSchema::getElement in modules/webform_devel/src/WebformDevelSchema.php
Get webform element schema.

File

modules/webform_devel/src/WebformDevelSchema.php, line 236

Class

WebformDevelSchema
Provides a webform schema generator.

Namespace

Drupal\webform_devel

Code

protected function getOptionsMaxlength(array $element) {
  $options = OptGroup::flattenOptions($element['#options']);
  $maxlength = 0;
  foreach ($options as $option_value => $option_text) {
    $maxlength = max(mb_strlen($option_value), $maxlength);
  }

  // Check element w/ other value maxlength.
  if (preg_match('/_other$/', $element['#type'])) {
    if (isset($element['#other__maxlength'])) {
      $maxlength = max($element['#other__maxlength'], $maxlength);
    }
    else {

      // @see \Drupal\webform\Plugin\WebformElement\TextField::prepare
      $maxlength = max(255, $maxlength);
    }
  }
  return $maxlength;
}