-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from openeuropa/EWPP-837
EWPP-837: Refactoring the default filter values and results processing.
- Loading branch information
Showing
34 changed files
with
925 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
modules/oe_list_pages_link_list_source/src/ContextualAwareProcessorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_list_pages_link_list_source; | ||
|
||
use Drupal\Core\Entity\ContentEntityInterface; | ||
|
||
/** | ||
* Interface to indicate a search API processor is aware of contextual filters. | ||
* | ||
* This allows the processor plugins that index custom values into the index | ||
* also provide corresponding values from an entity from context. | ||
*/ | ||
interface ContextualAwareProcessorInterface { | ||
|
||
/** | ||
* Given an entity, return contextual filter values. | ||
* | ||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity | ||
* The entity. | ||
* | ||
* @return array | ||
* The filter values. | ||
*/ | ||
public function getContextualValues(ContentEntityInterface $entity): array; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
modules/oe_list_pages_link_list_source/src/ContextualFiltersHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_list_pages_link_list_source; | ||
|
||
use Drupal\facets\FacetInterface; | ||
use Drupal\oe_list_pages\ListSourceInterface; | ||
use Drupal\search_api\Processor\ProcessorInterface; | ||
|
||
/** | ||
* Helper class for the contextual filters logic. | ||
*/ | ||
class ContextualFiltersHelper { | ||
|
||
/** | ||
* Returns the search API processor that is contextual filters aware. | ||
* | ||
* @param \Drupal\oe_list_pages\ListSourceInterface $list_source | ||
* The list source. | ||
* @param \Drupal\facets\FacetInterface $facet | ||
* The facet for which to determine the plugin. | ||
* | ||
* @return \Drupal\oe_list_pages_link_list_source\ContextualAwareProcessorInterface|null | ||
* The processor if found. | ||
*/ | ||
public static function getContextualAwareSearchApiProcessor(ListSourceInterface $list_source, FacetInterface $facet): ?ContextualAwareProcessorInterface { | ||
$processor = static::getSearchApiFieldProcessor($list_source, $facet); | ||
if ($processor instanceof ContextualAwareProcessorInterface) { | ||
return $processor; | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
/** | ||
* Returns the custom Search API field processor this facet is based on. | ||
* | ||
* @param \Drupal\oe_list_pages\ListSourceInterface $list_source | ||
* The list source. | ||
* @param \Drupal\facets\FacetInterface $facet | ||
* The facet. | ||
* | ||
* @return \Drupal\search_api\Processor\ProcessorInterface|null | ||
* The processor if found, NULL otherwise. | ||
*/ | ||
public static function getSearchApiFieldProcessor(ListSourceInterface $list_source, FacetInterface $facet): ?ProcessorInterface { | ||
$property_path = $list_source->getIndex()->getField($facet->getFieldIdentifier())->getPropertyPath(); | ||
$processors = $list_source->getIndex()->getProcessorsByStage(ProcessorInterface::STAGE_ADD_PROPERTIES); | ||
foreach ($processors as $processor) { | ||
$properties = $processor->getPropertyDefinitions(); | ||
if (isset($properties[$property_path])) { | ||
return $processor; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.