- Issue created by @dave reid
- πΊπΈUnited States dave reid Nebraska USA
What's happening is a bug in the following code:
public function sentence($link = FALSE) { $graph = $this->random->sentences(mt_rand(60, 180)); $explode = explode('.', $graph); // This $explode will always result in all of its array entries with one space at the beginning of the string, and then an always empty string as the last array value. $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] = \Drupal::service('renderer')->render($link); $sentence = implode(' ', $explode); } return Markup::create($sentence . '.'); }
By changing the first
explode('.', $graph)
call to usepreg_split('/\. ?/', $graph, -1, PREG_SPLIT_NO_EMPTY);
we end up with a clean array of sentences with no empty values or leading spaces in each array value. - @dave-reid opened merge request.
-
Dave Reid β
committed c37b56ff on 2.x
Issue #3342222 by Dave Reid: Fixed Generator::sentence() can often...
-
Dave Reid β
committed c37b56ff on 2.x
- Status changed to Fixed
about 2 years ago 4:47am 16 February 2023 Automatically closed - issue fixed for 2 weeks with no activity.