Skip to content
Snippets Groups Projects
Commit c37b56ff authored by Dave Reid's avatar Dave Reid
Browse files

Issue #3342222 by Dave Reid: Fixed Generator::sentence() can often generate an...

Issue #3342222 by Dave Reid: Fixed Generator::sentence() can often generate an empty string with just a period.
parent daa3546f
Branches
Tags
1 merge request!13Issue #3342222: Generator::sentence() can often generate an empty string with just a period.
......@@ -2,12 +2,12 @@
namespace Drupal\styleguide;
use Drupal\Component\Utility\Random;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Pager\PagerManagerInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\Component\Utility\Random;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Render\Markup;
/**
* Class Generator.
......@@ -179,7 +179,7 @@ class Generator implements GeneratorInterface {
*/
public function sentence($link = FALSE) {
$graph = $this->random->sentences(mt_rand(60, 180));
$explode = explode('.', $graph);
$explode = preg_split('/\. ?/', $graph, -1, PREG_SPLIT_NO_EMPTY);
$rand = array_rand($explode);
$sentence = trim($explode[$rand]);
if ($link) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment