class MembersPlugin in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Plugin/LearningPathMembers/MembersPlugin.php \Drupal\opigno_learning_path\Plugin\LearningPathMembers\MembersPlugin
Class MembersPlugin.
Plugin annotation
@LearningPathMembers(
id="members_plugin",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\opigno_learning_path\LearningPathMembersPluginBase implements LearningPathMembersPluginInterface
- class \Drupal\opigno_learning_path\Plugin\LearningPathMembers\MembersPlugin
- class \Drupal\opigno_learning_path\LearningPathMembersPluginBase implements LearningPathMembersPluginInterface
Expanded class hierarchy of MembersPlugin
File
- src/
Plugin/ LearningPathMembers/ MembersPlugin.php, line 16
Namespace
Drupal\opigno_learning_path\Plugin\LearningPathMembersView source
class MembersPlugin extends LearningPathMembersPluginBase {
/**
* {@inheritdoc}
*/
public function getMembersForm(array &$form, FormStateInterface $form_state, User $current_user) {
$storage = $form_state
->getStorage();
// If user can add any other users or only from his groups.
$show_all = $current_user
->hasPermission('add any members to calendar event') ? TRUE : FALSE;
$storage['show_all'] = $show_all;
// Add filters for the members field.
$form['members'] = [
'#type' => 'container',
'#weight' => 100,
];
$form['members']['title'] = [
'#type' => 'label',
'#title' => t('Members'),
];
// Get the users for the specific group.
$users = opigno_messaging_get_all_recipients($show_all);
$allowed_uids = [];
foreach ($users as $user) {
$allowed_uids[] = $user
->id();
}
if ($allowed_uids) {
$allowed_uids = array_unique($allowed_uids);
// Save to form storage.
$storage['allowed_uids'] = $allowed_uids;
// Filter allowed users.
if ($options = $form["field_calendar_event_members"]["widget"]["#options"]) {
foreach ($options as $key => $option) {
if (!in_array($key, $allowed_uids)) {
unset($form["field_calendar_event_members"]["widget"]["#options"][$key]);
}
}
}
}
$form['members']['field_calendar_event_members'] = $form['field_calendar_event_members'];
unset($form['field_calendar_event_members']);
$members =& $form['members']['field_calendar_event_members'];
$members["widget"]['#type'] = 'entity_selector';
$members['#prefix'] = '<div id="members">';
$members['#suffix'] = '</div>';
unset($members['widget']['#title']);
$form_state
->setStorage($storage);
if (!$current_user
->hasPermission('add members to calendar event')) {
// Hide calendar events members field.
if (!empty($form["field_calendar_event_members"])) {
$form["field_calendar_event_members"]["#access"] = FALSE;
}
if (!empty($form['members'])) {
$form['members']['#access'] = FALSE;
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LearningPathMembersPluginBase:: |
public | function | Returns group members uids. | |
LearningPathMembersPluginBase:: |
public | function |
Get plugin id. Overrides LearningPathMembersPluginInterface:: |
|
LearningPathMembersPluginBase:: |
public | function |
LearningPathMembersPluginBase constructor. Overrides PluginBase:: |
|
MembersPlugin:: |
public | function |
Get members form. Overrides LearningPathMembersPluginBase:: |
|
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:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |