function Random::sentences
Same name in other branches
- 9 core/lib/Drupal/Component/Utility/Random.php \Drupal\Component\Utility\Random::sentences()
- 10 core/lib/Drupal/Component/Utility/Random.php \Drupal\Component\Utility\Random::sentences()
- 11.x core/lib/Drupal/Component/Utility/Random.php \Drupal\Component\Utility\Random::sentences()
Generates sentences Latin words, often used as placeholder text.
Parameters
int $min_word_count: The minimum number of words in the return string. Total word count can slightly exceed provided this value in order to deliver sentences of random length.
bool $capitalize: Uppercase all the words in the string.
Return value
string Nonsense latin words which form sentence(s).
1 call to Random::sentences()
- Random::paragraphs in core/
lib/ Drupal/ Component/ Utility/ Random.php - Generate paragraphs separated by double new line.
File
-
core/
lib/ Drupal/ Component/ Utility/ Random.php, line 194
Class
- Random
- Defines a utility class for creating random data.
Namespace
Drupal\Component\UtilityCode
public function sentences($min_word_count, $capitalize = FALSE) {
$dictionary = [
"abbas",
"abdo",
"abico",
"abigo",
"abluo",
"accumsan",
"acsi",
"ad",
"adipiscing",
"aliquam",
"aliquip",
"amet",
"antehabeo",
"appellatio",
"aptent",
"at",
"augue",
"autem",
"bene",
"blandit",
"brevitas",
"caecus",
"camur",
"capto",
"causa",
"cogo",
"comis",
"commodo",
"commoveo",
"consectetuer",
"consequat",
"conventio",
"cui",
"damnum",
"decet",
"defui",
"diam",
"dignissim",
"distineo",
"dolor",
"dolore",
"dolus",
"duis",
"ea",
"eligo",
"elit",
"enim",
"erat",
"eros",
"esca",
"esse",
"et",
"eu",
"euismod",
"eum",
"ex",
"exerci",
"exputo",
"facilisi",
"facilisis",
"fere",
"feugiat",
"gemino",
"genitus",
"gilvus",
"gravis",
"haero",
"hendrerit",
"hos",
"huic",
"humo",
"iaceo",
"ibidem",
"ideo",
"ille",
"illum",
"immitto",
"importunus",
"imputo",
"in",
"incassum",
"inhibeo",
"interdico",
"iriure",
"iusto",
"iustum",
"jugis",
"jumentum",
"jus",
"laoreet",
"lenis",
"letalis",
"lobortis",
"loquor",
"lucidus",
"luctus",
"ludus",
"luptatum",
"macto",
"magna",
"mauris",
"melior",
"metuo",
"meus",
"minim",
"modo",
"molior",
"mos",
"natu",
"neo",
"neque",
"nibh",
"nimis",
"nisl",
"nobis",
"nostrud",
"nulla",
"nunc",
"nutus",
"obruo",
"occuro",
"odio",
"olim",
"oppeto",
"os",
"pagus",
"pala",
"paratus",
"patria",
"paulatim",
"pecus",
"persto",
"pertineo",
"plaga",
"pneum",
"populus",
"praemitto",
"praesent",
"premo",
"probo",
"proprius",
"quadrum",
"quae",
"qui",
"quia",
"quibus",
"quidem",
"quidne",
"quis",
"ratis",
"refero",
"refoveo",
"roto",
"rusticus",
"saepius",
"sagaciter",
"saluto",
"scisco",
"secundum",
"sed",
"si",
"similis",
"singularis",
"sino",
"sit",
"sudo",
"suscipere",
"suscipit",
"tamen",
"tation",
"te",
"tego",
"tincidunt",
"torqueo",
"tum",
"turpis",
"typicus",
"ulciscor",
"ullamcorper",
"usitas",
"ut",
"utinam",
"utrum",
"uxor",
"valde",
"valetudo",
"validus",
"vel",
"velit",
"veniam",
"venio",
"vereor",
"vero",
"verto",
"vicis",
"vindico",
"virtus",
"voco",
"volutpat",
"vulpes",
"vulputate",
"wisi",
"ymo",
"zelus",
];
$dictionary_flipped = array_flip($dictionary);
$greeking = '';
if (!$capitalize) {
$words_remaining = $min_word_count;
while ($words_remaining > 0) {
$sentence_length = mt_rand(3, 10);
$words = array_rand($dictionary_flipped, $sentence_length);
$sentence = implode(' ', $words);
$greeking .= ucfirst($sentence) . '. ';
$words_remaining -= $sentence_length;
}
}
else {
// Use slightly different method for titles.
$words = array_rand($dictionary_flipped, $min_word_count);
$words = is_array($words) ? implode(' ', $words) : $words;
$greeking = ucwords($words);
}
return trim($greeking);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.