You are here

protected function ContentDevelGenerate::develGenerateContentPreNode in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentPreNode()
  2. 8 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentPreNode()
  3. 8.2 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::develGenerateContentPreNode()

Preprocesses $results before adding content.

Parameters

array $results: Results information.

3 calls to ContentDevelGenerate::develGenerateContentPreNode()
ContentDevelGenerate::batchContentPreNode in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Batch wrapper for calling ContentPreNode.
ContentDevelGenerate::generateContent in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Generate content when not in batch mode.
ContentDevelGenerate::validateDrushParams in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php
Responsible for validating Drush params.

File

devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php, line 595

Class

ContentDevelGenerate
Provides a ContentDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function develGenerateContentPreNode(array &$results) {
  $authors = $results['authors'];

  // Remove non-selected users. !== 0 will leave the Anonymous user in if it
  // was selected on the form or entered in the drush parameters.
  $authors = array_filter($authors, function ($k) {
    return $k !== 0;
  });

  // If no users are specified then get a random set up to a maximum of 50.
  // There is no direct way randomise the selection using entity queries, so
  // we use a database query instead.
  if (empty($authors)) {
    $query = $this->database
      ->select('users', 'u')
      ->fields('u', [
      'uid',
    ])
      ->range(0, 50)
      ->orderRandom();
    $authors = $query
      ->execute()
      ->fetchCol();
  }
  $results['users'] = $authors;
}