function ContentDevelGenerate::develGenerateContentPreNode

Same name in other branches
  1. 5.x 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 598

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;
}