Skip to content

Commit

Permalink
Issue #3403634 by SV: Replace deprecates for the all services/plugins…
Browse files Browse the repository at this point in the history
… in social_group module
  • Loading branch information
volodymyr-sydor committed Jan 25, 2024
1 parent 471697e commit e2e2e6b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function social_flexible_group_book_form_node_form_alter(array &$form, FormState

if ($group instanceof GroupInterface) {
/** @var \Drupal\social_node\Entity\Node[] $books */
$books = $group->getContentEntities('group_node:book');
$books = $group->getRelatedEntities('group_node:book');
$bids = array_map(function ($book) {
return $book->id();
}, $books);
Expand Down Expand Up @@ -214,7 +214,7 @@ function _social_flexible_group_book_ajax_callback(array $form, FormStateInterfa
}

/** @var \Drupal\social_node\Entity\Node[] $books_in_group */
$books_in_group = $group->getContentEntities('group_node:book', [
$books_in_group = $group->getRelatedEntities('group_node:book', [
'entity_id' => $all_books,
]);
// Get translations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function batchUpdateGroupContentVisibility(GroupInterface $group,
// Load all the GroupContentEntities from Post to content.
// Memberships don't need an update.
$entities = $posts = [];
$entities = $group->getContentEntities();
$entities = $group->getRelatedEntities();
$posts = self::getPostsFromGroup($group);

// Add posts to the entities we need to update based on visibility.
Expand Down Expand Up @@ -128,7 +128,7 @@ public static function updateVisibility($entity, array $new_options, array &$con
$entity->save();
}

// Make sure our GroupContent referenced entities also get invalidated.
// Make sure our GroupRelationship referenced entities also get invalidated.
$tags = $entity->getCacheTagsToInvalidate();
Cache::invalidateTags($tags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function social_group_tokens($type, $tokens, array $data, array $options, Bubble
if ($entity !== NULL) {
// If it's group content.
if ($entity instanceof GroupRelationshipInterface) {
$group_content_type = $entity->getGroupContentType();
$group_content_type = $entity->getRelationshipType();
if ($group_content_type !== NULL) {
$display_name = $group_content_type->label();
$content_url = Url::fromRoute('entity.node.canonical',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function groupAddMemberTitle(): TranslatableMarkup {

if (
$group_content instanceof GroupRelationshipInterface &&
$group_content->getGroupContentType()->getContentPluginId() === 'group_invitation'
$group_content->getPluginId() === 'group_invitation'
) {
if ($group instanceof SocialGroupInterface) {
return $this->t('Add invites to group: @group_name', [
Expand Down Expand Up @@ -160,7 +160,7 @@ public function groupRemoveContentTitle(): TranslatableMarkup {

if (
$group_content instanceof GroupRelationshipInterface &&
$group_content->getGroupContentType()->getContentPluginId() === 'group_invitation'
$group_content->getPluginId() === 'group_invitation'
) {
$group = $this->routeMatch->getParameter('group');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Mod
*/
public static function batchUpdateGroupContentVisibility(GroupInterface $group, $new_type) {
// Set it up as a batch. We need to update visibility.
// Load all the GroupContentEntities from Post to Memberships to content.
$entities = $group->getContentEntities();
// Load all the GroupRelationshipEntities from Post to Memberships to content.
$entities = $group->getRelatedEntities();

$posts = self::getPostsFromGroup($group);
foreach ($posts as $pid => $post) {
Expand Down Expand Up @@ -102,7 +102,7 @@ public static function batchUpdateGroupContentVisibility(GroupInterface $group,
/**
* Update visibility for all Group Content based on a new group type.
*
* @param \Drupal\node\Entity\Node|\Drupal\social_post\Entity\Post|\Drupal\group\GroupMembership|\Drupal\group\Entity\GroupContentInterface $entity
* @param \Drupal\node\Entity\Node|\Drupal\social_post\Entity\Post|\Drupal\group\GroupMembership|\Drupal\group\Entity\GroupRelationshipInterface $entity
* The content we are updating.
* @param string $new_type
* The new Group type.
Expand All @@ -126,16 +126,16 @@ public static function updateVisibility($entity, $new_type, array &$context) {
$entity->set('field_content_visibility', $default_visibility);
$entity->save();
}
// For GroupMembers we have to update the GroupContent.
// For GroupMembers we have to update the GroupRelationship.
if ($entity instanceof GroupMembership) {
$new_group_type = $new_type . '-group_membership';
$membershipEntity = $entity->getGroupContent();
$membershipEntity = $entity->getGroupRelationship();
$membershipEntity->set('type', $new_group_type);
$membershipEntity->save();
$entity = $membershipEntity;
}

// Make sure our GroupContent referenced entities also get invalidated.
// Make sure our GroupRelationship referenced entities also get invalidated.
$tags = $entity->getCacheTagsToInvalidate();
Cache::invalidateTags($tags);

Expand Down
10 changes: 5 additions & 5 deletions modules/social_features/social_group/src/GroupMuteNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\flag\FlaggingInterface;
use Drupal\flag\FlagServiceInterface;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupContentInterface;
use Drupal\group\Entity\GroupRelationship;
use Drupal\group\Entity\GroupRelationshipInterface;
use Drupal\group\Entity\GroupInterface;
use Drupal\node\NodeInterface;
use Drupal\social_post\Entity\PostInterface;
Expand Down Expand Up @@ -98,7 +98,7 @@ public function getGroupByContent(EntityInterface $entity = NULL): ?GroupInterfa
return NULL;
}

if ($entity instanceof GroupContentInterface) {
if ($entity instanceof GroupRelationshipInterface) {
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $entity->getGroup();
}
Expand All @@ -125,9 +125,9 @@ public function getGroupByContent(EntityInterface $entity = NULL): ?GroupInterfa
case 'node':
if ($entity instanceof NodeInterface) {
// Try to get the group.
$group_content = GroupContent::loadByEntity($entity);
$group_content = GroupRelationship::loadByEntity($entity);
if (!empty($group_content)) {
/** @var \Drupal\group\Entity\GroupContentInterface $group_content */
/** @var \Drupal\group\Entity\GroupRelationshipInterface $group_content */
$group_content = reset($group_content);
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $group_content->getGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ protected function count(GroupInterface $group, $type) {
// return $query->countQuery()->execute()->fetchField();

return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\group\Entity\GroupContentInterface;
use Drupal\group\Entity\GroupRelationshipInterface;
use Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -88,7 +88,7 @@ public function execute($entity = NULL) {
$update = TRUE;
$value = [];

/** @var \Drupal\group\Entity\GroupContentInterface $entity */
/** @var \Drupal\group\Entity\GroupRelationshipInterface $entity */
/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $roles */
$roles = &$entity->get('group_roles');

Expand Down Expand Up @@ -149,7 +149,7 @@ public function execute($entity = NULL) {
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($object instanceof GroupContentInterface && $object->getContentPlugin()->getPluginId() === 'group_membership') {
if ($object instanceof GroupRelationshipInterface && $object->getPluginId() === 'group_membership') {
$access = $object->access('update', $account, TRUE);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\group\Entity\GroupInterface;
use Drupal\group\Plugin\GroupContentEnablerManager;
use Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface;
use Drupal\select2\Plugin\Field\FieldWidget\Select2EntityReferenceWidget;
use Drupal\user\EntityOwnerInterface;
use Drupal\user\UserInterface;
Expand Down Expand Up @@ -66,7 +66,7 @@ class SocialGroupSelectorWidget extends Select2EntityReferenceWidget implements
/**
* The plugin manager.
*/
protected GroupContentEnablerManager $pluginManager;
protected GroupRelationTypeManagerInterface $pluginManager;

/**
* The user entity storage..
Expand All @@ -78,7 +78,7 @@ class SocialGroupSelectorWidget extends Select2EntityReferenceWidget implements
*
* {@inheritdoc}
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ConfigFactoryInterface $configFactory, AccountProxyInterface $currentUser, ModuleHandler $moduleHandler, GroupContentEnablerManager $pluginManager, EntityTypeManagerInterface $entity_type_manager) {
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ConfigFactoryInterface $configFactory, AccountProxyInterface $currentUser, ModuleHandler $moduleHandler, GroupRelationTypeManagerInterface $pluginManager, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->configFactory = $configFactory;
$this->moduleHander = $moduleHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\social_group\Entity\Group;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupRelationship;

/**
* Field handler to present the groups membership count.
Expand All @@ -27,7 +27,7 @@ public function query() {}
public function render(ResultRow $row) {
$group_content = $this->getEntity($row);
// Grab the group from the group_invite.
if ($group_content instanceof GroupContent) {
if ($group_content instanceof GroupRelationship) {
$group = $group_content->getGroup();
if ($group instanceof Group) {
/** @var \Drupal\social_group\GroupStatistics $group_statistics */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\social_group;

use Drupal\group\Entity\Group;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupRelationship;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
Expand Down Expand Up @@ -130,15 +130,15 @@ public function setGroupsForNode(NodeInterface $node, array $groups_to_remove, a
if (!empty($groups_to_remove)) {
$groups = Group::loadMultiple($groups_to_remove);
foreach ($groups as $group) {
self::removeGroupContent($node, $group);
self::removeGroupRelationship($node, $group);
}
}

// Add the content to the Group if we placed it in a group.
if (!empty($groups_to_add)) {
$groups = Group::loadMultiple($groups_to_add);
foreach ($groups as $group) {
self::addGroupContent($node, $group);
self::addGroupRelationship($node, $group);
}
}

Expand All @@ -151,33 +151,33 @@ public function setGroupsForNode(NodeInterface $node, array $groups_to_remove, a
}

/**
* Creates a group content.
* Creates a group relationship.
*
* @param \Drupal\node\NodeInterface $node
* Object of a node.
* @param \Drupal\group\Entity\Group $group
* Object of a group.
*/
public static function addGroupContent(NodeInterface $node, Group $group) {
public static function addGroupRelationship(NodeInterface $node, Group $group) {
// @todo Check if group plugin id exists.
$plugin_id = 'group_node:' . $node->bundle();
$group_contents = GroupContent::loadByEntity($node);
$group_contents = GroupRelationship::loadByEntity($node);
if (empty($group_contents)) {
$group->addContent($node, $plugin_id, ['uid' => $node->getOwnerId()]);
$group->addRelationship($node, $plugin_id, ['uid' => $node->getOwnerId()]);
}
}

/**
* Deletes a group content.
* Deletes a group relationship.
*
* @param \Drupal\node\NodeInterface $node
* Object of a node.
* @param \Drupal\group\Entity\Group $group
* Object of a group.
*/
public static function removeGroupContent(NodeInterface $node, Group $group) {
public static function removeGroupRelationship(NodeInterface $node, Group $group) {
// Try to load group content from entity.
$group_contents = GroupContent::loadByEntity($node);
$group_contents = GroupRelationship::loadByEntity($node);
foreach ($group_contents as $group_content) {
if ($group->id() === $group_content->getGroup()->id()) {
$group_content->delete();
Expand Down

0 comments on commit e2e2e6b

Please sign in to comment.