class WorkflowAccessRoleForm in Workflow 8
Provides the base form for workflow add and edit forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\workflow\Form\WorkflowConfigTransitionFormBase
- class \Drupal\workflow_access\Form\WorkflowAccessRoleForm
- class \Drupal\workflow\Form\WorkflowConfigTransitionFormBase
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of WorkflowAccessRoleForm
1 string reference to 'WorkflowAccessRoleForm'
- workflow_access.routing.yml in modules/
workflow_access/ workflow_access.routing.yml - modules/workflow_access/workflow_access.routing.yml
File
- modules/
workflow_access/ src/ Form/ WorkflowAccessRoleForm.php, line 14
Namespace
Drupal\workflow_access\FormView source
class WorkflowAccessRoleForm extends WorkflowConfigTransitionFormBase {
/**
* {@inheritdoc}
*/
protected $entitiesKey = 'workflow_state';
/**
* The WorkflowConfigTransition form type.
*
* @var string
*/
protected $type = 'access';
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'workflow_access_role';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'workflow_access.role',
];
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [
'label_new' => $this
->t('State'),
'view' => $this
->t('Roles who can view posts in this state'),
'update' => $this
->t('Roles who can edit posts in this state'),
'delete' => $this
->t('Roles who can delete posts in this state'),
];
return $header;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row = [];
$workflow = $this->workflow;
if ($workflow) {
/** @var \Drupal\workflow\Entity\WorkflowState $state */
$state = $entity;
$sid = $state
->id();
// A list of role names keyed by role ID, including the 'author' role.
// Only get the roles with proper permission + Author role.
$type_id = $workflow
->id();
$roles = workflow_get_user_role_names("create {$type_id} workflow_transition");
if ($state
->isCreationState()) {
// No need to set perms on creation.
return [];
}
$view = $update = $delete = [];
$count = 0;
foreach (workflow_access_get_workflow_access_by_sid($sid) as $rid => $access) {
$count++;
$view[$rid] = $access['grant_view'] ? $rid : 0;
$update[$rid] = $access['grant_update'] ? $rid : 0;
$delete[$rid] = $access['grant_delete'] ? $rid : 0;
}
// Allow view grants by default for anonymous and authenticated users,
// if no grants were set up earlier.
if (!$count) {
$view = [
AccountInterface::ANONYMOUS_ROLE => AccountInterface::ANONYMOUS_ROLE,
AccountInterface::AUTHENTICATED_ROLE => AccountInterface::AUTHENTICATED_ROLE,
];
}
$row['label_new'] = [
'#type' => 'value',
'#markup' => $this
->t('@label', [
'@label' => $state
->label(),
]),
];
$row['view'] = [
'#type' => 'checkboxes',
'#options' => $roles,
'#default_value' => $view,
];
$row['update'] = [
'#type' => 'checkboxes',
'#options' => $roles,
'#default_value' => $update,
];
$row['delete'] = [
'#type' => 'checkboxes',
'#options' => $roles,
'#default_value' => $delete,
];
}
return $row;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state
->getValue($this->entitiesKey) as $sid => $access) {
// @todo Not waterproof; can be done smarter, using elementchildren().
if (!WorkflowState::load($sid)) {
continue;
}
foreach ($access['view'] as $rid => $checked) {
$data[$rid] = [
'grant_view' => !empty($access['view'][$rid]) ? (bool) $access['view'][$rid] : 0,
'grant_update' => !empty($access['update'][$rid]) ? (bool) $access['update'][$rid] : 0,
'grant_delete' => !empty($access['delete'][$rid]) ? (bool) $access['delete'][$rid] : 0,
];
}
workflow_access_insert_workflow_access_by_sid($sid, $data);
// Update all nodes to reflect new settings.
node_access_needs_rebuild(TRUE);
}
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WorkflowAccessRoleForm:: |
protected | property |
The key to use for the form element containing the entities. Overrides WorkflowConfigTransitionFormBase:: |
|
WorkflowAccessRoleForm:: |
protected | property |
The WorkflowConfigTransition form type. Overrides WorkflowConfigTransitionFormBase:: |
|
WorkflowAccessRoleForm:: |
public | function | ||
WorkflowAccessRoleForm:: |
public | function | ||
WorkflowAccessRoleForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides WorkflowConfigTransitionFormBase:: |
|
WorkflowAccessRoleForm:: |
public | function |
Returns a unique string identifying the form. Overrides WorkflowConfigTransitionFormBase:: |
|
WorkflowAccessRoleForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
WorkflowConfigTransitionFormBase:: |
protected | property | The entities being listed. | |
WorkflowConfigTransitionFormBase:: |
protected | property | The messenger / logger service. | |
WorkflowConfigTransitionFormBase:: |
protected | property | The workflow object. | |
WorkflowConfigTransitionFormBase:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
WorkflowConfigTransitionFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
WorkflowConfigTransitionFormBase:: |
public | function | Create an $entity for every ConfigTransition. | |
WorkflowConfigTransitionFormBase:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |