public function Generator::sentence in Style Guide 8
Same name and namespace in other branches
- 2.x src/Generator.php \Drupal\styleguide\Generator::sentence()
Generate a random sentence.
Parameters
string $link: The link to add to the sentence.
Overrides GeneratorInterface::sentence
1 call to Generator::sentence()
- Generator::menuItem in src/
Generator.php - Generate a random menu item.
File
- src/
Generator.php, line 180
Class
- Generator
- Class Generator.
Namespace
Drupal\styleguideCode
public function sentence($link = FALSE) {
$graph = $this->random
->sentences(mt_rand(60, 180));
$explode = explode('.', $graph);
$rand = array_rand($explode);
$sentence = trim($explode[$rand]);
if ($link) {
$explode = explode(' ', $sentence);
$link = [
'#type' => 'link',
'#title' => $explode[0],
'#url' => $link,
'#options' => [
'attributes' => [],
'html' => FALSE,
],
'#text' => $explode[0],
];
$explode[0] = render($link);
$sentence = implode(' ', $explode);
}
return Markup::create($sentence . '.');
}