RegistrationAccess.php in RNG - Events and Registrations 3.x
File
src/Plugin/Action/RegistrationAccess.php
View source
<?php
namespace Drupal\rng\Plugin\Action;
use Drupal\Core\Action\ConfigurableActionBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Session\AccountInterface;
class RegistrationAccess extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function defaultConfiguration() {
return [
'operations' => [],
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$this->configuration['operations'] += [
'create' => NULL,
'view' => NULL,
'update' => NULL,
'delete' => NULL,
];
$options = [];
$values = [];
foreach ($this->configuration['operations'] as $operation => $checked) {
$options[$operation] = $operation;
$values[$operation] = $checked ? $operation : NULL;
}
$form['operations'] = [
'#title' => $this
->t('Operations'),
'#description' => $this
->t('Select which operations to grant.'),
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $values,
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$operations = $form_state
->getValue('operations');
foreach ($operations as $op => $checked) {
$this->configuration['operations'][$op] = $checked ? TRUE : NULL;
}
}
public function execute($context = NULL) {
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
}
}