GroupEvent.php in Event 8
File
modules/gevent/src/Plugin/GroupContentEnabler/GroupEvent.php
View source
<?php
namespace Drupal\gevent\Plugin\GroupContentEnabler;
use Drupal\group\Entity\GroupInterface;
use Drupal\group\Plugin\GroupContentEnablerBase;
use Drupal\event\Entity\EventType;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
class GroupEvent extends GroupContentEnablerBase {
protected function getEventType() {
return EventType::load($this
->getEntityBundle());
}
public function getGroupOperations(GroupInterface $group) {
$account = \Drupal::currentUser();
$plugin_id = $this
->getPluginId();
$type = $this
->getEntityBundle();
$operations = [];
if ($group
->hasPermission("create {$plugin_id} entity", $account)) {
$route_params = [
'group' => $group
->id(),
'plugin_id' => $plugin_id,
];
$operations["gevent-create-{$type}"] = [
'title' => $this
->t('Add @type', [
'@type' => $this
->getEventType()
->label(),
]),
'url' => new Url('entity.group_content.create_form', $route_params),
'weight' => 30,
];
}
return $operations;
}
protected function getTargetEntityPermissions() {
$permissions = parent::getTargetEntityPermissions();
$plugin_id = $this
->getPluginId();
$original = $permissions["view {$plugin_id} entity"];
$permissions["view unpublished {$plugin_id} entity"] = [
'title' => str_replace('View ', 'View unpublished ', $original['title']),
] + $original;
return $permissions;
}
public function defaultConfiguration() {
$config = parent::defaultConfiguration();
$config['entity_cardinality'] = 1;
return $config;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$info = $this
->t("This field has been disabled by the plugin to guarantee the functionality that's expected of it.");
$form['entity_cardinality']['#disabled'] = TRUE;
$form['entity_cardinality']['#description'] .= '<br /><em>' . $info . '</em>';
return $form;
}
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$dependencies['config'][] = 'event.type.' . $this
->getEntityBundle();
return $dependencies;
}
}