From 1bfdfe9b94fe678821e7637ef4be1a377e6b77e8 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Thu, 2 Mar 2017 16:05:41 +0000 Subject: [PATCH 01/31] Initial port --- og_access/og_access.info.yml | 9 ++ og_access/og_access.install | 24 +++ og_access/og_access.module | 149 ++++++++++++++++++ .../src/Plugin/OgFields/OgAccessField.php | 80 ++++++++++ .../Plugin/OgFields/OgContentAccessField.php | 80 ++++++++++ 5 files changed, 342 insertions(+) create mode 100644 og_access/og_access.info.yml create mode 100644 og_access/og_access.install create mode 100644 og_access/og_access.module create mode 100644 og_access/src/Plugin/OgFields/OgAccessField.php create mode 100644 og_access/src/Plugin/OgFields/OgContentAccessField.php diff --git a/og_access/og_access.info.yml b/og_access/og_access.info.yml new file mode 100644 index 000000000..054d6130f --- /dev/null +++ b/og_access/og_access.info.yml @@ -0,0 +1,9 @@ +name: Organic Groups access control +description: Enable access control for private and public groups and group content." +package: Organic Groups + +core: 8.x +type: module + +dependencies: + - og diff --git a/og_access/og_access.install b/og_access/og_access.install new file mode 100644 index 000000000..2d4628790 --- /dev/null +++ b/og_access/og_access.install @@ -0,0 +1,24 @@ +getAllGroupBundles('node'); + + foreach ($groups as $group) { + Og::createField(OG_ACCESS_FIELD, 'node', $group); + } + + $group_content_bundles = $group_type_manager->getAllGroupContentBundlesByEntityType('node'); + foreach ($group_content_bundles as $bundle) { + Og::createField(OG_CONTENT_ACCESS_FIELD, 'node', $bundle); + } +} diff --git a/og_access/og_access.module b/og_access/og_access.module new file mode 100644 index 000000000..c0680b58d --- /dev/null +++ b/og_access/og_access.module @@ -0,0 +1,149 @@ +getUserGroups($account)) { + foreach ($groups as $group_type => $entity_groups) { + /** @var \Drupal\core\Entity\EntityInterface $group */ + foreach ($entity_groups as $group) { + $realm = OG_ACCESS_REALM . ':' . $group_type; + $grants[$realm][] = $group->id(); + } + } + } + + return !empty($grants) ? $grants : []; +} + +/** + * Implements hook_node_access_records(). + */ +function og_access_node_access_records(NodeInterface $node) { + if (empty($node->status)) { + // Node is unpublished, so we don't allow every group member to see it. + return []; + } + + // The group IDs, that in case access is granted, will be recorded. + $gids = []; + + if (Og::isGroup('node', $node->getType()) && + $node->hasField(OG_ACCESS_FIELD) && + !empty($node->{OG_ACCESS_FIELD}) && $node->{OG_ACCESS_FIELD}->value) { + // Private group. + $gids['node'][] = $node->id(); + } + + if (!empty($node->get(OG_CONTENT_ACCESS_FIELD))) { + $content_access = $node->get(OG_CONTENT_ACCESS_FIELD)->value; + } + else { + $content_access = OG_ACCESS_PUBLIC; + } + + switch ($content_access) { + case OG_ACCESS_PUBLIC: + // Skip non-group content nodes. + if (!Og::isGroupContent('node', $node->getType())) { + break; + } + + $has_private = FALSE; + /** @var \Drupal\og\OgGroupAudienceHelper $audience_helper */ + $audience_helper = \Drupal::service('og.group_audience_helper'); + foreach ($audience_helper->getAllGroupAudienceFields('node', $node->getType()) as $field_name => $field) { + foreach ($node->get($field_name)->referencedEntities() as $group) { + $list_gids[$group->getType][] = $group->id(); + + if ($has_private) { + // We already know we have a private group, so we can avoid + // re-checking it. + continue; + } + + if (!empty($group->get(OG_ACCESS_FIELD)) && + $group->get(OG_ACCESS_FIELD)->value) { + $has_private = TRUE; + } + } + } + if ($has_private) { + $gids = array_merge_recursive($gids, $list_gids); + } + break; + + case OG_ACCESS_PRIVATE: + $list_gids = []; + /** @var \Drupal\og\OgGroupAudienceHelper $audience_helper */ + $audience_helper = \Drupal::service('og.group_audience_helper'); + foreach ($audience_helper->getAllGroupAudienceFields('node', $node->getType()) as $field_name => $field) { + foreach ($node->get($field_name)->referencedEntities() as $group) { + $list_gids[$group->getType][] = $group->id(); + } + } + + $gids = array_merge_recursive($gids, $list_gids); + break; + } + + foreach ($gids as $group_type => $values) { + foreach ($values as $gid) { + $grants[] = [ + 'realm' => OG_ACCESS_REALM . ':' . $group_type, + 'gid' => $gid, + 'grant_view' => 1, + 'grant_update' => 0, + 'grant_delete' => 0, + ]; + } + } + + + return !empty($grants) ? $grants : []; +} diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php new file mode 100644 index 000000000..a11012cc0 --- /dev/null +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -0,0 +1,80 @@ + 1, + 'settings' => [ + 'allowed_values' => [ + 0 => 'Public - accessible to all site users', + 1 => 'Private - accessible only to group members', + ], + 'allowed_values_function' => '', + ], + 'type' => 'list_integer', + 'locked' => TRUE, + ]; + + return parent::getFieldStorageBaseDefinition($values); + } + + /** + * {@inheritdoc} + */ + public function getFieldBaseDefinition(array $values = []) { + $values += [ + 'default_value' => [0 => ['value' => 0]], + 'description' => $this->t('Determine access to the group.'), + 'display_label' => TRUE, + 'label' => $this->t('Group visibility'), + 'required' => TRUE, + ]; + + return parent::getFieldBaseDefinition($values); + } + + /** + * {@inheritdoc} + */ + public function getFormDisplayDefinition(array $values = []) { + $values += [ + 'type' => 'options_buttons', + 'settings' => [], + 'default_value' => 0, + ]; + + return $values; + } + + /** + * {@inheritdoc} + */ + public function getViewDisplayDefinition(array $values = []) { + $values += [ + 'type' => 'list_default', + 'label' => 'above', + ]; + + return $values; + } + +} diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php new file mode 100644 index 000000000..124bf02a8 --- /dev/null +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -0,0 +1,80 @@ + 1, + 'settings' => [ + 'allowed_values' => [ + 0 => 'Public - accessible to all site users', + 1 => 'Private - accessible only to group members', + ], + 'allowed_values_function' => '', + ], + 'type' => 'list_integer', + 'locked' => TRUE, + ]; + + return parent::getFieldStorageBaseDefinition($values); + } + + /** + * {@inheritdoc} + */ + public function getFieldBaseDefinition(array $values = []) { + $values += [ + 'default_value' => [0 => ['value' => 0]], + 'description' => $this->t('Determine access to the group.'), + 'display_label' => TRUE, + 'label' => $this->t('Group visibility'), + 'required' => TRUE, + ]; + + return parent::getFieldBaseDefinition($values); + } + + /** + * {@inheritdoc} + */ + public function getFormDisplayDefinition(array $values = []) { + $values += [ + 'type' => 'options_buttons', + 'settings' => [], + 'default_value' => 0, + ]; + + return $values; + } + + /** + * {@inheritdoc} + */ + public function getViewDisplayDefinition(array $values = []) { + $values += [ + 'type' => 'list_default', + 'label' => 'above', + ]; + + return $values; + } + +} From 18ab4110e128f69cb0f0bc606f0651a4c83c083a Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Thu, 2 Mar 2017 17:25:10 +0000 Subject: [PATCH 02/31] Cleanup --- og_access/og_access.install | 4 +++- og_access/og_access.module | 8 ++++++-- og_access/src/Plugin/OgFields/OgAccessField.php | 1 - og_access/src/Plugin/OgFields/OgContentAccessField.php | 9 ++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/og_access/og_access.install b/og_access/og_access.install index 2d4628790..180b4ac3e 100644 --- a/og_access/og_access.install +++ b/og_access/og_access.install @@ -7,10 +7,12 @@ use Drupal\og\Og; * Install/update/uninstall hook implementations. */ +/** + * Implements hook_install(). + */ function og_access_install() { /** @var \Drupal\og\GroupTypeManager $group_type_manager */ $group_type_manager = \Drupal::service('og.group_type_manager'); - $groups = $group_type_manager->getAllGroupBundles('node'); foreach ($groups as $group) { diff --git a/og_access/og_access.module b/og_access/og_access.module index c0680b58d..1c8fca3d4 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -9,7 +9,10 @@ * @TODO move grants/access to service */ +use Drupal\Core\Config\Entity\ConfigEntityBundleBase; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\field\Entity\FieldConfig; use Drupal\node\NodeInterface; use Drupal\og\Og; @@ -80,7 +83,8 @@ function og_access_node_access_records(NodeInterface $node) { $gids['node'][] = $node->id(); } - if (!empty($node->get(OG_CONTENT_ACCESS_FIELD))) { + if ($node->hasField(OG_CONTENT_ACCESS_FIELD) && + !empty($node->get(OG_CONTENT_ACCESS_FIELD))) { $content_access = $node->get(OG_CONTENT_ACCESS_FIELD)->value; } else { @@ -107,7 +111,7 @@ function og_access_node_access_records(NodeInterface $node) { continue; } - if (!empty($group->get(OG_ACCESS_FIELD)) && + if ($group->hasField(OG_ACCESS_FIELD) && !empty($group->get(OG_ACCESS_FIELD)) && $group->get(OG_ACCESS_FIELD)->value) { $has_private = TRUE; } diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index a11012cc0..90d6031b4 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -31,7 +31,6 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'allowed_values_function' => '', ], 'type' => 'list_integer', - 'locked' => TRUE, ]; return parent::getFieldStorageBaseDefinition($values); diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index 124bf02a8..206e339d6 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -7,12 +7,12 @@ use Drupal\og\OgFieldsInterface; /** - * Determine if group should use default roles and permissions. + * Determine the group content visibility. * * @OgFields( * id = OG_CONTENT_ACCESS_FIELD, * type = "node", - * description = @Translation("Determine access to the group.") + * description = @Translation("Determine the group content visibility.") * ) */ class OgContentAccessField extends OgFieldBase implements OgFieldsInterface { @@ -31,7 +31,6 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'allowed_values_function' => '', ], 'type' => 'list_integer', - 'locked' => TRUE, ]; return parent::getFieldStorageBaseDefinition($values); @@ -43,9 +42,9 @@ public function getFieldStorageBaseDefinition(array $values = []) { public function getFieldBaseDefinition(array $values = []) { $values += [ 'default_value' => [0 => ['value' => 0]], - 'description' => $this->t('Determine access to the group.'), + 'description' => $this->t('Determine the group content visibility.'), 'display_label' => TRUE, - 'label' => $this->t('Group visibility'), + 'label' => $this->t('Group content visibility'), 'required' => TRUE, ]; From 72451e1bd6cb7ea4aba46a199d725b0b5b3297f3 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Thu, 2 Mar 2017 17:26:12 +0000 Subject: [PATCH 03/31] Add remove access fields on entity group/group content config changes --- og_access/og_access.module | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/og_access/og_access.module b/og_access/og_access.module index 1c8fca3d4..0aa1637e1 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -151,3 +151,58 @@ function og_access_node_access_records(NodeInterface $node) { return !empty($grants) ? $grants : []; } + +/** + * Implements hook_entity_insert(). + */ +function og_access_entity_insert(EntityInterface $entity) { + og_access_entity_type_save($entity); +} + +/** + * Implements hook_entity_update(). + */ +function og_access_entity_update(EntityInterface $entity) { + og_access_entity_type_save($entity); +} + +/** + * Adds/removes the group and group content access fields. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity object. + */ +function og_access_entity_type_save(EntityInterface $entity) { + if (!$entity instanceof ConfigEntityBundleBase || !isset($entity->og_is_group)) { + return; + } + + $bundle = $entity->id(); + $definition = \Drupal::entityTypeManager()->getDefinition($entity->getEntityTypeId()); + $entity_type_id = $definition->getBundleOf(); + + // Add/remove the group itself. + $is_group = Og::isGroup($entity_type_id, $bundle); + if ($entity->og_is_group != $is_group) { + if ($entity->og_is_group) { + Og::createField(OG_ACCESS_FIELD, $entity_type_id, $bundle); + } + elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_FIELD)) { + $field->delete(); + return; + } + } + + // Add remove the relevant field. + $is_group_content = Og::isGroupContent($entity_type_id, $bundle); + if ($entity->og_group_content_bundle != $is_group_content) { + if ($entity->og_group_content_bundle) { + Og::createField(OG_CONTENT_ACCESS_FIELD, $entity_type_id, $bundle); + } + elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_CONTENT_ACCESS_FIELD)) { + $field->delete(); + return; + } + } + +} From f08fe78689235880b4ede579b4b971ebdeb4a7e4 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Mon, 13 Mar 2017 11:07:03 +0000 Subject: [PATCH 04/31] Remove install step This should follow the group/group content method of enabling --- og_access/og_access.install | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 og_access/og_access.install diff --git a/og_access/og_access.install b/og_access/og_access.install deleted file mode 100644 index 180b4ac3e..000000000 --- a/og_access/og_access.install +++ /dev/null @@ -1,26 +0,0 @@ -getAllGroupBundles('node'); - - foreach ($groups as $group) { - Og::createField(OG_ACCESS_FIELD, 'node', $group); - } - - $group_content_bundles = $group_type_manager->getAllGroupContentBundlesByEntityType('node'); - foreach ($group_content_bundles as $bundle) { - Og::createField(OG_CONTENT_ACCESS_FIELD, 'node', $bundle); - } -} From 3a770013769cd8812584a2d7fcef64e7d1fefcbf Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Mon, 13 Mar 2017 11:07:30 +0000 Subject: [PATCH 05/31] Use core method for checking if node is published --- og_access/og_access.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 0aa1637e1..b1641c9de 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -68,7 +68,7 @@ function og_access_node_grants(AccountInterface $account, $op) { * Implements hook_node_access_records(). */ function og_access_node_access_records(NodeInterface $node) { - if (empty($node->status)) { + if (!$node->isPublished()) { // Node is unpublished, so we don't allow every group member to see it. return []; } @@ -181,7 +181,7 @@ function og_access_entity_type_save(EntityInterface $entity) { $definition = \Drupal::entityTypeManager()->getDefinition($entity->getEntityTypeId()); $entity_type_id = $definition->getBundleOf(); - // Add/remove the group itself. + // Add/remove on the group itself. $is_group = Og::isGroup($entity_type_id, $bundle); if ($entity->og_is_group != $is_group) { if ($entity->og_is_group) { From 5e1436c5b30091bea4fe28668d034c817ba03d0a Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Mon, 13 Mar 2017 16:01:28 +0000 Subject: [PATCH 06/31] Add access field toggle in the bundle form --- og_access/og_access.info.yml | 3 +- og_access/og_access.module | 54 +++++++++++++---- og_access/src/BundleFormAlter.php | 96 +++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 og_access/src/BundleFormAlter.php diff --git a/og_access/og_access.info.yml b/og_access/og_access.info.yml index 054d6130f..0a1474b89 100644 --- a/og_access/og_access.info.yml +++ b/og_access/og_access.info.yml @@ -1,5 +1,5 @@ name: Organic Groups access control -description: Enable access control for private and public groups and group content." +description: "Enable access control for private and public groups and group content." package: Organic Groups core: 8.x @@ -7,3 +7,4 @@ type: module dependencies: - og + - og_ui diff --git a/og_access/og_access.module b/og_access/og_access.module index b1641c9de..66b7f4566 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -10,11 +10,14 @@ */ use Drupal\Core\Config\Entity\ConfigEntityBundleBase; +use Drupal\Core\Entity\BundleEntityFormBase; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\field\Entity\FieldConfig; use Drupal\node\NodeInterface; use Drupal\og\Og; +use Drupal\og_access\BundleFormAlter; /** * The access realm of group member. @@ -152,6 +155,16 @@ function og_access_node_access_records(NodeInterface $node) { return !empty($grants) ? $grants : []; } +/** + * Implements hook_form_alter(). + */ +function og_access_form_alter(array &$form, FormStateInterface $form_state, $form_id) { + if ($form_state->getFormObject() instanceof BundleEntityFormBase) { + (new BundleFormAlter($form_state->getFormObject()->getEntity())) + ->formAlter($form, $form_state); + } +} + /** * Implements hook_entity_insert(). */ @@ -181,28 +194,47 @@ function og_access_entity_type_save(EntityInterface $entity) { $definition = \Drupal::entityTypeManager()->getDefinition($entity->getEntityTypeId()); $entity_type_id = $definition->getBundleOf(); + $enable_og_access = $entity->og_enable_access; + // Add/remove on the group itself. $is_group = Og::isGroup($entity_type_id, $bundle); - if ($entity->og_is_group != $is_group) { - if ($entity->og_is_group) { + if ($entity->og_is_group || $is_group) { + $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_FIELD); + if (!$field && $enable_og_access) { Og::createField(OG_ACCESS_FIELD, $entity_type_id, $bundle); } - elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_FIELD)) { - $field->delete(); - return; + elseif ($field) { + if (!$enable_og_access || $is_group && !$entity->og_is_group) { + $field->delete(); + } } } - // Add remove the relevant field. + // Add remove the relevant field to the group content bundle. $is_group_content = Og::isGroupContent($entity_type_id, $bundle); - if ($entity->og_group_content_bundle != $is_group_content) { - if ($entity->og_group_content_bundle) { + if ($entity->og_group_content_bundle || $is_group_content) { + $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_CONTENT_ACCESS_FIELD); + + if (!$field && $enable_og_access) { Og::createField(OG_CONTENT_ACCESS_FIELD, $entity_type_id, $bundle); } - elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_CONTENT_ACCESS_FIELD)) { - $field->delete(); - return; + elseif ($field) { + if (!$enable_og_access || $is_group_content && !$entity->og_group_content_bundle) { + $field->delete(); + } } } +} +/** + * Implements hook_module_implements_alter(). + */ +function og_access_module_implements_alter(&$implementations, $hook) { + if ($hook == 'form_alter') { + // Move our form alter after the og_ui one. + // @TODO remove once og_ui and og are merged. + $group = $implementations['og_access']; + unset($implementations['og_access']); + $implementations['og_access'] = $group; + } } diff --git a/og_access/src/BundleFormAlter.php b/og_access/src/BundleFormAlter.php new file mode 100644 index 000000000..97de0b928 --- /dev/null +++ b/og_access/src/BundleFormAlter.php @@ -0,0 +1,96 @@ +entity = $entity; + } + + /** + * This is a helper for og_ui_form_alter(). + * + * @param array $form + * The form variable. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. + */ + public function formAlter(array &$form, FormStateInterface $form_state) { + // Example: node. + $this->entityTypeId = $this->entity->getEntityType()->getBundleOf(); + + // Example: article. + $this->bundle = $this->entity->id(); + + $form['og']['og_enable_access'] = [ + '#type' => 'checkbox', + '#title' => t('Enable OG access control'), + '#default_value' => $this->hasAccessControl(), + '#states' => [ + 'visible' => [ + [':input[name="og_is_group"]' => ['checked' => TRUE]], + [':input[name="og_group_content_bundle"]' => ['checked' => TRUE]], + ] + ], + ]; + } + + /** + * Checks whether the existing bundle has OG access control enabled. + * + * @return bool + * True if the group bundle has the OG_ACCESS_FIELD field -OR- + * if the group content bundle has the OG_CONTENT_ACCESS_FIELD field. + * False otherwise. + */ + protected function hasAccessControl() { + $field_definitions = \Drupal::service('entity_field.manager') + ->getFieldDefinitions($this->entityTypeId, $this->bundle); + + if (Og::isGroup($this->entityTypeId, $this->bundle)) { + return isset($field_definitions[OG_ACCESS_FIELD]); + } + + if (Og::isGroupContent($this->entityTypeId, $this->bundle)) { + return isset($field_definitions[OG_CONTENT_ACCESS_FIELD]); + } + + return FALSE; + } + +} From 5a801abca32665d9b96d560bfbefba1816152a2c Mon Sep 17 00:00:00 2001 From: Sven Decabooter Date: Mon, 15 May 2017 15:44:46 +0200 Subject: [PATCH 07/31] Fix og_access realm (#1) * Fix og_access realm * Use entity type instead of bundle type in realm records --- og_access/og_access.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 66b7f4566..a838908d7 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -106,7 +106,7 @@ function og_access_node_access_records(NodeInterface $node) { $audience_helper = \Drupal::service('og.group_audience_helper'); foreach ($audience_helper->getAllGroupAudienceFields('node', $node->getType()) as $field_name => $field) { foreach ($node->get($field_name)->referencedEntities() as $group) { - $list_gids[$group->getType][] = $group->id(); + $list_gids[$group->getEntityTypeId()][] = $group->id(); if ($has_private) { // We already know we have a private group, so we can avoid @@ -131,7 +131,7 @@ function og_access_node_access_records(NodeInterface $node) { $audience_helper = \Drupal::service('og.group_audience_helper'); foreach ($audience_helper->getAllGroupAudienceFields('node', $node->getType()) as $field_name => $field) { foreach ($node->get($field_name)->referencedEntities() as $group) { - $list_gids[$group->getType][] = $group->id(); + $list_gids[$group->getEntityTypeId()][] = $group->id(); } } From 690235a46e21c625f8752be773210527f0edc75a Mon Sep 17 00:00:00 2001 From: Joachim Noreiko Date: Thu, 21 Sep 2017 11:45:25 +0100 Subject: [PATCH 08/31] Fix crash on add forms for bundles of content entities that implement bundleFieldDefinitions(). --- og_access/src/BundleFormAlter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/src/BundleFormAlter.php b/og_access/src/BundleFormAlter.php index 97de0b928..583c963b1 100644 --- a/og_access/src/BundleFormAlter.php +++ b/og_access/src/BundleFormAlter.php @@ -60,7 +60,7 @@ public function formAlter(array &$form, FormStateInterface $form_state) { $form['og']['og_enable_access'] = [ '#type' => 'checkbox', '#title' => t('Enable OG access control'), - '#default_value' => $this->hasAccessControl(), + '#default_value' => $this->bundle ? FALSE : $this->hasAccessControl(), '#states' => [ 'visible' => [ [':input[name="og_is_group"]' => ['checked' => TRUE]], From d3c36c374d806cb49b1641dae1c5b732562fd1b9 Mon Sep 17 00:00:00 2001 From: Joachim Noreiko Date: Thu, 21 Sep 2017 12:50:33 +0100 Subject: [PATCH 09/31] Fixup! Fix crash on add forms for bundles of content entities that implement bundleFieldDefinitions(). --- og_access/src/BundleFormAlter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/src/BundleFormAlter.php b/og_access/src/BundleFormAlter.php index 583c963b1..f1f6e855a 100644 --- a/og_access/src/BundleFormAlter.php +++ b/og_access/src/BundleFormAlter.php @@ -60,7 +60,7 @@ public function formAlter(array &$form, FormStateInterface $form_state) { $form['og']['og_enable_access'] = [ '#type' => 'checkbox', '#title' => t('Enable OG access control'), - '#default_value' => $this->bundle ? FALSE : $this->hasAccessControl(), + '#default_value' => $this->bundle ? $this->hasAccessControl() : FALSE, '#states' => [ 'visible' => [ [':input[name="og_is_group"]' => ['checked' => TRUE]], From f1dc41b798ca52b23d917ad53b625df14e744f50 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 22 Sep 2017 17:48:32 +0100 Subject: [PATCH 10/31] Lint --- og_access/og_access.module | 17 ++++++++--------- og_access/src/BundleFormAlter.php | 9 +++++---- og_access/src/Plugin/OgFields/OgAccessField.php | 3 +-- .../Plugin/OgFields/OgContentAccessField.php | 5 ++--- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index a838908d7..ee3063f66 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -17,7 +17,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\field\Entity\FieldConfig; use Drupal\node\NodeInterface; use Drupal\og\Og; -use Drupal\og_access\BundleFormAlter; +use Drupal\og_access\OgAccessBundleFormAlter; /** * The access realm of group member. @@ -32,7 +32,7 @@ define('OG_ACCESS_FIELD', 'group_access'); /** * Group public access field. */ -define('OG_CONTENT_ACCESS_FIELD', 'group_content_access'); +define('OG_ACCESS_CONTENT_FIELD', 'group_content_access'); /** * Public group/group content access. @@ -86,9 +86,9 @@ function og_access_node_access_records(NodeInterface $node) { $gids['node'][] = $node->id(); } - if ($node->hasField(OG_CONTENT_ACCESS_FIELD) && - !empty($node->get(OG_CONTENT_ACCESS_FIELD))) { - $content_access = $node->get(OG_CONTENT_ACCESS_FIELD)->value; + if ($node->hasField(OG_ACCESS_CONTENT_FIELD) && + !empty($node->get(OG_ACCESS_CONTENT_FIELD))) { + $content_access = $node->get(OG_ACCESS_CONTENT_FIELD)->value; } else { $content_access = OG_ACCESS_PUBLIC; @@ -151,7 +151,6 @@ function og_access_node_access_records(NodeInterface $node) { } } - return !empty($grants) ? $grants : []; } @@ -160,7 +159,7 @@ function og_access_node_access_records(NodeInterface $node) { */ function og_access_form_alter(array &$form, FormStateInterface $form_state, $form_id) { if ($form_state->getFormObject() instanceof BundleEntityFormBase) { - (new BundleFormAlter($form_state->getFormObject()->getEntity())) + (new OgAccessBundleFormAlter($form_state->getFormObject()->getEntity())) ->formAlter($form, $form_state); } } @@ -213,10 +212,10 @@ function og_access_entity_type_save(EntityInterface $entity) { // Add remove the relevant field to the group content bundle. $is_group_content = Og::isGroupContent($entity_type_id, $bundle); if ($entity->og_group_content_bundle || $is_group_content) { - $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_CONTENT_ACCESS_FIELD); + $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_CONTENT_FIELD); if (!$field && $enable_og_access) { - Og::createField(OG_CONTENT_ACCESS_FIELD, $entity_type_id, $bundle); + Og::createField(OG_ACCESS_CONTENT_FIELD, $entity_type_id, $bundle); } elseif ($field) { if (!$enable_og_access || $is_group_content && !$entity->og_group_content_bundle) { diff --git a/og_access/src/BundleFormAlter.php b/og_access/src/BundleFormAlter.php index f1f6e855a..ee80ea871 100644 --- a/og_access/src/BundleFormAlter.php +++ b/og_access/src/BundleFormAlter.php @@ -9,7 +9,7 @@ /** * Helper for og_access_form_alter(). */ -class BundleFormAlter { +class OgAccessBundleFormAlter { /** * The entity bundle. @@ -59,13 +59,14 @@ public function formAlter(array &$form, FormStateInterface $form_state) { $form['og']['og_enable_access'] = [ '#type' => 'checkbox', - '#title' => t('Enable OG access control'), + '#title' => t('Restrict access to group members'), + '#description' => t('Enable OG access control. Provides a new field that determines the group/group content visibility. Public groups can have member-only content. Any public group content belonging to a private group will be restricted to the members of that group only.'), '#default_value' => $this->bundle ? $this->hasAccessControl() : FALSE, '#states' => [ 'visible' => [ [':input[name="og_is_group"]' => ['checked' => TRUE]], [':input[name="og_group_content_bundle"]' => ['checked' => TRUE]], - ] + ], ], ]; } @@ -87,7 +88,7 @@ protected function hasAccessControl() { } if (Og::isGroupContent($this->entityTypeId, $this->bundle)) { - return isset($field_definitions[OG_CONTENT_ACCESS_FIELD]); + return isset($field_definitions[OG_ACCESS_CONTENT_FIELD]); } return FALSE; diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index 90d6031b4..9c25060cd 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -2,7 +2,6 @@ namespace Drupal\og_access\Plugin\OgFields; -use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; @@ -26,7 +25,7 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'settings' => [ 'allowed_values' => [ 0 => 'Public - accessible to all site users', - 1 => 'Private - accessible only to group members', + 1 => 'Private - accessible only to group members', ], 'allowed_values_function' => '', ], diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index 206e339d6..caadb52f9 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -2,7 +2,6 @@ namespace Drupal\og_access\Plugin\OgFields; -use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; @@ -10,7 +9,7 @@ * Determine the group content visibility. * * @OgFields( - * id = OG_CONTENT_ACCESS_FIELD, + * id = OG_ACCESS_CONTENT_FIELD, * type = "node", * description = @Translation("Determine the group content visibility.") * ) @@ -26,7 +25,7 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'settings' => [ 'allowed_values' => [ 0 => 'Public - accessible to all site users', - 1 => 'Private - accessible only to group members', + 1 => 'Private - accessible only to group members', ], 'allowed_values_function' => '', ], From 98f0c38bfe29078a1002d5a81faac02ae9a57fee Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Thu, 16 Nov 2017 00:25:53 +0000 Subject: [PATCH 11/31] Fix bundle form alter class filename --- .../src/{BundleFormAlter.php => OgAccessBundleFormAlter.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename og_access/src/{BundleFormAlter.php => OgAccessBundleFormAlter.php} (100%) diff --git a/og_access/src/BundleFormAlter.php b/og_access/src/OgAccessBundleFormAlter.php similarity index 100% rename from og_access/src/BundleFormAlter.php rename to og_access/src/OgAccessBundleFormAlter.php From 202c31c568fb0293da1cbde78e59f50c9ec88b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20J=C3=A1nos=20Tat=C3=A1r?= Date: Wed, 4 Jul 2018 21:48:16 +0200 Subject: [PATCH 12/31] #242 Improvements for og_access port. (#2) * #242 Remove og_ui dependency, replace defines with OgAccess class and its consts, also in the whole module. * #242 Grammar issue is fixed. * #242 Introduce service injection and replace t() with the injected one. * #242 PHPCS fixes. --- og_access/og_access.info.yml | 1 - og_access/og_access.module | 60 ++++++------------- og_access/src/OgAccess.php | 35 +++++++++++ og_access/src/OgAccessBundleFormAlter.php | 17 ++++-- .../src/Plugin/OgFields/OgAccessField.php | 4 +- .../Plugin/OgFields/OgContentAccessField.php | 6 +- 6 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 og_access/src/OgAccess.php diff --git a/og_access/og_access.info.yml b/og_access/og_access.info.yml index 0a1474b89..b15aa25b4 100644 --- a/og_access/og_access.info.yml +++ b/og_access/og_access.info.yml @@ -7,4 +7,3 @@ type: module dependencies: - og - - og_ui diff --git a/og_access/og_access.module b/og_access/og_access.module index ee3063f66..dc4aa6c42 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -18,31 +18,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\node\NodeInterface; use Drupal\og\Og; use Drupal\og_access\OgAccessBundleFormAlter; - -/** - * The access realm of group member. - */ -define('OG_ACCESS_REALM', 'og_access'); - -/** - * Group public access field. - */ -define('OG_ACCESS_FIELD', 'group_access'); - -/** - * Group public access field. - */ -define('OG_ACCESS_CONTENT_FIELD', 'group_content_access'); - -/** - * Public group/group content access. - */ -define('OG_ACCESS_PUBLIC', 0); - -/** - * Private group/group content access. - */ -define('OG_ACCESS_PRIVATE', 1); +use Drupal\og_access\OgAccess; /** * Implements hook_node_grants(). @@ -58,7 +34,7 @@ function og_access_node_grants(AccountInterface $account, $op) { foreach ($groups as $group_type => $entity_groups) { /** @var \Drupal\core\Entity\EntityInterface $group */ foreach ($entity_groups as $group) { - $realm = OG_ACCESS_REALM . ':' . $group_type; + $realm = OgAccess::OG_ACCESS_REALM . ':' . $group_type; $grants[$realm][] = $group->id(); } } @@ -72,7 +48,7 @@ function og_access_node_grants(AccountInterface $account, $op) { */ function og_access_node_access_records(NodeInterface $node) { if (!$node->isPublished()) { - // Node is unpublished, so we don't allow every group member to see it. + // Node is unpublished, so we don't allow any group member to see it. return []; } @@ -80,22 +56,22 @@ function og_access_node_access_records(NodeInterface $node) { $gids = []; if (Og::isGroup('node', $node->getType()) && - $node->hasField(OG_ACCESS_FIELD) && - !empty($node->{OG_ACCESS_FIELD}) && $node->{OG_ACCESS_FIELD}->value) { + $node->hasField(OgAccess::OG_ACCESS_FIELD) && + !empty($node->{OgAccess::OG_ACCESS_FIELD}) && $node->{OgAccess::OG_ACCESS_FIELD}->value) { // Private group. $gids['node'][] = $node->id(); } - if ($node->hasField(OG_ACCESS_CONTENT_FIELD) && - !empty($node->get(OG_ACCESS_CONTENT_FIELD))) { - $content_access = $node->get(OG_ACCESS_CONTENT_FIELD)->value; + if ($node->hasField(OgAccess::OG_ACCESS_CONTENT_FIELD) && + !empty($node->get(OgAccess::OG_ACCESS_CONTENT_FIELD))) { + $content_access = $node->get(OgAccess::OG_ACCESS_CONTENT_FIELD)->value; } else { - $content_access = OG_ACCESS_PUBLIC; + $content_access = OgAccess::OG_ACCESS_PUBLIC; } switch ($content_access) { - case OG_ACCESS_PUBLIC: + case OgAccess::OG_ACCESS_PUBLIC: // Skip non-group content nodes. if (!Og::isGroupContent('node', $node->getType())) { break; @@ -114,8 +90,8 @@ function og_access_node_access_records(NodeInterface $node) { continue; } - if ($group->hasField(OG_ACCESS_FIELD) && !empty($group->get(OG_ACCESS_FIELD)) && - $group->get(OG_ACCESS_FIELD)->value) { + if ($group->hasField(OgAccess::OG_ACCESS_FIELD) && !empty($group->get(OgAccess::OG_ACCESS_FIELD)) && + $group->get(OgAccess::OG_ACCESS_FIELD)->value) { $has_private = TRUE; } } @@ -125,7 +101,7 @@ function og_access_node_access_records(NodeInterface $node) { } break; - case OG_ACCESS_PRIVATE: + case OgAccess::OG_ACCESS_PRIVATE: $list_gids = []; /** @var \Drupal\og\OgGroupAudienceHelper $audience_helper */ $audience_helper = \Drupal::service('og.group_audience_helper'); @@ -142,7 +118,7 @@ function og_access_node_access_records(NodeInterface $node) { foreach ($gids as $group_type => $values) { foreach ($values as $gid) { $grants[] = [ - 'realm' => OG_ACCESS_REALM . ':' . $group_type, + 'realm' => OgAccess::OG_ACCESS_REALM . ':' . $group_type, 'gid' => $gid, 'grant_view' => 1, 'grant_update' => 0, @@ -198,9 +174,9 @@ function og_access_entity_type_save(EntityInterface $entity) { // Add/remove on the group itself. $is_group = Og::isGroup($entity_type_id, $bundle); if ($entity->og_is_group || $is_group) { - $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_FIELD); + $field = FieldConfig::loadByName($entity_type_id, $bundle, OgAccess::OG_ACCESS_FIELD); if (!$field && $enable_og_access) { - Og::createField(OG_ACCESS_FIELD, $entity_type_id, $bundle); + Og::createField(OgAccess::OG_ACCESS_FIELD, $entity_type_id, $bundle); } elseif ($field) { if (!$enable_og_access || $is_group && !$entity->og_is_group) { @@ -212,10 +188,10 @@ function og_access_entity_type_save(EntityInterface $entity) { // Add remove the relevant field to the group content bundle. $is_group_content = Og::isGroupContent($entity_type_id, $bundle); if ($entity->og_group_content_bundle || $is_group_content) { - $field = FieldConfig::loadByName($entity_type_id, $bundle, OG_ACCESS_CONTENT_FIELD); + $field = FieldConfig::loadByName($entity_type_id, $bundle, OgAccess::OG_ACCESS_CONTENT_FIELD); if (!$field && $enable_og_access) { - Og::createField(OG_ACCESS_CONTENT_FIELD, $entity_type_id, $bundle); + Og::createField(OgAccess::OG_ACCESS_CONTENT_FIELD, $entity_type_id, $bundle); } elseif ($field) { if (!$enable_og_access || $is_group_content && !$entity->og_group_content_bundle) { diff --git a/og_access/src/OgAccess.php b/og_access/src/OgAccess.php new file mode 100644 index 000000000..ee1237935 --- /dev/null +++ b/og_access/src/OgAccess.php @@ -0,0 +1,35 @@ +entity = $entity; + $this->stringTranslation = $string_translation; } /** @@ -59,8 +64,8 @@ public function formAlter(array &$form, FormStateInterface $form_state) { $form['og']['og_enable_access'] = [ '#type' => 'checkbox', - '#title' => t('Restrict access to group members'), - '#description' => t('Enable OG access control. Provides a new field that determines the group/group content visibility. Public groups can have member-only content. Any public group content belonging to a private group will be restricted to the members of that group only.'), + '#title' => $this->t('Restrict access to group members'), + '#description' => $this->t('Enable OG access control. Provides a new field that determines the group/group content visibility. Public groups can have member-only content. Any public group content belonging to a private group will be restricted to the members of that group only.'), '#default_value' => $this->bundle ? $this->hasAccessControl() : FALSE, '#states' => [ 'visible' => [ @@ -75,7 +80,7 @@ public function formAlter(array &$form, FormStateInterface $form_state) { * Checks whether the existing bundle has OG access control enabled. * * @return bool - * True if the group bundle has the OG_ACCESS_FIELD field -OR- + * True if the group bundle has the OgAccess::OG_ACCESS_FIELD field -OR- * if the group content bundle has the OG_CONTENT_ACCESS_FIELD field. * False otherwise. */ @@ -84,11 +89,11 @@ protected function hasAccessControl() { ->getFieldDefinitions($this->entityTypeId, $this->bundle); if (Og::isGroup($this->entityTypeId, $this->bundle)) { - return isset($field_definitions[OG_ACCESS_FIELD]); + return isset($field_definitions[OgAccess::OG_ACCESS_FIELD]); } if (Og::isGroupContent($this->entityTypeId, $this->bundle)) { - return isset($field_definitions[OG_ACCESS_CONTENT_FIELD]); + return isset($field_definitions[OgAccess::OG_ACCESS_CONTENT_FIELD]); } return FALSE; diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index 9c25060cd..d8d117e27 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -24,8 +24,8 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'cardinality' => 1, 'settings' => [ 'allowed_values' => [ - 0 => 'Public - accessible to all site users', - 1 => 'Private - accessible only to group members', + 0 => $this->t('Public - accessible to all site users'), + 1 => $this->t('Private - accessible only to group members'), ], 'allowed_values_function' => '', ], diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index caadb52f9..341f8d1ca 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -9,7 +9,7 @@ * Determine the group content visibility. * * @OgFields( - * id = OG_ACCESS_CONTENT_FIELD, + * id = OgAccess::OG_ACCESS_CONTENT_FIELD, * type = "node", * description = @Translation("Determine the group content visibility.") * ) @@ -24,8 +24,8 @@ public function getFieldStorageBaseDefinition(array $values = []) { 'cardinality' => 1, 'settings' => [ 'allowed_values' => [ - 0 => 'Public - accessible to all site users', - 1 => 'Private - accessible only to group members', + 0 => $this->t('Public - accessible to all site users'), + 1 => $this->t('Private - accessible only to group members'), ], 'allowed_values_function' => '', ], From ac43c9d0bcf0aa28df703700826ff2ff9ee4845d Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 26 Mar 2019 10:57:39 +0100 Subject: [PATCH 13/31] Update og_access/og_access.info.yml --- og_access/og_access.info.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.info.yml b/og_access/og_access.info.yml index b15aa25b4..308d67dfe 100644 --- a/og_access/og_access.info.yml +++ b/og_access/og_access.info.yml @@ -6,4 +6,4 @@ core: 8.x type: module dependencies: - - og + - og:og From 4cf5b4b8333f81d76b944eeab5f4d467327020e6 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 26 Mar 2019 15:40:43 +0100 Subject: [PATCH 14/31] Update og_access/src/Plugin/OgFields/OgAccessField.php --- og_access/src/Plugin/OgFields/OgAccessField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index d8d117e27..9dde4c3b3 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -4,6 +4,7 @@ use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; +use Drupal\og_access\OgAccess; /** * Determine if group should use default roles and permissions. From 66cbcbf5204d81f15aec97e5e662d720b664c0cc Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 26 Mar 2019 15:42:16 +0100 Subject: [PATCH 15/31] Update og_access/src/Plugin/OgFields/OgContentAccessField.php --- og_access/src/Plugin/OgFields/OgContentAccessField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index 341f8d1ca..df1cb3bb2 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -4,6 +4,7 @@ use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; +use Drupal\og_access\OgAccess; /** * Determine the group content visibility. From 50fde53de4205431dc3cc89c4f2fdb08d1f7c0cc Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 09:42:04 +0200 Subject: [PATCH 16/31] Fixed fatal error StringTranslationTrait not found --- og_access/src/OgAccessBundleFormAlter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/og_access/src/OgAccessBundleFormAlter.php b/og_access/src/OgAccessBundleFormAlter.php index 35ffe35ec..3826650ae 100644 --- a/og_access/src/OgAccessBundleFormAlter.php +++ b/og_access/src/OgAccessBundleFormAlter.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\og\Og; use Drupal\Core\StringTranslation\TranslationInterface; From 40acefaf522d0e6e9b5b45360d3c30cc559fba8d Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 09:44:53 +0200 Subject: [PATCH 17/31] Fixed ArgumentCountError: Too few arguments for OgAccessBundleFormAlter::__construct --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index dc4aa6c42..862ff703d 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -135,7 +135,7 @@ function og_access_node_access_records(NodeInterface $node) { */ function og_access_form_alter(array &$form, FormStateInterface $form_state, $form_id) { if ($form_state->getFormObject() instanceof BundleEntityFormBase) { - (new OgAccessBundleFormAlter($form_state->getFormObject()->getEntity())) + (new OgAccessBundleFormAlter($form_state->getFormObject()->getEntity(), \Drupal::service('string_translation'))) ->formAlter($form, $form_state); } } From 645f40ae76a84fa4ebc288d699e273f458cd61e2 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 13:54:37 +0200 Subject: [PATCH 18/31] Update og_access/src/Plugin/OgFields/OgContentAccessField.php --- og_access/src/Plugin/OgFields/OgContentAccessField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index df1cb3bb2..5119dde61 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -10,7 +10,7 @@ * Determine the group content visibility. * * @OgFields( - * id = OgAccess::OG_ACCESS_CONTENT_FIELD, + * id = \Drupal\og_access\OgAccess\OgAccess::OG_ACCESS_CONTENT_FIELD, * type = "node", * description = @Translation("Determine the group content visibility.") * ) From babf336b597093c4b677ade9b6c20dfbe5412fb1 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 13:56:36 +0200 Subject: [PATCH 19/31] Update og_access/src/Plugin/OgFields/OgContentAccessField.php --- og_access/src/Plugin/OgFields/OgContentAccessField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index 5119dde61..bae9c5224 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -10,7 +10,7 @@ * Determine the group content visibility. * * @OgFields( - * id = \Drupal\og_access\OgAccess\OgAccess::OG_ACCESS_CONTENT_FIELD, + * id = \Drupal\og_access\OgAccess::OG_ACCESS_CONTENT_FIELD, * type = "node", * description = @Translation("Determine the group content visibility.") * ) From 71f636ff626cfeb38affe3f85b5ad578ca5d3bce Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 14:01:19 +0200 Subject: [PATCH 20/31] Update og_access/src/Plugin/OgFields/OgAccessField.php --- og_access/src/Plugin/OgFields/OgAccessField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index 9dde4c3b3..cb9356c20 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -10,7 +10,7 @@ * Determine if group should use default roles and permissions. * * @OgFields( - * id = OG_ACCESS_FIELD, + * id = \Drupal\og_access\OgAccess::OG_ACCESS_FIELD, * type = "group", * description = @Translation("Determine access to the group.") * ) From 7e0b216fa62667b53651cd2b614f623bf7b33315 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 14:43:12 +0200 Subject: [PATCH 21/31] Update og_access/src/Plugin/OgFields/OgContentAccessField.php --- og_access/src/Plugin/OgFields/OgContentAccessField.php | 1 - 1 file changed, 1 deletion(-) diff --git a/og_access/src/Plugin/OgFields/OgContentAccessField.php b/og_access/src/Plugin/OgFields/OgContentAccessField.php index bae9c5224..fc59bb751 100644 --- a/og_access/src/Plugin/OgFields/OgContentAccessField.php +++ b/og_access/src/Plugin/OgFields/OgContentAccessField.php @@ -4,7 +4,6 @@ use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; -use Drupal\og_access\OgAccess; /** * Determine the group content visibility. From eb548eb853f92808fff87829a1233715c1b1d6c2 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 9 Apr 2019 14:43:31 +0200 Subject: [PATCH 22/31] Update og_access/src/Plugin/OgFields/OgAccessField.php --- og_access/src/Plugin/OgFields/OgAccessField.php | 1 - 1 file changed, 1 deletion(-) diff --git a/og_access/src/Plugin/OgFields/OgAccessField.php b/og_access/src/Plugin/OgFields/OgAccessField.php index cb9356c20..d2638ff06 100644 --- a/og_access/src/Plugin/OgFields/OgAccessField.php +++ b/og_access/src/Plugin/OgFields/OgAccessField.php @@ -4,7 +4,6 @@ use Drupal\og\OgFieldBase; use Drupal\og\OgFieldsInterface; -use Drupal\og_access\OgAccess; /** * Determine if group should use default roles and permissions. From 4ab462aa65af164148e25973b2fe503be0d7742a Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Thu, 18 Apr 2019 19:46:44 +0200 Subject: [PATCH 23/31] Rebuild node access permissions (#3) * Rebuild node access permissions * Update og_access.install * Update og_access.install * Update og_access/og_access.install Co-Authored-By: MPParsley * Update og_access/og_access.install --- og_access/og_access.install | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 og_access/og_access.install diff --git a/og_access/og_access.install b/og_access/og_access.install new file mode 100644 index 000000000..0f04c1371 --- /dev/null +++ b/og_access/og_access.install @@ -0,0 +1,14 @@ + Date: Fri, 9 Aug 2019 07:58:19 +0200 Subject: [PATCH 24/31] Update og_access/og_access.module --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 862ff703d..9d9de6915 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -205,7 +205,7 @@ function og_access_entity_type_save(EntityInterface $entity) { * Implements hook_module_implements_alter(). */ function og_access_module_implements_alter(&$implementations, $hook) { - if ($hook == 'form_alter') { + if ($hook === 'form_alter') { // Move our form alter after the og_ui one. // @TODO remove once og_ui and og are merged. $group = $implementations['og_access']; From 60197b677b0b61228a4476e797c15d4d404a3a0c Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 21 Aug 2019 20:02:21 +0200 Subject: [PATCH 25/31] Update og_access/og_access.module --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 9d9de6915..34f84d5b5 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -24,7 +24,7 @@ use Drupal\og_access\OgAccess; * Implements hook_node_grants(). */ function og_access_node_grants(AccountInterface $account, $op) { - if ($op != 'view') { + if ($op !== 'view') { return []; } From 29de2b3474a5a2faaaa94dbd7f29157eb64309dd Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 10 Sep 2019 12:40:33 +0200 Subject: [PATCH 26/31] Fixed deprecation --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 34f84d5b5..d474ddf0e 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -30,7 +30,7 @@ function og_access_node_grants(AccountInterface $account, $op) { /** @var \Drupal\og\MembershipManager $membership_manager */ $membership_manager = \Drupal::service('og.membership_manager'); - if ($groups = $membership_manager->getUserGroups($account)) { + if ($groups = $membership_manager->getUserGroups($account->id())) { foreach ($groups as $group_type => $entity_groups) { /** @var \Drupal\core\Entity\EntityInterface $group */ foreach ($entity_groups as $group) { From 1ab94666a1977733832fec59ff637c59aee97df2 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 10 Aug 2020 10:34:48 +0200 Subject: [PATCH 27/31] Add strict types --- og_access/og_access.install | 2 ++ og_access/og_access.module | 2 ++ og_access/src/OgAccess.php | 2 ++ og_access/src/OgAccessBundleFormAlter.php | 2 ++ og_access/src/Plugin/OgFields/OgAccessField.php | 2 ++ og_access/src/Plugin/OgFields/OgContentAccessField.php | 2 ++ 6 files changed, 12 insertions(+) diff --git a/og_access/og_access.install b/og_access/og_access.install index 0f04c1371..c39a15be7 100644 --- a/og_access/og_access.install +++ b/og_access/og_access.install @@ -5,6 +5,8 @@ * Install/update/uninstall hook implementations. */ +declare(strict_types = 1); + /** * Implements hook_install(). */ diff --git a/og_access/og_access.module b/og_access/og_access.module index d474ddf0e..6f1a3d9d8 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -9,6 +9,8 @@ * @TODO move grants/access to service */ +declare(strict_types = 1); + use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\Core\Entity\BundleEntityFormBase; use Drupal\Core\Entity\EntityInterface; diff --git a/og_access/src/OgAccess.php b/og_access/src/OgAccess.php index ee1237935..548a86796 100644 --- a/og_access/src/OgAccess.php +++ b/og_access/src/OgAccess.php @@ -1,5 +1,7 @@ Date: Tue, 19 Jan 2021 13:28:12 +0100 Subject: [PATCH 28/31] Apply suggestions from code review --- og_access/og_access.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 6f1a3d9d8..3f2d7be92 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -4,9 +4,9 @@ * @file * Enable access control for private and public groups and group content. * - * @TODO handle visibility change - * @TODO set group content visibility default to that of the group - * @TODO move grants/access to service + * @todo Handle visibility change. + * @todo Set group content visibility default to that of the group. + * @todo Move grants/access to service. */ declare(strict_types = 1); @@ -209,7 +209,7 @@ function og_access_entity_type_save(EntityInterface $entity) { function og_access_module_implements_alter(&$implementations, $hook) { if ($hook === 'form_alter') { // Move our form alter after the og_ui one. - // @TODO remove once og_ui and og are merged. + // @todo Remove once og_ui and og are merged. $group = $implementations['og_access']; unset($implementations['og_access']); $implementations['og_access'] = $group; From 57f47d047cfb721b02b7eae9b3846a365b67e2ef Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 20 Apr 2021 14:28:09 +0200 Subject: [PATCH 29/31] Update og_access/og_access.module --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index 3f2d7be92..c05c379ac 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -209,7 +209,7 @@ function og_access_entity_type_save(EntityInterface $entity) { function og_access_module_implements_alter(&$implementations, $hook) { if ($hook === 'form_alter') { // Move our form alter after the og_ui one. - // @todo Remove once og_ui and og are merged. + // @todo: Remove once og_ui and og are merged. $group = $implementations['og_access']; unset($implementations['og_access']); $implementations['og_access'] = $group; From e635a757da630ce5a0717112cc06b2b38f3b11d6 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Thu, 22 Apr 2021 09:39:57 +0200 Subject: [PATCH 30/31] Add support for Drupal 9 --- og_access/og_access.info.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.info.yml b/og_access/og_access.info.yml index 308d67dfe..45cb18ce1 100644 --- a/og_access/og_access.info.yml +++ b/og_access/og_access.info.yml @@ -2,7 +2,7 @@ name: Organic Groups access control description: "Enable access control for private and public groups and group content." package: Organic Groups -core: 8.x +core_version_requirement: ^8 || ^9 type: module dependencies: From d59a0ee51e0867460b61ad38654f3cf14fa96377 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Thu, 22 Apr 2021 20:28:22 +0200 Subject: [PATCH 31/31] Update og_access/og_access.module --- og_access/og_access.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_access/og_access.module b/og_access/og_access.module index c05c379ac..3f2d7be92 100644 --- a/og_access/og_access.module +++ b/og_access/og_access.module @@ -209,7 +209,7 @@ function og_access_entity_type_save(EntityInterface $entity) { function og_access_module_implements_alter(&$implementations, $hook) { if ($hook === 'form_alter') { // Move our form alter after the og_ui one. - // @todo: Remove once og_ui and og are merged. + // @todo Remove once og_ui and og are merged. $group = $implementations['og_access']; unset($implementations['og_access']); $implementations['og_access'] = $group;