class GroupMenu in Group Menu 8
Provides a content enabler for nodes.
Plugin annotation
@GroupContentEnabler(
id = "group_menu",
label = @Translation("Group menu"),
description = @Translation("Adds menus to groups both publicly and privately."),
entity_type_id = "menu",
entity_access = TRUE,
pretty_path_key = "menu",
reference_label = @Translation("Title"),
reference_description = @Translation("The title of the menu to add to the group"),
deriver = "Drupal\groupmenu\Plugin\GroupContentEnabler\GroupMenuDeriver"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\group\Plugin\GroupContentEnablerBase implements GroupContentEnablerInterface
- class \Drupal\groupmenu\Plugin\GroupContentEnabler\GroupMenu
- class \Drupal\group\Plugin\GroupContentEnablerBase implements GroupContentEnablerInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GroupMenu
File
- src/
Plugin/ GroupContentEnabler/ GroupMenu.php, line 28
Namespace
Drupal\groupmenu\Plugin\GroupContentEnablerView source
class GroupMenu extends GroupContentEnablerBase {
/**
* {@inheritdoc}
*/
public function getGroupOperations(GroupInterface $group) {
$account = \Drupal::currentUser();
$plugin_id = $this
->getPluginId();
$operations = [];
if ($group
->hasPermission("create {$plugin_id} entity", $account)) {
$route_params = [
'group' => $group
->id(),
'plugin_id' => $plugin_id,
];
$operations["groupmenu-create"] = [
'title' => $this
->t('Create menu'),
'url' => new Url('entity.group_content.create_form', $route_params),
'weight' => 30,
];
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function getPermissions() {
// Add custom permissions for managing the menus since we don't have
// "edit own" / "edit any".
$plugin_id = $this
->getPluginId();
// Allow permissions here and in child classes to easily use the plugin name
// and target entity type name in their titles and descriptions.
$t_args = [
'%plugin_name' => $this
->getLabel(),
'%entity_type' => $this
->getEntityType()
->getSingularLabel(),
];
$defaults = [
'title_args' => $t_args,
'description_args' => $t_args,
];
// Use the same title prefix to keep permissions sorted properly.
$entity_prefix = '%plugin_name - Entity:';
$relation_prefix = '%plugin_name - Relationship:';
$permissions["view {$plugin_id} entity"] = [
'title' => "{$entity_prefix} View %entity_type entities",
] + $defaults;
$permissions["create {$plugin_id} entity"] = [
'title' => "{$entity_prefix} Add %entity_type entities",
'description' => 'Allows you to create a new %entity_type entity and relate it to the group.',
] + $defaults;
$permissions["update {$plugin_id} entity"] = [
'title' => "{$entity_prefix} Edit %entity_type entities",
] + $defaults;
$permissions["delete {$plugin_id} entity"] = [
'title' => "{$entity_prefix} Delete %entity_type entities",
] + $defaults;
$permissions["view {$plugin_id} content"] = [
'title' => "{$relation_prefix} View entity relations",
] + $defaults;
$permissions["create {$plugin_id} content"] = [
'title' => "{$relation_prefix} Add entity relation",
'description' => 'Allows you to relate an existing %entity_type entity to the group.',
] + $defaults;
$permissions["update {$plugin_id} content"] = [
'title' => "{$relation_prefix} Edit entity relations",
] + $defaults;
$permissions["delete {$plugin_id} content"] = [
'title' => "{$relation_prefix} Delete entity relations",
] + $defaults;
return $permissions;
}
/**
* {@inheritdoc}
*/
protected function updateAccess(GroupContentInterface $group_content, AccountInterface $account) {
$group = $group_content
->getGroup();
$plugin_id = $this
->getPluginId();
return GroupAccessResult::allowedIfHasGroupPermission($group, $account, "update {$plugin_id} content");
}
/**
* {@inheritdoc}
*/
protected function deleteAccess(GroupContentInterface $group_content, AccountInterface $account) {
$group = $group_content
->getGroup();
$plugin_id = $this
->getPluginId();
return GroupAccessResult::allowedIfHasGroupPermission($group, $account, "delete {$plugin_id} content");
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$config = parent::defaultConfiguration();
$config['entity_cardinality'] = 1;
$config['node_form_group_menu'] = 1;
$config['auto_create_group_menu'] = FALSE;
$config['auto_create_home_link'] = FALSE;
$config['auto_create_home_link_title'] = 'Home';
return $config;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$configuration = $this
->getConfiguration();
// 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>';
$form['auto_create_group_menu'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically create a menu when a group is created.'),
'#description' => $this
->t('The menu will be added to the new group as a group menu. The menu will be deleted when group is deleted.'),
'#default_value' => $configuration['auto_create_group_menu'],
];
$form['auto_create_home_link'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically create a "Home" link for the menu.'),
'#description' => $this
->t('The "Home" link will link to the canonical URL of the group.'),
'#default_value' => $configuration['auto_create_home_link'],
'#states' => [
'visible' => [
':input[name="auto_create_group_menu"]' => [
'checked' => TRUE,
],
],
],
];
$form['auto_create_home_link_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link title'),
'#default_value' => $configuration['auto_create_home_link_title'],
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="auto_create_home_link"]' => [
'checked' => TRUE,
],
],
],
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
GroupContentEnablerBase:: |
protected | property | The ID of group type this plugin was instantiated for. | |
GroupContentEnablerBase:: |
private | property | Backwards compatible permission array. | |
GroupContentEnablerBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
GroupContentEnablerBase:: |
public | function |
Checks access to an operation on a given group content entity. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Performs access check for the create operation. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Performs access check for the create target entity operation. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns whether this plugin defines entity access. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Retrieves the label for a piece of group content. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns a safe, unique configuration ID for a group content type. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the administrative description for a group content type. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the administrative label for a group content type. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the administrative description for the plugin. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the entity bundle the plugin supports. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the amount of times the same content can be added to a group. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the description for the entity reference field. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the label for the entity reference field. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns a list of entity reference field settings. Overrides GroupContentEnablerInterface:: |
1 |
GroupContentEnablerBase:: |
protected | function | Returns the entity type definition the plugin supports. | |
GroupContentEnablerBase:: |
public | function |
Returns the entity type ID the plugin supports. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the amount of groups the same content can be added to. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
protected | function | Provides permissions for the group content entity; i.e. the relationship. | |
GroupContentEnablerBase:: |
public | function |
Provides the cacheable metadata for this plugin's group operations. Overrides GroupContentEnablerInterface:: |
1 |
GroupContentEnablerBase:: |
public | function |
Returns the group type the plugin was instantiated for. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the ID of the group type the plugin was instantiated for. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the administrative label for the plugin. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Provides a list of operations for the content enabler plugin. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the pretty path key for use in path aliases. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns the plugin provider. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
protected | function | Provides permissions for the actual entity being added to the group. | |
GroupContentEnablerBase:: |
public | function |
Returns whether this plugin can only be (un)installed through code. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Returns whether this plugin is always on. Overrides GroupContentEnablerInterface:: |
|
GroupContentEnablerBase:: |
public | function |
Runs tasks after the group content type for this plugin has been created. Overrides GroupContentEnablerInterface:: |
1 |
GroupContentEnablerBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
GroupContentEnablerBase:: |
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:: |
|
GroupContentEnablerBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
GroupContentEnablerBase:: |
protected | function | Performs access check for the view operation. | |
GroupContentEnablerBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
GroupMenu:: |
public | function |
Form constructor. Overrides GroupContentEnablerBase:: |
|
GroupMenu:: |
public | function |
Gets default configuration for this plugin. Overrides GroupContentEnablerBase:: |
|
GroupMenu:: |
protected | function |
Performs access check for the delete operation. Overrides GroupContentEnablerBase:: |
|
GroupMenu:: |
public | function |
Provides a list of operations for a group. Overrides GroupContentEnablerBase:: |
|
GroupMenu:: |
public | function |
Provides a list of group permissions the plugin exposes. Overrides GroupContentEnablerBase:: |
|
GroupMenu:: |
protected | function |
Performs access check for the update operation. Overrides GroupContentEnablerBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |