EventOperation.php in RNG - Events and Registrations 8.2
File
src/Plugin/Condition/EventOperation.php
View source
<?php
namespace Drupal\rng\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
class EventOperation extends ConditionPluginBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['description']['#markup'] = $this
->t('For %operation operations.', [
'%operation' => implode(' ', array_keys($this->configuration['operations'])),
]);
return $form;
}
public function defaultConfiguration() {
return [
'operations' => [
'manage event' => TRUE,
],
] + parent::defaultConfiguration();
}
public function summary() {
$operations = [];
foreach ($this->configuration['operations'] as $operation => $granted) {
if ($granted) {
$operations[] = $this
->t("%operation", [
'%operation' => $operation,
]);
}
}
return $this
->t(!$this
->isNegated() ? 'Logged-in user has access to operations on event: @operations' : 'Logged-in user does not have access to operations on event: @operations', [
'@operations' => count($operations) > 1 ? implode($this
->t(' and '), $operations) : reset($operations),
]);
}
public function evaluate() {
$operation = 'manage event';
$user = $this
->getContextValue('user');
$event = $this
->getContextValue('event');
return $event
->access($operation);
}
}
Classes
Name |
Description |
EventOperation |
Provides an identity has operation permission on event condition. |