You are here

public static function YamlFormOptionsHelper::range in YAML Form 8

Build an associative array containing a range of options.

Parameters

int|string $min: First value of the sequence.

int $max: The sequence is ended upon reaching the end value.

int $step: Increments between the range. Default value is 1.

int $pad_length: Number of character to be prepended to the range.

string $pad_str: The character to default the string.

Return value

array An associative array containing a range of options.

2 calls to YamlFormOptionsHelper::range()
YamlFormOptionsHelperTest::testRange in tests/src/Unit/YamlFormOptionsHelperTest.php
Tests YamlFormOptionsHelper::range().
yamlform_yamlform_options_range_alter in includes/yamlform.options.inc
Implements hook_yamlform_options_YAMLFORM_OPTIONS_ID_alter().

File

src/Utility/YamlFormOptionsHelper.php, line 117

Class

YamlFormOptionsHelper
Helper class form options based methods.

Namespace

Drupal\yamlform\Utility

Code

public static function range($min = 1, $max = 100, $step = 1, $pad_length = NULL, $pad_str = '0') {

  // Create range.
  $range = range($min, $max, $step);

  // Pad left on range.
  if ($pad_length) {
    $range = array_map(function ($item) use ($pad_length, $pad_str) {
      return str_pad($item, $pad_length, $pad_str, STR_PAD_LEFT);
    }, $range);
  }

  // Return associative array of range options.
  return array_combine($range, $range);
}