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

Commit

Permalink
Merge branch '8.x-1.x' into document-access-system
Browse files Browse the repository at this point in the history
  • Loading branch information
MPParsley authored Apr 22, 2021
2 parents 379bae8 + dd60ff6 commit f437a62
Show file tree
Hide file tree
Showing 62 changed files with 244 additions and 128 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ before_script:
# Make sure Composer is up to date.
- composer self-update

# Downgrade to composer version 1 to support Drupal 8.8.
- test ${TEST_SUITE} != "8.8.x" || composer self-update --1

# Remember the current directory for later use in the Drupal installation.
- MODULE_DIR=$(pwd)

Expand All @@ -66,12 +69,12 @@ before_script:
# Remember the Drupal installation path.
- DRUPAL_DIR=$(pwd)/drupal

# Install Composer dependencies for core. Skip this for the coding standards test.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR

# Update PHPUnit.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || travis_retry composer update phpunit/phpunit symfony/phpunit-bridge phpspec/prophecy symfony/yaml --with-dependencies --working-dir=$DRUPAL_DIR
- test ${TEST_SUITE} == "PHP_CodeSniffer" || travis_retry composer drupal-phpunit-upgrade --working-dir=$DRUPAL_DIR

# Install Composer dependencies for core. Skip this for the coding standards test.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || composer install --working-dir=$DRUPAL_DIR

# Start a web server on port 8888 in the background.
- test ${TEST_SUITE} == "PHP_CodeSniffer" || nohup php -S localhost:8888 --docroot $DRUPAL_DIR > /dev/null 2>&1 &

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ provide a quick way to get started with Organic groups.
'Subscribe' link. (Subscribing is the act of associating a user with a
group.)
To show this subscribe link:
9.1 Make sure you have the Group UI module enabled
9.2 Go to admin/config/group/permissions and make sure that the "Subscribe
1. Make sure you have the Group UI module enabled
2. Go to admin/config/group/permissions and make sure that the "Subscribe
user to group" permission is given to the appropriate user-roles.
9.3 Navigate to the "manage display" tab of your content type
3. Navigate to the "manage display" tab of your content type
(admin/structure/types/manage/group/display)
and choose the Group subscription format for the Group type field.
9.4 Back in the group view you will now notice a 'Subscribe' link (If you are
4. Back in the group view you will now notice a 'Subscribe' link (If you are
the group administrator it will say "You are the group manager").
10. In order to associate other entities with group or group content, navigate
to Organic Groups field settings", in admin/config/group/fields.
Expand Down
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
10 changes: 6 additions & 4 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 Expand Up @@ -90,7 +90,9 @@ public function getQuestion() {

$message = $this->isStateActive()
? $this->t('Are you sure you want to join the group %label?', ['%label' => $label])
: $this->t('Are you sure you want to request subscription the group %label?', ['%label' => $label]);
: $this->t('Are you sure you want to request a subscription to the group %label?', [
'%label' => $label,
]);

return $message;
}
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
4 changes: 2 additions & 2 deletions src/OgMembershipInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getType(): string;
/**
* Sets the group's roles for the current user group membership.
*
* @param \Drupal\og\Entity\OgRole[] $roles
* @param \Drupal\og\OgRoleInterface[] $roles
* The array of OG roles to set.
*
* @return \Drupal\og\OgMembershipInterface
Expand Down Expand Up @@ -208,7 +208,7 @@ public function revokeRoleById(string $role_id): OgMembershipInterface;
/**
* Gets all the referenced OG roles.
*
* @return \Drupal\og\Entity\OgRole[]
* @return \Drupal\og\OgRoleInterface[]
* List of OG roles the user own for the current membership instance.
*/
public function getRoles(): array;
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
Loading

0 comments on commit f437a62

Please sign in to comment.