class CreateFixtureNodesForTestingCommands in Permissions by Term 8.2
A Drush commandfile.
Hierarchy
- class \Drupal\permissions_by_term\Commands\CreateFixtureNodesForTestingCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of CreateFixtureNodesForTestingCommands
1 string reference to 'CreateFixtureNodesForTestingCommands'
1 service uses CreateFixtureNodesForTestingCommands
File
- src/
Commands/ CreateFixtureNodesForTestingCommands.php, line 15
Namespace
Drupal\permissions_by_term\CommandsView source
class CreateFixtureNodesForTestingCommands extends DrushCommands {
/**
* @var \Drupal\permissions_by_term\Service\AccessStorage
*/
private $accessStorage;
/**
* @var \Drupal\Component\Utility\Random
*/
private $random;
public function __construct(AccessStorage $accessStorage) {
$this->accessStorage = $accessStorage;
$this->random = new Random();
}
/**
* @command permissions-by-term:create-nodes-with-permissions
* @aliases pbtcnwp
*/
public function createNodesWithPermissions(int $numNodes = 1000) : void {
if ($this
->io()
->confirm('Do you really want to create ' . $numNodes . ' Drupal nodes with permissions? This is a testing feature for the permissions by term module.', FALSE)) {
$this
->io()
->progressStart($numNodes);
for ($i = 0; $i <= $numNodes; ++$i) {
$term = Term::create([
'name' => $this->random
->word(10),
'vid' => 'tags',
]);
$term
->save();
$this->accessStorage
->addTermPermissionsByUserIds([
1,
], $term
->id());
$node = Node::create([
'type' => 'article',
'title' => $this->random
->word(10),
'field_tags' => [
[
'target_id' => $term
->id(),
],
],
]);
$node
->save();
$this
->io()
->progressAdvance();
}
$this
->io()
->progressFinish();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CreateFixtureNodesForTestingCommands:: |
private | property | ||
CreateFixtureNodesForTestingCommands:: |
private | property | ||
CreateFixtureNodesForTestingCommands:: |
public | function | @command permissions-by-term:create-nodes-with-permissions @aliases pbtcnwp | |
CreateFixtureNodesForTestingCommands:: |
public | function |