SuperUser.php in Open Social 8.5
Same filename and directory in other branches
- 8.9 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.2 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.3 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.4 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.6 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.7 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 8.8 modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 10.3.x modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 10.0.x modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 10.1.x modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
- 10.2.x modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.php
File
modules/social_features/social_search/src/Plugin/search_api/processor/SuperUser.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;
/**
* Adds access checks for profiles.
*
* @SearchApiProcessor(
* id = "super_user",
* label = @Translation("Skip User 1"),
* description = @Translation("Makes sure that user 1 is not added to the index."),
* stages = {
* "alter_items" = 0,
* },
* )
*/
class SuperUser extends ProcessorPluginBase {
/**
* {@inheritdoc}
*/
public static function supportsIndex(IndexInterface $index) {
$supported_entity_types = [
'profile',
];
foreach ($index
->getDatasources() as $datasource) {
if (in_array($datasource
->getEntityTypeId(), $supported_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
->getOwnerId() == '1') {
unset($items[$item_id]);
}
}
elseif ($object instanceof UserInterface) {
if ($object
->id() == '1') {
unset($items[$item_id]);
}
}
}
}
}