Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/group
  • issue/group-3157478
  • issue/group-3084140
  • issue/group-3159277
  • issue/group-3163334
  • issue/group-3166252
  • issue/group-3167443
  • issue/group-3169377
  • issue/group-2797793
  • issue/group-2919982
  • issue/group-3177042
  • issue/group-3177542
  • issue/group-2801603
  • issue/group-3179857
  • issue/group-3052620
  • issue/group-2872645
  • issue/group-3007472
  • issue/group-3162259
  • issue/group-3183791
  • issue/group-3150877
  • issue/group-3185179
  • issue/group-3067811
  • issue/group-3189659
  • issue/group-3190190
  • issue/group-3190306
  • issue/group-2876696
  • issue/group-3118383
  • issue/group-3026735
  • issue/group-3194750
  • issue/group-3197122
  • issue/group-2746839
  • issue/group-3163683
  • issue/group-3201941
  • issue/group-3202091
  • issue/group-3202966
  • issue/group-3202249
  • issue/group-3045373
  • issue/group-3278740
  • issue/group-3209096
  • issue/group-3207064
  • issue/group-3214009
  • issue/group-3166107
  • issue/group-3214895
  • issue/group-2916907
  • issue/group-3220758
  • issue/group-3221785
  • issue/group-3222359
  • issue/group-3222747
  • issue/group-3223957
  • issue/group-2824018
  • issue/group-3226713
  • issue/group-3227793
  • issue/group-3228454
  • issue/group-3229567
  • issue/group-3232851
  • issue/group-3137312
  • issue/group-2295249
  • issue/group-3236626
  • issue/group-3281530
  • issue/group-3202908
  • issue/group-3278778
  • issue/group-3245095
  • issue/group-2972933
  • issue/group-3074933
  • issue/group-3162511
  • issue/group-3253368
  • issue/group-2767155
  • issue/group-2877493
  • issue/group-3254038
  • issue/group-3257227
  • issue/group-3257756
  • issue/group-2717981
  • issue/group-3259178
  • issue/group-3256998
  • issue/group-3204083
  • issue/group-3082125
  • issue/group-3265962
  • issue/group-3266146
  • issue/group-3262923
  • issue/group-3276613
  • issue/group-3005047
  • issue/group-3284402
  • issue/group-3071489
  • issue/group-3061881
  • issue/group-3305051
  • issue/group-2842630
  • issue/group-3301785
  • issue/group-3310499
  • issue/group-3311119
  • issue/group-3307282
  • issue/group-3307291
  • issue/group-2933819
  • issue/group-3310605
  • issue/group-2774729
  • issue/group-3311949
  • issue/group-3313220
  • issue/group-3317459
  • issue/group-3313515
  • issue/group-3315779
  • issue/group-2817109
  • issue/group-3319274
  • issue/group-3325789
  • issue/group-3320513
  • issue/group-3328660
  • issue/group-3210808
  • issue/group-3317396
  • issue/group-3325994
  • issue/group-3322623
  • issue/group-3331923
  • issue/group-3332963
  • issue/group-3112501
  • issue/group-3324506
  • issue/group-3344283
  • issue/group-3180860
  • issue/group-3104345
  • issue/group-3332640
  • issue/group-3354135
  • issue/group-3322761
  • issue/group-3367755
  • issue/group-3406043
  • issue/group-3398778
  • issue/group-3399601
  • issue/group-3406373
  • issue/group-3371637
  • issue/group-3371641
  • issue/group-3371651
  • issue/group-3374041
  • issue/group-3378653
  • issue/group-3364226
  • issue/group-3378977
  • issue/group-3399569
  • issue/group-3336186
  • issue/group-3382559
  • issue/group-3382831
  • issue/group-3016197
  • issue/group-2878723
  • issue/group-3390016
  • issue/group-3268711
  • issue/group-3394724
  • issue/group-3379174
  • issue/group-3397015
  • issue/group-3397021
  • issue/group-3397114
  • issue/group-3399085
  • issue/group-3406840
  • issue/group-3336280
  • issue/group-3409735
  • issue/group-3411381
  • issue/group-3413722
  • issue/group-3414592
  • issue/group-3415695
  • issue/group-3416324
  • issue/group-3421138
  • issue/group-3422253
  • issue/group-3422445
  • issue/group-3423341
  • issue/group-2895988
  • issue/group-3420605
  • issue/group-3424972
  • issue/group-3132084
  • issue/group-3101314
  • issue/group-3425601
  • issue/group-3426007
  • issue/group-3426098
  • issue/group-3426239
  • issue/group-3426408
  • issue/group-3427343
  • issue/group-3397063
  • issue/group-3427547
  • issue/group-3427552
  • issue/group-3428392
  • issue/group-3419405
  • issue/group-3441929
  • issue/group-2774827
  • issue/group-3414708
  • issue/group-2815971
  • issue/group-3441076
  • issue/group-3438400
  • issue/group-3440222
  • issue/group-3409374
  • issue/group-3430826
  • issue/group-3446192
  • issue/group-3137221
  • issue/group-3448221
  • issue/group-3449620
  • issue/group-3449640
  • issue/group-3346626
  • issue/group-3451560
  • issue/group-3437029
  • issue/group-3457095
  • issue/group-3462425
  • issue/group-2929788
  • issue/group-3352235
  • issue/group-3455789
  • issue/group-3467754
  • issue/group-3469835
  • issue/group-3470663
  • issue/group-3036272
  • issue/group-3469890
  • issue/group-3475807
  • issue/group-2907838
  • issue/group-3476539
  • issue/group-3478088
  • issue/group-3475816
  • issue/group-3399452
  • issue/group-3480110
  • issue/group-2754399
  • issue/group-3278936
  • issue/group-3482975
  • issue/group-3421756
  • issue/group-3485785
  • issue/group-3482418
  • issue/group-3490229
  • issue/group-3490670
  • issue/group-3489243
  • issue/group-3493593
  • issue/group-3493597
  • issue/group-3493741
  • issue/group-3493807
  • issue/group-3494447
  • issue/group-3494780
  • issue/group-3494986
  • issue/group-3497467
  • issue/group-3499639
  • issue/group-3494298
  • issue/group-3501018
  • issue/group-3502994
  • issue/group-3504133
  • issue/group-3504805
  • issue/group-3505771
  • issue/group-3506061
  • issue/group-3506097
  • issue/group-3506163
  • issue/group-3507425
  • issue/group-3508876
  • issue/group-3509416
  • issue/group-3509657
  • issue/group-3511625
  • issue/group-3512941
  • issue/group-3511454
  • issue/group-3484817
241 results
Show changes
Showing
with 627 additions and 120 deletions
...@@ -142,7 +142,7 @@ class GroupRelationshipTypeForm extends EntityForm { ...@@ -142,7 +142,7 @@ class GroupRelationshipTypeForm extends EntityForm {
// If we are on an 'add' form, we create the relationship type using the // If we are on an 'add' form, we create the relationship type using the
// plugin configuration submitted using this form. // plugin configuration submitted using this form.
if ($this->operation == 'add') { if ($this->operation == 'add') {
$storage = $this->entityTypeManager->getStorage('group_content_type'); $storage = $this->entityTypeManager->getStorage('group_relationship_type');
assert($storage instanceof GroupRelationshipTypeStorageInterface); assert($storage instanceof GroupRelationshipTypeStorageInterface);
$storage->createFromPlugin($group_type, $plugin->getRelationTypeId(), $config)->save(); $storage->createFromPlugin($group_type, $plugin->getRelationTypeId(), $config)->save();
$this->messenger()->addStatus($this->t('The content plugin was installed on the group type.')); $this->messenger()->addStatus($this->t('The content plugin was installed on the group type.'));
......
...@@ -38,7 +38,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase { ...@@ -38,7 +38,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase {
/** /**
* Constructs a new GroupRevisionDeleteForm. * Constructs a new GroupRevisionDeleteForm.
* *
* @param \Drupal\Core\Entity\ContentEntityStorageInterface * @param \Drupal\Core\Entity\ContentEntityStorageInterface $group_storage
* The group storage. * The group storage.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service. * The date formatter service.
...@@ -111,7 +111,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase { ...@@ -111,7 +111,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase {
$this->messenger()->addStatus( $this->messenger()->addStatus(
$this->t('Revision from %revision-date of @type %title has been deleted.', [ $this->t('Revision from %revision-date of @type %title has been deleted.', [
'%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()),
'@type' => $group_type, '@type' => $group_type->label(),
'%title' => $this->revision->label(), '%title' => $this->revision->label(),
]) ])
); );
...@@ -138,6 +138,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase { ...@@ -138,6 +138,7 @@ class GroupRevisionDeleteForm extends ConfirmFormBase {
->getQuery() ->getQuery()
->allRevisions() ->allRevisions()
->condition('id', $group->id()) ->condition('id', $group->id())
->accessCheck()
->count() ->count()
->execute(); ->execute();
} }
......
...@@ -13,6 +13,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -13,6 +13,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
class GroupRevisionRevertForm extends RevisionRevertForm { class GroupRevisionRevertForm extends RevisionRevertForm {
/**
* The entity revision.
*
* @var \Drupal\group\Entity\GroupInterface
*/
protected $revision;
/** /**
* The time service. * The time service.
* *
......
...@@ -22,7 +22,6 @@ class GroupRoleForm extends EntityForm { ...@@ -22,7 +22,6 @@ class GroupRoleForm extends EntityForm {
assert($this->entity instanceof GroupRoleInterface); assert($this->entity instanceof GroupRoleInterface);
$group_role = $this->entity; $group_role = $this->entity;
$group_role_id = '';
$form['label'] = [ $form['label'] = [
'#title' => $this->t('Name'), '#title' => $this->t('Name'),
...@@ -33,28 +32,28 @@ class GroupRoleForm extends EntityForm { ...@@ -33,28 +32,28 @@ class GroupRoleForm extends EntityForm {
'#size' => 30, '#size' => 30,
]; ];
// Since group role IDs are prefixed by the group type's ID followed by a // UI-generated group roles have the group type prefixed to their ID.
// period, we need to save some space for that. if ($this->operation === 'add') {
$subtract = strlen($group_role->getGroupTypeId()) + 1; // Since group role IDs are prefixed by the group type's ID followed by a
// period, we need to save some space for that.
// Since machine names with periods in it are technically not allowed, we $subtract = strlen($group_role->getGroupTypeId()) + 1;
// strip the group type ID prefix when editing a group role. $form['id'] = [
if ($group_role->id()) { '#type' => 'machine_name',
[, $group_role_id] = explode('-', $group_role->id(), 2); '#description' => $this->t('A unique machine-readable name for this group role. It must only contain lowercase letters, numbers, and underscores.'),
'#maxlength' => EntityTypeInterface::ID_MAX_LENGTH - $subtract,
'#field_prefix' => $group_role->getGroupTypeId() . '-',
'#machine_name' => [
'exists' => [$this, 'exists'],
'source' => ['label'],
],
];
}
else {
$form['id'] = [
'#type' => 'value',
'#value' => $group_role->id(),
];
} }
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $group_role_id,
'#maxlength' => EntityTypeInterface::ID_MAX_LENGTH - $subtract,
'#machine_name' => [
'exists' => [$this, 'exists'],
'source' => ['label'],
],
'#description' => $this->t('A unique machine-readable name for this group role. It must only contain lowercase letters, numbers, and underscores.'),
'#disabled' => !$group_role->isNew(),
'#field_prefix' => $group_role->getGroupTypeId() . '-',
];
$form['weight'] = [ $form['weight'] = [
'#type' => 'value', '#type' => 'value',
...@@ -146,10 +145,15 @@ class GroupRoleForm extends EntityForm { ...@@ -146,10 +145,15 @@ class GroupRoleForm extends EntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
assert($this->entity instanceof GroupRoleInterface); assert($this->entity instanceof GroupRoleInterface);
$group_role = $this->entity; $group_role = $this->entity;
$group_role->set('id', $group_role->getGroupTypeId() . '-' . $group_role->id());
$group_role->set('label', trim($group_role->label())); $group_role->set('label', trim($group_role->label()));
// UI-generated group roles have the group type prefixed to their ID.
if ($this->operation === 'add') {
$group_role->set('id', $group_role->getGroupTypeId() . '-' . $group_role->id());
}
// Make sure the global_role property is NULL rather than FALSE. // Make sure the global_role property is NULL rather than FALSE.
if ($group_role->getScope() === PermissionScopeInterface::INDIVIDUAL_ID) { if ($group_role->getScope() === PermissionScopeInterface::INDIVIDUAL_ID) {
$group_role->set('global_role', NULL); $group_role->set('global_role', NULL);
...@@ -169,12 +173,14 @@ class GroupRoleForm extends EntityForm { ...@@ -169,12 +173,14 @@ class GroupRoleForm extends EntityForm {
} }
$form_state->setRedirectUrl($group_role->toUrl('collection')); $form_state->setRedirectUrl($group_role->toUrl('collection'));
return $status;
} }
/** /**
* Checks whether a group role ID exists already. * Checks whether a group role ID exists already.
* *
* @param string $id * @param string $id
* The group role ID.
* *
* @return bool * @return bool
* Whether the ID is taken. * Whether the ID is taken.
...@@ -182,7 +188,7 @@ class GroupRoleForm extends EntityForm { ...@@ -182,7 +188,7 @@ class GroupRoleForm extends EntityForm {
public function exists($id) { public function exists($id) {
assert($this->entity instanceof GroupRoleInterface); assert($this->entity instanceof GroupRoleInterface);
$group_role = $this->entity; $group_role = $this->entity;
return (boolean) $this->entityTypeManager->getStorage('group_role')->load($group_role->getGroupTypeId() . '-' .$id); return (boolean) $this->entityTypeManager->getStorage('group_role')->load($group_role->getGroupTypeId() . '-' . $id);
} }
/** /**
......
...@@ -4,7 +4,6 @@ namespace Drupal\group\Entity\Form; ...@@ -4,7 +4,6 @@ namespace Drupal\group\Entity\Form;
use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Provides a form for group type deletion. * Provides a form for group type deletion.
...@@ -30,7 +29,7 @@ class GroupTypeDeleteForm extends EntityDeleteForm { ...@@ -30,7 +29,7 @@ class GroupTypeDeleteForm extends EntityDeleteForm {
$form['#title'] = $this->getQuestion(); $form['#title'] = $this->getQuestion();
$form['description'] = [ $form['description'] = [
'#markup' => '<p>' . $this->formatPlural($num_groups, $single, $multiple, $replace) . '</p>' '#markup' => '<p>' . $this->formatPlural($num_groups, $single, $multiple, $replace) . '</p>',
]; ];
return $form; return $form;
......
...@@ -89,7 +89,14 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -89,7 +89,14 @@ class GroupTypeForm extends BundleEntityFormBase {
'#description' => $this->t('This text will be displayed on the <em>Add group</em> page.'), '#description' => $this->t('This text will be displayed on the <em>Add group</em> page.'),
]; ];
$form['title_label'] = [ $form['group_settings'] = [
'#type' => 'details',
'#title' => $this->t('Group settings'),
'#description' => $this->t('The following settings apply to all groups of this type.'),
'#open' => FALSE,
];
$form['group_settings']['title_label'] = [
'#title' => $this->t('Title field label'), '#title' => $this->t('Title field label'),
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $fields['label']->getLabel(), '#default_value' => $fields['label']->getLabel(),
...@@ -97,20 +104,26 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -97,20 +104,26 @@ class GroupTypeForm extends BundleEntityFormBase {
'#required' => TRUE, '#required' => TRUE,
]; ];
$form['new_revision'] = [ $form['group_settings']['new_revision'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Create a new revision when a group is modified'), '#title' => $this->t('Create a new revision when a group is modified'),
'#default_value' => $type->shouldCreateNewRevision(), '#default_value' => $type->shouldCreateNewRevision(),
]; ];
$form['creator_membership'] = [ $form['creator_settings'] = [
'#type' => 'details',
'#title' => $this->t('Creator settings'),
'#open' => TRUE,
];
$form['creator_settings']['creator_membership'] = [
'#title' => $this->t('The group creator automatically becomes a member'), '#title' => $this->t('The group creator automatically becomes a member'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $type->creatorGetsMembership(), '#default_value' => $type->creatorGetsMembership(),
'#description' => $this->t('This will make sure that anyone who creates a group of this type will automatically become a member of it.'), '#description' => $this->t('This will make sure that anyone who creates a group of this type will automatically become a member of it.'),
]; ];
$form['creator_wizard'] = [ $form['creator_settings']['creator_wizard'] = [
'#title' => $this->t('Group creator must complete their membership'), '#title' => $this->t('Group creator must complete their membership'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $type->creatorMustCompleteMembership(), '#default_value' => $type->creatorMustCompleteMembership(),
...@@ -120,34 +133,88 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -120,34 +133,88 @@ class GroupTypeForm extends BundleEntityFormBase {
], ],
]; ];
$access_information = $this->t('
<p>Please note that Drupal accounts, <em><strong>including user 1</strong></em>, do not have access to any groups unless configured so.<br />It is therefore important that you at the very least do one of the following:</p>
<ul>
<li>Allow the group creator to get a role and set some permissions on it. You can edit this group type at any time to set more creator roles.</li>
<li>Allow certain global roles to get some permissions via Outsider or Insider group roles.</li>
<li>Optionally set an admin role, either for the group creator or for global roles (via Outsider or Insider group roles).</li>
</ul>
<p>If your use case does not require the group creator to be an admin of the group, then it is <strong>strongly advised</strong> to at least create an Outsider and/or Insider group role that synchronize with whatever administrator global role you have configured.</p>
');
$form['access_settings'] = [
'#type' => 'details',
'#title' => $this->t('Access settings'),
'#description' => $access_information,
'#open' => TRUE,
];
// Add-form specific elements. // Add-form specific elements.
if ($this->operation == 'add') { if ($this->operation == 'add') {
$form['add_default_roles'] = [ $form['access_settings']['add_default_roles'] = [
'#title' => $this->t('Automatically configure useful default roles'), '#title' => $this->t('Automatically configure useful default roles'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => 0, '#default_value' => 0,
'#description' => $this->t("This will create an 'Anonymous', 'Outsider' and 'Member' role by default which will synchronize to the 'Anonymous user' and 'Authenticated user' global roles."), '#description' => $this->t("This will create an 'Anonymous', 'Outsider' and 'Member' role by default which will synchronize to the 'Anonymous user' and 'Authenticated user' global roles."),
]; ];
$form['add_admin_role'] = [ $form['access_settings']['add_admin_role'] = [
'#title' => $this->t('Automatically configure an administrative role'), '#title' => $this->t('Automatically configure an administrative role'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => 0, '#default_value' => 0,
'#description' => $this->t("This will create an 'Admin' role by default which will have all permissions."), '#description' => $this->t("This will create an 'Admin' role by default which will have all permissions."),
]; ];
$form['assign_admin_role'] = [ $form['access_settings']['assign_admin_role'] = [
'#title' => $this->t('Automatically assign this administrative role to group creators'), '#title' => $this->t('Automatically assign this administrative role to group creators'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => 0, '#default_value' => 0,
'#description' => $this->t("This will assign the 'Admin' role to the group creator membership."), '#description' => $this->t("This will assign the 'Admin' role to the group creator membership."),
'#states' => [ '#states' => [
'visible' => [ 'visible' => [
':input[name="creator_membership"]' => ['checked' => TRUE], ':input[name="creator_membership"]' => ['unchecked' => FALSE],
':input[name="add_admin_role"]' => ['checked' => TRUE], ':input[name="add_admin_role"]' => ['unchecked' => FALSE],
], ],
], ],
]; ];
$admin_role = FALSE;
foreach ($this->entityTypeManager->getStorage('user_role')->loadMultiple() as $user_role) {
assert($user_role instanceof RoleInterface);
if ($user_role->isAdmin()) {
$admin_role = $user_role;
break;
}
}
if ($admin_role !== FALSE) {
$form['access_settings']['global_admins'] = [
'#type' => 'details',
'#title' => $this->t('Global administrator settings'),
'#description' => $this->t('<p>We have detected that your site has an all-access global role called @role.</p>', ['@role' => $admin_role->toLink(NULL, 'edit-form')->toString()]),
'#open' => TRUE,
];
$form['access_settings']['global_admins']['global_admin_role_id'] = [
'#type' => 'value',
'#value' => $admin_role->id(),
];
$form['access_settings']['global_admins']['add_admin_outsider'] = [
'#title' => $this->t('Automatically allow accounts with this role to manage all groups of this type they <strong>are not</strong> a member of'),
'#type' => 'checkbox',
'#default_value' => 1,
'#description' => $this->t("This will create an 'Administrator' role in the Outsider scope that syncs to the global role."),
];
$form['access_settings']['global_admins']['add_admin_insider'] = [
'#title' => $this->t('Automatically allow accounts with this role to manage all groups of this type they <strong>are</strong> a member of'),
'#type' => 'checkbox',
'#default_value' => 1,
'#description' => $this->t("This will create an 'Administrator' role in the Insider scope that syncs to the global role."),
];
}
} }
// Edit-form specific elements. // Edit-form specific elements.
else { else {
...@@ -156,7 +223,7 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -156,7 +223,7 @@ class GroupTypeForm extends BundleEntityFormBase {
$options[$group_role->id()] = $group_role->label(); $options[$group_role->id()] = $group_role->label();
} }
$form['creator_roles'] = [ $form['access_settings']['creator_roles'] = [
'#title' => $this->t('Group creator roles'), '#title' => $this->t('Group creator roles'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => $options, '#options' => $options,
...@@ -171,7 +238,7 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -171,7 +238,7 @@ class GroupTypeForm extends BundleEntityFormBase {
$add_role_url = Url::fromRoute('entity.group_role.add_form', ['group_type' => $type->id()]); $add_role_url = Url::fromRoute('entity.group_role.add_form', ['group_type' => $type->id()]);
$t_args = ['@url' => $add_role_url->toString()]; $t_args = ['@url' => $add_role_url->toString()];
$description = $this->t('You do not have any custom group roles yet, <a href="@url">create one here</a>.', $t_args); $description = $this->t('You do not have any custom group roles yet, <a href="@url">create one here</a>.', $t_args);
$form['creator_roles']['#description'] .= "<br /><em>$description</em>"; $form['access_settings']['creator_roles']['#description'] .= "<br /><em>$description</em>";
} }
} }
...@@ -239,7 +306,10 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -239,7 +306,10 @@ class GroupTypeForm extends BundleEntityFormBase {
// Optionally create the default and/or admin roles. // Optionally create the default and/or admin roles.
$add_default_roles = $form_state->getValue('add_default_roles'); $add_default_roles = $form_state->getValue('add_default_roles');
$add_admin_role = $form_state->getValue('add_admin_role'); $add_admin_role = $form_state->getValue('add_admin_role');
if ($add_default_roles || $add_admin_role) { $add_admin_outsider = $form_state->getValue('add_admin_outsider');
$add_admin_insider = $form_state->getValue('add_admin_insider');
if ($add_default_roles || $add_admin_role || $add_admin_outsider || $add_admin_insider) {
$storage = $this->entityTypeManager->getStorage('group_role'); $storage = $this->entityTypeManager->getStorage('group_role');
assert($storage instanceof GroupRoleStorageInterface); assert($storage instanceof GroupRoleStorageInterface);
...@@ -276,7 +346,7 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -276,7 +346,7 @@ class GroupTypeForm extends BundleEntityFormBase {
$storage->save($storage->create([ $storage->save($storage->create([
'id' => "$group_type_id-admin", 'id' => "$group_type_id-admin",
'label' => $this->t('Admin'), 'label' => $this->t('Admin'),
'weight' => -99, 'weight' => 100,
'scope' => PermissionScopeInterface::INDIVIDUAL_ID, 'scope' => PermissionScopeInterface::INDIVIDUAL_ID,
'group_type' => $group_type_id, 'group_type' => $group_type_id,
'admin' => TRUE, 'admin' => TRUE,
...@@ -287,10 +357,36 @@ class GroupTypeForm extends BundleEntityFormBase { ...@@ -287,10 +357,36 @@ class GroupTypeForm extends BundleEntityFormBase {
$group_type->set('creator_roles', [$group_type_id . '-admin'])->save(); $group_type->set('creator_roles', [$group_type_id . '-admin'])->save();
} }
} }
if ($add_admin_outsider || $add_admin_insider) {
$base = [
'label' => $this->t('Administrator'),
'global_role' => $form_state->getValue('global_admin_role_id'),
'group_type' => $group_type_id,
'admin' => TRUE,
];
if ($add_admin_outsider) {
$storage->save($storage->create([
'id' => "$group_type_id-admin_out",
'weight' => 101,
'scope' => PermissionScopeInterface::OUTSIDER_ID,
] + $base));
}
if ($add_admin_insider) {
$storage->save($storage->create([
'id' => "$group_type_id-admin_in",
'weight' => 102,
'scope' => PermissionScopeInterface::INSIDER_ID,
] + $base));
}
}
} }
} }
$form_state->setRedirectUrl($group_type->toUrl('collection')); $form_state->setRedirectUrl($group_type->toUrl('collection'));
return $status;
} }
} }
This diff is collapsed.
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
namespace Drupal\group\Entity; namespace Drupal\group\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\RevisionLogInterface; use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\user\UserInterface; use Drupal\user\UserInterface;
/** /**
...@@ -30,6 +30,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E ...@@ -30,6 +30,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E
* Returns the group type entity the group uses. * Returns the group type entity the group uses.
* *
* @return \Drupal\group\Entity\GroupTypeInterface * @return \Drupal\group\Entity\GroupTypeInterface
* The group type entity.
*/ */
public function getGroupType(); public function getGroupType();
...@@ -121,7 +122,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E ...@@ -121,7 +122,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E
* The user to load the membership for. * The user to load the membership for.
* *
* @return \Drupal\group\GroupMembership|false * @return \Drupal\group\GroupMembership|false
* The loaded GroupMembership or FALSE if none was found. * The loaded group membership or FALSE if none was found.
*/ */
public function getMember(AccountInterface $account); public function getMember(AccountInterface $account);
...@@ -133,7 +134,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E ...@@ -133,7 +134,7 @@ interface GroupInterface extends ContentEntityInterface, EntityOwnerInterface, E
* names to filter on. Results only need to match on one role (IN query). * names to filter on. Results only need to match on one role (IN query).
* *
* @return \Drupal\group\GroupMembership[] * @return \Drupal\group\GroupMembership[]
* A list of GroupMembership objects representing the memberships. * A list of group memberships.
*/ */
public function getMembers($roles = NULL); public function getMembers($roles = NULL);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.