Skip to content

Commit

Permalink
DataFavorites #827
Browse files Browse the repository at this point in the history
dependency injection fix
  • Loading branch information
protitude committed Feb 3, 2025
1 parent bcc8493 commit 142bccd
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/Plugin/search_api/processor/DataFavorites.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api\Processor\ProcessorProperty;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\flag\FlagServiceInterface;

/**
* Search API Processor for indexing data reports favorites.
Expand All @@ -23,6 +25,42 @@
*/
class DataFavorites extends ProcessorPluginBase {

/**
* The flag service.
*
* @var \Drupal\flag\FlagServiceInterface
*/
protected $flagService;

/**
* Constructs a DataFavorites object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\flag\FlagServiceInterface $flag_service
* The flag service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, FlagServiceInterface $flag_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->flagService = $flag_service;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('flag')
);
}

/**
* {@inheritdoc}
*/
Expand All @@ -48,7 +86,7 @@ public function getPropertyDefinitions(?DatasourceInterface $datasource = NULL)
public function addFieldValues(ItemInterface $item) {
$entity = $item->getOriginalObject()->getValue();

$flag = \Drupal::service('flag')->getFlaggingUsers($entity);
$flag = $this->flagService->getFlaggingUsers($entity);

$flag_uids = array_keys($flag);

Expand Down

0 comments on commit 142bccd

Please sign in to comment.