Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab committed Sep 22, 2017
1 parent acd1987 commit 80b00c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
17 changes: 8 additions & 9 deletions og_access/og_access.module
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +151,6 @@ function og_access_node_access_records(NodeInterface $node) {
}
}


return !empty($grants) ? $grants : [];
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions og_access/src/BundleFormAlter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Helper for og_access_form_alter().
*/
class BundleFormAlter {
class OgAccessBundleFormAlter {

/**
* The entity bundle.
Expand Down Expand Up @@ -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]],
]
],
],
];
}
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions og_access/src/Plugin/OgFields/OgAccessField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\og_access\Plugin\OgFields;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\og\OgFieldBase;
use Drupal\og\OgFieldsInterface;

Expand All @@ -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' => '',
],
Expand Down
5 changes: 2 additions & 3 deletions og_access/src/Plugin/OgFields/OgContentAccessField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Drupal\og_access\Plugin\OgFields;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\og\OgFieldBase;
use Drupal\og\OgFieldsInterface;

/**
* 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.")
* )
Expand All @@ -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' => '',
],
Expand Down

0 comments on commit 80b00c9

Please sign in to comment.