public static function Element::oxford in Lightning Core 8.3
Same name and namespace in other branches
- 8.5 src/Element.php \Drupal\lightning_core\Element::oxford()
- 8 src/Element.php \Drupal\lightning_core\Element::oxford()
- 8.2 src/Element.php \Drupal\lightning_core\Element::oxford()
- 8.4 src/Element.php \Drupal\lightning_core\Element::oxford()
Formats a set of strings with an Oxford comma.
Parameters
string[] $items: The set of strings to format.
string $conjunction: (optional) The translated conjunction to insert before the final item. Defaults to 'and'.
Return value
string The single Oxford-ized string.
2 calls to Element::oxford()
- ElementTest::testOxford in tests/
src/ Unit/ ElementTest.php - @covers ::oxford
- ElementTest::testOxford in tests/
src/ Kernel/ ElementTest.php - @covers ::oxford
File
- src/
Element.php, line 110
Class
- Element
- Helpful functions for dealing with renderable arrays and elements.
Namespace
Drupal\lightning_coreCode
public static function oxford(array $items, $conjunction = 'and') {
$count = count($items);
if ($count < 2) {
return (string) reset($items);
}
elseif ($count === 2) {
return reset($items) . ' ' . $conjunction . ' ' . end($items);
}
else {
$items[] = $conjunction . ' ' . array_pop($items);
return implode(', ', $items);
}
}