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' => '', ],