devel_wizard-2.x-dev/src/Plugin/DevelWizard/Spell/NodeTypeUserRoleSpell.php
src/Plugin/DevelWizard/Spell/NodeTypeUserRoleSpell.php
<?php
declare(strict_types=1);
namespace Drupal\devel_wizard\Plugin\DevelWizard\Spell;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\devel_wizard\Attribute\DevelWizardSpell;
#[DevelWizardSpell(
id: 'devel_wizard_node_type_user_role',
category: new TranslatableMarkup('Content type'),
label: new TranslatableMarkup('Content type - User Role'),
description: new TranslatableMarkup('Creates a new user role which grants full control over a specific Content type.'),
tags: [
'code' => new TranslatableMarkup('Bundle'),
'config_entity' => new TranslatableMarkup('Config entity'),
'node_type' => new TranslatableMarkup('Content type'),
'site_build' => new TranslatableMarkup('Site build'),
'user_role' => new TranslatableMarkup('User role'),
],
)]
class NodeTypeUserRoleSpell extends ConfigEntityUserRoleSpellBase {
protected string $provider = 'node';
protected string $configEntityTypeId = 'node_type';
protected string $contentEntityTypeId = 'node';
/**
* @return array<string, bool>
*/
protected function getDefaultPermissions(): array {
$configuration = $this->getConfiguration();
$machineName = $configuration['machine_name'];
return [
'access administration pages' => TRUE,
'view the administration theme' => TRUE,
"create $machineName content" => TRUE,
"edit any $machineName content" => TRUE,
"delete any $machineName content" => TRUE,
"view $machineName revisions" => TRUE,
"revert $machineName revisions" => TRUE,
"delete $machineName revisions" => TRUE,
];
}
}
