From b6219fee4b195f2af320726f56ed7770ca802606 Mon Sep 17 00:00:00 2001 From: Prashant Kanse Date: Fri, 2 Feb 2024 20:46:59 +0530 Subject: [PATCH 1/3] DGIR-150 : Processor to add data in indexing --- src/Plugin/search_api/.DS_Store | Bin 0 -> 6148 bytes .../search_api/processor/EmbargoProcessor.php | 133 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/Plugin/search_api/.DS_Store create mode 100644 src/Plugin/search_api/processor/EmbargoProcessor.php diff --git a/src/Plugin/search_api/.DS_Store b/src/Plugin/search_api/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b6d378b133c81f9be12f995d5e059ee8ddd4090c GIT binary patch literal 6148 zcmeHKI}XAy47Gs)#L|&5SKtN_f*pwqAU+#XB@lZj&c)Gq{tTeP1`B$woR>I$srrVv z77<-s4|9=5M81IC@mTFzkYpZWXKu5C}Y zO``%-fC^9nDnJFks6ZCi@$`#l@+c}m1^z<;yB`YNuqJkaesy5*763Rx*bQ^pyTG7}X7i!>X3Y*o{p~ovc)Dl}i80h5~3oFMnPl~)^ YbL`i|F3{#>1%9o-1B6}`tpET3 literal 0 HcmV?d00001 diff --git a/src/Plugin/search_api/processor/EmbargoProcessor.php b/src/Plugin/search_api/processor/EmbargoProcessor.php new file mode 100644 index 0000000..7e6862b --- /dev/null +++ b/src/Plugin/search_api/processor/EmbargoProcessor.php @@ -0,0 +1,133 @@ +entityTypeManager = $entity_type_manager; + $this->storage = $entity_type_manager->getStorage('embargo'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) { + $properties = []; + + if ($datasource) { + $definition = [ + 'label' => $this->t('Embargo Status'), + 'description' => $this->t('Field to pass embargo status to solr index.'), + 'type' => 'string', + 'processor_id' => $this->getPluginId(), + 'is_list' => TRUE, + ]; + $properties['embargo_status'] = new CustomValueProperty($definition); + } + + return $properties; + } + + /** + * {@inheritdoc} + */ + public function addFieldValues(ItemInterface $item) { + $embargo_expiration_type = $embargo_type = []; + + // Get node ID. + $item_id = $item->getId(); + $nodeId = preg_replace('/^entity:node\/(\d+):en$/', '$1', $item_id); + + // Load node based on ID, and get embargo. + $node = $this->entityTypeManager->getStorage('node')->load($nodeId); + $storages = $this->storage->getApplicableEmbargoes($node); + + if (empty($storages)) { + return; + } + + // Get Embargo details and prepare to pass it to index field. + foreach ($storages as $embargo) { + $allowed_expiration_types = EmbargoInterface::EXPIRATION_TYPES; + $allowed_embargo_type = EmbargoInterface::EMBARGO_TYPES; + // Get Embargo Type. + $embargo_type[] = 'embargo-type-' . $allowed_embargo_type[$embargo->getEmbargoType()]; + + // Get Expiration Type. + $embargo_expiration_type[] = 'embargo-expiration-type-' . $allowed_expiration_types[$embargo->getExpirationType()]; + } + + $embargo_status = $combinedString = implode(' ', $embargo_type) . ' ' . implode(' ', $embargo_expiration_type); + + $fields = $this->getFieldsHelper() + ->filterForPropertyPath($item->getFields(), $item->getDatasourceId(), 'embargo_status'); + foreach ($fields as $field) { + $field->addValue($embargo_status); + } + } + +} From df8d21218818e43f29cdde44b2ca65124b577396 Mon Sep 17 00:00:00 2001 From: Prashant Kanse Date: Fri, 2 Feb 2024 20:47:45 +0530 Subject: [PATCH 2/3] DGIR-150 : Processor to add data in indexing --- src/Plugin/search_api/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/Plugin/search_api/.DS_Store diff --git a/src/Plugin/search_api/.DS_Store b/src/Plugin/search_api/.DS_Store deleted file mode 100644 index b6d378b133c81f9be12f995d5e059ee8ddd4090c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKI}XAy47Gs)#L|&5SKtN_f*pwqAU+#XB@lZj&c)Gq{tTeP1`B$woR>I$srrVv z77<-s4|9=5M81IC@mTFzkYpZWXKu5C}Y zO``%-fC^9nDnJFks6ZCi@$`#l@+c}m1^z<;yB`YNuqJkaesy5*763Rx*bQ^pyTG7}X7i!>X3Y*o{p~ovc)Dl}i80h5~3oFMnPl~)^ YbL`i|F3{#>1%9o-1B6}`tpET3 From 6d06aa3b80e767662317d0b5c223cc8c8280010b Mon Sep 17 00:00:00 2001 From: Prashant Kanse Date: Fri, 2 Feb 2024 20:50:48 +0530 Subject: [PATCH 3/3] DGIR-150 : Comment changes --- src/Plugin/search_api/processor/EmbargoProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/search_api/processor/EmbargoProcessor.php b/src/Plugin/search_api/processor/EmbargoProcessor.php index 7e6862b..ad07ce2 100644 --- a/src/Plugin/search_api/processor/EmbargoProcessor.php +++ b/src/Plugin/search_api/processor/EmbargoProcessor.php @@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * A search_api_solr processor to filter results based on embargo and user IP. + * A search_api_solr processor to add embargo related info. * * @SearchApiProcessor( * id = "embargo_processor",