You are here

class GroupEvent in Event 8

Provides a content enabler for events.

Plugin annotation


@GroupContentEnabler(
  id = "group_event",
  label = @Translation("Group event"),
  description = @Translation("Adds events to groups both publicly and privately."),
  entity_type_id = "event",
  entity_access = TRUE,
  reference_label = @Translation("Title"),
  reference_description = @Translation("The title of the event to add to the group"),
  deriver = "Drupal\gevent\Plugin\GroupContentEnabler\GroupEventDeriver"
)

Hierarchy

Expanded class hierarchy of GroupEvent

File

modules/gevent/src/Plugin/GroupContentEnabler/GroupEvent.php, line 25

Namespace

Drupal\gevent\Plugin\GroupContentEnabler
View source
class GroupEvent extends GroupContentEnablerBase {

  /**
   * Retrieves the event type this plugin supports.
   *
   * @return \Drupal\event\EventTypeInterface
   *   The event type this plugin supports.
   */
  protected function getEventType() {
    return EventType::load($this
      ->getEntityBundle());
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected function getTargetEntityPermissions() {
    $permissions = parent::getTargetEntityPermissions();
    $plugin_id = $this
      ->getPluginId();

    // Add a 'view unpublished' permission by re-using most of the 'view' one.
    $original = $permissions["view {$plugin_id} entity"];
    $permissions["view unpublished {$plugin_id} entity"] = [
      'title' => str_replace('View ', 'View unpublished ', $original['title']),
    ] + $original;
    return $permissions;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    $config = parent::defaultConfiguration();
    $config['entity_cardinality'] = 1;
    return $config;
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    // Disable the entity cardinality field as the functionality of this module
    // relies on a cardinality of 1. We don't just hide it, though, to keep a UI
    // that's consistent with other content enabler plugins.
    $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;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    $dependencies['config'][] = 'event.type.' . $this
      ->getEntityBundle();
    return $dependencies;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
GroupContentEnablerBase::$groupTypeId protected property The ID of group type this plugin was instantiated for.
GroupContentEnablerBase::$_permissions private property Backwards compatible permission array.
GroupContentEnablerBase::checkAccess public function Checks access to an operation on a given group content entity. Overrides GroupContentEnablerInterface::checkAccess
GroupContentEnablerBase::createAccess public function Performs access check for the create operation. Overrides GroupContentEnablerInterface::createAccess
GroupContentEnablerBase::createEntityAccess public function Performs access check for the create target entity operation. Overrides GroupContentEnablerInterface::createEntityAccess
GroupContentEnablerBase::definesEntityAccess public function Returns whether this plugin defines entity access. Overrides GroupContentEnablerInterface::definesEntityAccess
GroupContentEnablerBase::deleteAccess protected function Performs access check for the delete operation.
GroupContentEnablerBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
GroupContentEnablerBase::getContentLabel public function Retrieves the label for a piece of group content. Overrides GroupContentEnablerInterface::getContentLabel
GroupContentEnablerBase::getContentTypeConfigId public function Returns a safe, unique configuration ID for a group content type. Overrides GroupContentEnablerInterface::getContentTypeConfigId
GroupContentEnablerBase::getContentTypeDescription public function Returns the administrative description for a group content type. Overrides GroupContentEnablerInterface::getContentTypeDescription
GroupContentEnablerBase::getContentTypeLabel public function Returns the administrative label for a group content type. Overrides GroupContentEnablerInterface::getContentTypeLabel
GroupContentEnablerBase::getDescription public function Returns the administrative description for the plugin. Overrides GroupContentEnablerInterface::getDescription
GroupContentEnablerBase::getEntityBundle public function Returns the entity bundle the plugin supports. Overrides GroupContentEnablerInterface::getEntityBundle
GroupContentEnablerBase::getEntityCardinality public function Returns the amount of times the same content can be added to a group. Overrides GroupContentEnablerInterface::getEntityCardinality
GroupContentEnablerBase::getEntityReferenceDescription public function Returns the description for the entity reference field. Overrides GroupContentEnablerInterface::getEntityReferenceDescription
GroupContentEnablerBase::getEntityReferenceLabel public function Returns the label for the entity reference field. Overrides GroupContentEnablerInterface::getEntityReferenceLabel
GroupContentEnablerBase::getEntityReferenceSettings public function Returns a list of entity reference field settings. Overrides GroupContentEnablerInterface::getEntityReferenceSettings 1
GroupContentEnablerBase::getEntityType protected function Returns the entity type definition the plugin supports.
GroupContentEnablerBase::getEntityTypeId public function Returns the entity type ID the plugin supports. Overrides GroupContentEnablerInterface::getEntityTypeId
GroupContentEnablerBase::getGroupCardinality public function Returns the amount of groups the same content can be added to. Overrides GroupContentEnablerInterface::getGroupCardinality
GroupContentEnablerBase::getGroupContentPermissions Deprecated protected function Provides permissions for the group content entity; i.e. the relationship.
GroupContentEnablerBase::getGroupOperationsCacheableMetadata public function Provides the cacheable metadata for this plugin's group operations. Overrides GroupContentEnablerInterface::getGroupOperationsCacheableMetadata 1
GroupContentEnablerBase::getGroupType public function Returns the group type the plugin was instantiated for. Overrides GroupContentEnablerInterface::getGroupType
GroupContentEnablerBase::getGroupTypeId public function Returns the ID of the group type the plugin was instantiated for. Overrides GroupContentEnablerInterface::getGroupTypeId
GroupContentEnablerBase::getLabel public function Returns the administrative label for the plugin. Overrides GroupContentEnablerInterface::getLabel
GroupContentEnablerBase::getOperations public function Provides a list of operations for the content enabler plugin. Overrides GroupContentEnablerInterface::getOperations
GroupContentEnablerBase::getPermissions public function Provides a list of group permissions the plugin exposes. Overrides GroupContentEnablerInterface::getPermissions
GroupContentEnablerBase::getPrettyPathKey public function Returns the pretty path key for use in path aliases. Overrides GroupContentEnablerInterface::getPrettyPathKey
GroupContentEnablerBase::getProvider public function Returns the plugin provider. Overrides GroupContentEnablerInterface::getProvider
GroupContentEnablerBase::isCodeOnly public function Returns whether this plugin can only be (un)installed through code. Overrides GroupContentEnablerInterface::isCodeOnly
GroupContentEnablerBase::isEnforced public function Returns whether this plugin is always on. Overrides GroupContentEnablerInterface::isEnforced
GroupContentEnablerBase::postInstall public function Runs tasks after the group content type for this plugin has been created. Overrides GroupContentEnablerInterface::postInstall 1
GroupContentEnablerBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
GroupContentEnablerBase::submitConfigurationForm public function Only override this function if you need to do something specific to the submitted data before it is saved as configuration on the plugin. The data gets saved on the plugin in \Drupal\group\Entity\Form\GroupContentTypeForm. Overrides PluginFormInterface::submitConfigurationForm
GroupContentEnablerBase::updateAccess protected function Performs access check for the update operation.
GroupContentEnablerBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
GroupContentEnablerBase::viewAccess protected function Performs access check for the view operation.
GroupContentEnablerBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
GroupEvent::buildConfigurationForm public function Form constructor. Overrides GroupContentEnablerBase::buildConfigurationForm
GroupEvent::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides GroupContentEnablerBase::calculateDependencies
GroupEvent::defaultConfiguration public function Gets default configuration for this plugin. Overrides GroupContentEnablerBase::defaultConfiguration
GroupEvent::getEventType protected function Retrieves the event type this plugin supports.
GroupEvent::getGroupOperations public function Provides a list of operations for a group. Overrides GroupContentEnablerBase::getGroupOperations
GroupEvent::getTargetEntityPermissions protected function Provides permissions for the actual entity being added to the group. Overrides GroupContentEnablerBase::getTargetEntityPermissions
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.