public static function WebformArrayHelper::toString in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Utility/WebformArrayHelper.php \Drupal\webform\Utility\WebformArrayHelper::toString()
Implode an array with commas separating the elements and with an "and" before the last element.
Parameters
array $array: The array to be convert to a string.
string $conjunction: (optional) The word, which should be 'and' or 'or' used to join the values of the array. Defaults to 'and'.
Return value
string The array converted to a string.
20 calls to WebformArrayHelper::toString()
- DateBase::validateDate in src/
Plugin/ WebformElement/ DateBase.php - Webform element validation handler for date elements.
- OptionsBase::form in src/
Plugin/ WebformElement/ OptionsBase.php - Gets the actual configuration webform array to be built.
- Select::form in src/
Plugin/ WebformElement/ Select.php - Gets the actual configuration webform array to be built.
- SettingsWebformHandler::validateConfigurationForm in src/
Plugin/ WebformHandler/ SettingsWebformHandler.php - Form validation handler.
- WebformAdminConfigElementsForm::buildForm in src/
Form/ AdminConfig/ WebformAdminConfigElementsForm.php - Form constructor.
File
- src/
Utility/ WebformArrayHelper.php, line 22
Class
- WebformArrayHelper
- Provides helper to operate on arrays.
Namespace
Drupal\webform\UtilityCode
public static function toString(array $array, $conjunction = NULL) {
if ($conjunction === NULL) {
$conjunction = t('and');
}
switch (count($array)) {
case 0:
return '';
case 1:
return reset($array);
case 2:
return implode(' ' . $conjunction . ' ', $array);
default:
$last = array_pop($array);
return implode(', ', $array) . ', ' . $conjunction . ' ' . $last;
}
}