BlockedUsers.php in Open Social 8.8
Same filename and directory in other branches
- 8.9 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.2 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.3 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.4 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.5 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.6 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 8.7 modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 10.3.x modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 10.0.x modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 10.1.x modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
- 10.2.x modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.php
File
modules/social_features/social_search/src/Plugin/search_api/processor/BlockedUsers.phpView source
<?php
namespace Drupal\social_search\Plugin\search_api\processor;
use Drupal\search_api\IndexInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\profile\Entity\ProfileInterface;
use Drupal\user\UserInterface;
use Drupal\search_api\Query\QueryInterface;
/**
* Ignores blocked users in index and queries.
*
* Makes sure blocked users are no longer indexed AND
* also filters out blocked users from queries.
*
* @SearchApiProcessor(
* id = "blocked_users",
* label = @Translation("Skip Blocked users"),
* description = @Translation("Makes sure that blocked users are not added to the index."),
* stages = {
* "alter_items" = 0,
* "preprocess_query" = -30,
* },
* )
*/
class BlockedUsers extends ProcessorPluginBase {
/**
* {@inheritdoc}
*/
public static function supportsIndex(IndexInterface $index) {
$entity_types = [
'profile',
];
foreach ($index
->getDatasources() as $datasource) {
if (in_array($datasource
->getEntityTypeId(), $entity_types)) {
return TRUE;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function alterIndexedItems(array &$items) {
foreach ($items as $item_id => $item) {
$object = $item
->getOriginalObject()
->getValue();
if ($object instanceof ProfileInterface) {
// Profile ownedId is the userId.
if ($object
->getOwner()
->isBlocked() === TRUE) {
unset($items[$item_id]);
}
}
elseif ($object instanceof UserInterface) {
if ($object
->isBlocked() === TRUE) {
unset($items[$item_id]);
}
}
}
}
/**
* {@inheritdoc}
*/
public function preprocessSearchQuery(QueryInterface $query) {
if (!$query
->getOption('search_api_bypass_access')) {
// Add a condition to filter out users through the status field.
$conditions = $query
->createConditionGroup('AND');
$conditions
->addCondition('user_status', 0, '<>');
// Add the conditions.
$query
->addConditionGroup($conditions);
}
}
}
Classes
Name | Description |
---|---|
BlockedUsers | Ignores blocked users in index and queries. |