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

Commit

Permalink
Merge pull request #700 from Gizra/feature/phpcs
Browse files Browse the repository at this point in the history
Fix PHP CS issues
  • Loading branch information
amitaibu authored Jan 19, 2021
2 parents d3319da + 2860f6b commit 7fc797b
Show file tree
Hide file tree
Showing 59 changed files with 227 additions and 116 deletions.
4 changes: 3 additions & 1 deletion og.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function og_field_views_data(FieldStorageConfigInterface $field_storage) {
'title' => new TranslatableMarkup('@label referenced from @field_name', $args),
'label' => new TranslatableMarkup('@field_name: @label', $args),
'group' => $entity_type->getLabel(),
'help' => new TranslatableMarkup('Appears in: @bundles.', ['@bundles' => implode(', ', $field_storage->getBundles())]),
'help' => new TranslatableMarkup('Appears in: @bundles.', [
'@bundles' => implode(', ', $field_storage->getBundles()),
]),
'id' => 'standard',
'base' => $target_base_table,
'entity type' => $target_entity_type_id,
Expand Down
2 changes: 1 addition & 1 deletion og_ui/src/Form/AdminSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $config_og->get('node_access_strict'),
];

// @todo: Port og_ui_admin_people_view.
// @todo Port og_ui_admin_people_view.
$form['og_delete_orphans'] = [
'#type' => 'checkbox',
'#title' => $this->t('Delete orphans'),
Expand Down
2 changes: 1 addition & 1 deletion og_ui/tests/src/Functional/BundleFormAlterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Drupal\Core\Form\FormState;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\og\Og;
use Drupal\og_ui\BundleFormAlter;
use Drupal\Tests\BrowserTestBase;

/**
* Test making a bundle a group and a group content.
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/OgAdminMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Drupal\views\Views;

/**
* OgAdminMembersController class.
* Displays the members administration page.
*/
class OgAdminMembersController extends ControllerBase {

Expand Down
7 changes: 5 additions & 2 deletions src/Controller/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Drupal\og\Og;
use Drupal\og\OgAccessInterface;
use Drupal\og\OgMembershipInterface;
use Drupal\og\OgMembershipTypeInterface;
Expand All @@ -17,7 +18,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\og\Og;

/**
* Controller for OG subscription routes.
Expand Down Expand Up @@ -100,7 +100,10 @@ public function subscribe($entity_type_id, EntityInterface $group, OgMembershipT
}
else {
$user_register_url = Url::fromRoute('user.register', [], $destination)->toString();
$params = [':register' => $user_register_url, ':login' => $user_login_url];
$params = [
':register' => $user_register_url,
':login' => $user_login_url,
];
$this->messenger->addMessage($this->t('In order to join any group, you must <a href=":login">login</a> or <a href=":register">register</a> a new account. After you have successfully done so, you will need to request membership again.', $params));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/OgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\UserInterface;
use Drupal\og\Og;
use Drupal\og\OgMembershipInterface;
use Drupal\og\OgRoleInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\user\UserInterface;

/**
* The membership entity that connects a group and a user.
Expand Down
6 changes: 3 additions & 3 deletions src/Form/GroupSubscribeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class GroupSubscribeForm extends ContentEntityForm {
* The OG access service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface|null $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* @param \Drupal\Component\Datetime\TimeInterface|null $time
* The time service.
*
* @todo Set the `EntityRepositoryInterface` type hint on the second argument
Expand All @@ -50,7 +50,7 @@ class GroupSubscribeForm extends ContentEntityForm {
*
* @see https://github.com/Gizra/og/issues/397
*/
public function __construct(OgAccessInterface $og_access, EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
public function __construct(OgAccessInterface $og_access, EntityRepositoryInterface $entity_repository, ?EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, ?TimeInterface $time = NULL) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->ogAccess = $og_access;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GroupTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Drupal\og;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\og\Event\GroupCreationEvent;
use Drupal\og\Event\GroupCreationEventInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -268,7 +268,7 @@ public function addGroup($entity_type_id, $bundle_id) {

$groups = $editable->get('groups');
$groups[$entity_type_id][] = $bundle_id;
// @todo, just key by bundle ID instead?
// @todo Key by bundle ID instead?
$groups[$entity_type_id] = array_unique($groups[$entity_type_id]);

$editable->set('groups', $groups);
Expand Down
6 changes: 3 additions & 3 deletions src/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\og\Entity\OgMembership;
use Drupal\user\UserInterface;
Expand Down Expand Up @@ -380,7 +379,8 @@ public function getGroupContentIds(EntityInterface $entity, array $entity_types
}

/** @var \Drupal\field\FieldStorageConfigInterface[] $fields */
$fields = array_filter(FieldStorageConfig::loadMultiple($query->execute()), function (FieldStorageConfigInterface $field) use ($entity) {
$storage = $this->entityTypeManager->getStorage('field_storage_config');
$fields = array_filter($storage->loadMultiple($query->execute()), function (FieldStorageConfigInterface $field) use ($entity) {
$type_matches = $field->getSetting('target_type') === $entity->getEntityTypeId();
// If the list of target bundles is empty, it targets all bundles.
$bundle_matches = empty($field->getSetting('target_bundles')) || in_array($entity->bundle(), $field->getSetting('target_bundles'));
Expand Down Expand Up @@ -463,7 +463,7 @@ public function isMemberBlocked(EntityInterface $group, $user_id) {
* @return array
* The prepared array.
*/
protected function prepareConditionArray(array $value, array $default = NULL) {
protected function prepareConditionArray(array $value, ?array $default = NULL) {
// Fall back to the default value if the passed in value is empty and a
// default value is given.
if (empty($value) && $default !== NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/Og.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function createField($plugin_id, $entity_type, $bundle, array $set
$field_definition = FieldConfig::create($field_config);
$field_definition->save();

// @todo: Verify this is still needed here.
// @todo Verify this is still needed here.
static::invalidateCache();
}

Expand Down
8 changes: 4 additions & 4 deletions src/OgAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountProxy
/**
* {@inheritdoc}
*/
public function userAccess(EntityInterface $group, string $permission, AccountInterface $user = NULL, bool $skip_alter = FALSE): AccessResultInterface {
public function userAccess(EntityInterface $group, string $permission, ?AccountInterface $user = NULL, bool $skip_alter = FALSE): AccessResultInterface {
$group_type_id = $group->getEntityTypeId();
$bundle = $group->bundle();
// As Og::isGroup depends on this config, we retrieve it here and set it as
Expand Down Expand Up @@ -223,7 +223,7 @@ public function userAccess(EntityInterface $group, string $permission, AccountIn
/**
* {@inheritdoc}
*/
public function userAccessEntity(string $permission, EntityInterface $entity, AccountInterface $user = NULL): AccessResultInterface {
public function userAccessEntity(string $permission, EntityInterface $entity, ?AccountInterface $user = NULL): AccessResultInterface {
$result = AccessResult::neutral();

$entity_type = $entity->getEntityType();
Expand Down Expand Up @@ -262,7 +262,7 @@ public function userAccessEntity(string $permission, EntityInterface $entity, Ac
/**
* {@inheritdoc}
*/
public function userAccessEntityOperation(string $operation, EntityInterface $entity, AccountInterface $user = NULL): AccessResultInterface {
public function userAccessEntityOperation(string $operation, EntityInterface $entity, ?AccountInterface $user = NULL): AccessResultInterface {
$result = AccessResult::neutral();

$entity_type = $entity->getEntityType();
Expand Down Expand Up @@ -307,7 +307,7 @@ public function userAccessEntityOperation(string $operation, EntityInterface $en
/**
* {@inheritdoc}
*/
public function userAccessGroupContentEntityOperation(string $operation, EntityInterface $group_entity, EntityInterface $group_content_entity, AccountInterface $user = NULL): AccessResultInterface {
public function userAccessGroupContentEntityOperation(string $operation, EntityInterface $group_entity, EntityInterface $group_content_entity, ?AccountInterface $user = NULL): AccessResultInterface {
// Default to the current user.
$user = $user ?: $this->accountProxy->getAccount();

Expand Down
8 changes: 4 additions & 4 deletions src/OgAccessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface OgAccessInterface {
* @return \Drupal\Core\Access\AccessResultInterface
* An access result object.
*/
public function userAccess(EntityInterface $group, string $permission, AccountInterface $user = NULL, bool $skip_alter = FALSE): AccessResultInterface;
public function userAccess(EntityInterface $group, string $permission, ?AccountInterface $user = NULL, bool $skip_alter = FALSE): AccessResultInterface;

/**
* Determines whether a user has a group permission in a given entity.
Expand Down Expand Up @@ -89,7 +89,7 @@ public function userAccess(EntityInterface $group, string $permission, AccountIn
*
* @see \Drupal\og\userAccess();
*/
public function userAccessEntity(string $permission, EntityInterface $entity, AccountInterface $user = NULL): AccessResultInterface;
public function userAccessEntity(string $permission, EntityInterface $entity, ?AccountInterface $user = NULL): AccessResultInterface;

/**
* Checks whether a user can perform an operation on a given entity.
Expand Down Expand Up @@ -127,7 +127,7 @@ public function userAccessEntity(string $permission, EntityInterface $entity, Ac
*
* @see \Drupal\og\userAccessGroupContentEntityOperation();
*/
public function userAccessEntityOperation(string $operation, EntityInterface $entity, AccountInterface $user = NULL): AccessResultInterface;
public function userAccessEntityOperation(string $operation, EntityInterface $entity, ?AccountInterface $user = NULL): AccessResultInterface;

/**
* Checks access for entity operations on group content in a specific group.
Expand Down Expand Up @@ -160,7 +160,7 @@ public function userAccessEntityOperation(string $operation, EntityInterface $en
* @return \Drupal\Core\Access\AccessResultInterface
* The access result object.
*/
public function userAccessGroupContentEntityOperation(string $operation, EntityInterface $group_entity, EntityInterface $group_content_entity, AccountInterface $user = NULL): AccessResultInterface;
public function userAccessGroupContentEntityOperation(string $operation, EntityInterface $group_entity, EntityInterface $group_content_entity, ?AccountInterface $user = NULL): AccessResultInterface;

/**
* Resets the static cache.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Action/AddSingleOgMembershipRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AddSingleOgMembershipRole extends ChangeSingleOgMembershipRoleBase {
/**
* {@inheritdoc}
*/
public function execute(OgMembership $membership = NULL) {
public function execute(?OgMembership $membership = NULL) {
if (!$membership) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Action/ChangeMultipleOgMembershipRolesBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function execute($object = NULL) {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\og\Entity\OgMembership $object */
// Only grant access if the user has permission to manage members in this
// group.
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Action/ChangeOgMembershipStateBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function execute(OgMembership $membership = NULL) {
public function execute(?OgMembership $membership = NULL) {
if (!$membership) {
return;
}
Expand All @@ -66,7 +66,7 @@ public function execute(OgMembership $membership = NULL) {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\og\Entity\OgMembership $object */
// Deny access if the membership is not in the required state.
$original_state = $this->getOriginalState();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Action/ChangeSingleOgMembershipRoleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\og\Entity\OgMembership $object */
// Grant access if the user can manage members in this group.
$access = $this->ogAccess->userAccess($object->getGroup(), 'manage members', $account);
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Action/DeleteOgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function execute(OgMembership $membership = NULL) {
public function execute(?OgMembership $membership = NULL) {
if (!$membership) {
return;
}
Expand All @@ -71,7 +71,7 @@ public function execute(OgMembership $membership = NULL) {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\og\Entity\OgMembership $object */
// Grant access if the user can manage members in this group.
$access = $this->ogAccess->userAccess($object->getGroup(), 'manage members', $account);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Action/RemoveSingleOgMembershipRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RemoveSingleOgMembershipRole extends ChangeSingleOgMembershipRoleBase {
/**
* {@inheritdoc}
*/
public function execute(OgMembership $membership = NULL) {
public function execute(?OgMembership $membership = NULL) {
if (!$membership) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Action/UnblockOgMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function execute(OgMembership $membership = NULL) {
public function execute(?OgMembership $membership = NULL) {
if (!$membership) {
return;
}
Expand All @@ -73,7 +73,7 @@ public function execute(OgMembership $membership = NULL) {
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\og\Entity\OgMembership $object */
// Deny access if the membership is not blocked.
if ($object->getState() !== OgMembershipInterface::STATE_BLOCKED) {
Expand Down
13 changes: 7 additions & 6 deletions src/Plugin/Block/RecentGroupContentBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\og\GroupTypeManagerInterface;
use Drupal\og\OgContextInterface;
Expand Down Expand Up @@ -219,7 +218,10 @@ public function getCacheTags() {
public function getCacheContexts() {
// The block varies by user because of the access check on the query that
// retrieves the group content.
return Cache::mergeContexts(parent::getCacheContexts(), ['user', 'og_group_context']);
return Cache::mergeContexts(parent::getCacheContexts(), [
'user',
'og_group_context',
]);
}

/**
Expand All @@ -236,14 +238,13 @@ protected function getGroupContent() {
$definition = $this->entityTypeManager->getDefinition($entity_type);

// Retrieve the fields which reference our entity type and bundle.
$query = $this->entityTypeManager
->getStorage('field_storage_config')
->getQuery()
$field_storage_config_storage = $this->entityTypeManager->getStorage('field_storage_config');
$query = $field_storage_config_storage->getQuery()
->condition('type', OgGroupAudienceHelperInterface::GROUP_REFERENCE)
->condition('entity_type', $entity_type);

/** @var \Drupal\field\FieldStorageConfigInterface[] $fields */
$fields = array_filter(FieldStorageConfig::loadMultiple($query->execute()), function (FieldStorageConfigInterface $field) use ($group) {
$fields = array_filter($field_storage_config_storage->loadMultiple($query->execute()), function (FieldStorageConfigInterface $field) use ($group) {
$type_matches = $field->getSetting('target_type') === $group->getEntityTypeId();
// If the list of target bundles is empty, it targets all bundles.
$bundle_matches = empty($field->getSetting('target_bundles')) || in_array($group->bundle(), $field->getSetting('target_bundles'));
Expand Down
5 changes: 4 additions & 1 deletion src/Plugin/Condition/GroupType.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ public function summary() {
$group_types = $this->configuration['group_types'];
$last_group = array_pop($group_types);
$group_types = implode(', ', $group_types);
return $this->t('The group type is @group_types or @last_group', ['@group_types' => $group_types, '@last_group' => $last_group]);
return $this->t('The group type is @group_types or @last_group', [
'@group_types' => $group_types,
'@last_group' => $last_group,
]);
}
$group_type = reset($this->configuration['group_types']);
return $this->t('The group type is @group_type', ['@group_type' => $group_type]);
Expand Down
5 changes: 5 additions & 0 deletions src/Plugin/Derivative/OgLocalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ public function getDerivativeDefinitions($base_plugin_definition) {
];
}

// @todo Coder throws a false positive for this line. Remove this once the
// issue is fixed in the Coder project.
// @see https://www.drupal.org/project/coder/issues/3065679
// @codingStandardsIgnoreLine
foreach ($derivatives as &$entry) {
// @codingStandardsIgnoreLine
$entry += $base_plugin_definition;
}

Expand Down
Loading

0 comments on commit 7fc797b

Please sign in to comment.