Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PER-60 / PER-61: Result filtering #32

Merged
merged 22 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
163a8b4
Merge pull request #2 from discoverygarden/main
Prashant-bd Feb 2, 2024
b6219fe
DGIR-150 : Processor to add data in indexing
Prashant-bd Feb 2, 2024
df8d212
DGIR-150 : Processor to add data in indexing
Prashant-bd Feb 2, 2024
6d06aa3
DGIR-150 : Comment changes
Prashant-bd Feb 2, 2024
18a5661
Rework to add ALL the info.
adam-vessey Feb 27, 2024
5854a93
Theoretical query filtering.
adam-vessey Feb 28, 2024
bc7ee8c
Move to the appropriate directory for the namespace.
adam-vessey Feb 28, 2024
8c485e7
Largely functional.
adam-vessey Feb 29, 2024
0ac3d69
Misc coding standards.
adam-vessey Feb 29, 2024
debe947
Coding standards.
adam-vessey Feb 29, 2024
b5f9ffa
Fix test erroring.
adam-vessey Feb 29, 2024
69a2df3
Rework to differently relate the embargoes to the affected entities.
adam-vessey Mar 1, 2024
883fba3
Avoid letting scheduled embargoes through if there are indefinite.
adam-vessey Mar 4, 2024
a4a8d3e
Coding standards.
adam-vessey Mar 4, 2024
01b77bb
Attempt rolling additional tracking.
adam-vessey Mar 4, 2024
a82bdbb
Roll in additional entity tracking.
adam-vessey Mar 4, 2024
1c371d7
Fix up logic, move comments around.
adam-vessey Mar 4, 2024
15b901b
Don't strictly need to pass the first offset.
adam-vessey Mar 4, 2024
12ba90e
Start thinking to roll in more cache headers; however, shouldn't be n…
adam-vessey Mar 4, 2024
80d5b99
More cache info.
adam-vessey Mar 4, 2024
92b4b05
Additional cache tag dealio.
adam-vessey Mar 4, 2024
3477650
Back over to property, instead of a calculated field.
adam-vessey Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions embargo.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\embargo\EmbargoInterface;
use Drupal\embargo\EmbargoStorage;
use Drupal\islandora_hierarchical_access\LUTGeneratorInterface;

/**
* Implements hook_entity_type_alter().
Expand Down Expand Up @@ -97,3 +100,77 @@ function embargo_theme($existing, $type, $theme, $path) {
],
];
}

/**
* Implements hook_ENTITY_TYPE_insert() for embargo entities.
*/
function embargo_embargo_insert(EntityInterface $entity) : void {
_embargo_search_api_track($entity);
}

/**
* Implements hook_ENTITY_TYPE_update() for embargo entities.
*/
function embargo_embargo_update(EntityInterface $entity) : void {
_embargo_search_api_track($entity);
}

/**
* Implements hook_ENTITY_TYPE_delete() for embargo entities.
*/
function embargo_embargo_delete(EntityInterface $entity) : void {
_embargo_search_api_track($entity);
}

/**
* Helper; deal with updating indexes of related items.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The embargo instance.
*/
function _embargo_search_api_track(EntityInterface $entity) : void {
assert($entity instanceof EmbargoInterface);
if (!\Drupal::moduleHandler()->moduleExists('search_api')) {
return;
}

// On updates, deal with the original value, in addition to the new.
if (isset($entity->original)) {
_embargo_search_api_track($entity->original);
}

if (!($node = $entity->getEmbargoedNode())) {
// No embargoed node?
return;
}

/** @var \Drupal\search_api\Plugin\search_api\datasource\ContentEntityTrackingManager $tracking_manager */
$tracking_manager = \Drupal::getContainer()->get('search_api.entity_datasource.tracking_manager');
/** @var \Drupal\search_api\Utility\TrackingHelperInterface $tracking_helper */
$tracking_helper = \Drupal::getContainer()->get('search_api.tracking_helper');

$track = function (ContentEntityInterface $entity) use ($tracking_manager, $tracking_helper) {
$tracking_manager->trackEntityChange($entity);
$tracking_helper->trackReferencedEntityUpdate($entity);
};

$track($node);

$results = \Drupal::database()->select(LUTGeneratorInterface::TABLE_NAME, 'lut')
->fields('lut', ['mid', 'fid'])
->condition('nid', $node->id())
->execute();
$media_ids = array_unique($results->fetchCol(/* 0 */));
$file_ids = array_unique($results->fetchCol(1));

$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Drupal\media\MediaInterface $media */
foreach ($entity_type_manager->getStorage('media')->loadMultiple($media_ids) as $media) {
$track($media);
}
/** @var \Drupal\file\FileInterface $file */
foreach ($entity_type_manager->getStorage('file')->loadMultiple($file_ids) as $file) {
$track($file);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Drupal\migrate_embargoes_to_embargo\Plugin\migrate\source;

use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate\Plugin\MigrationInterface;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;

use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down
44 changes: 44 additions & 0 deletions src/EmbargoItemList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Drupal\embargo;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;

/**
* Track embargo items.
*/
class EmbargoItemList extends EntityReferenceFieldItemList {

use ComputedItemListTrait;

/**
* {@inheritDoc}
*/
protected function computeValue() {
$entity = $this->getEntity();
/** @var \Drupal\embargo\EmbargoStorageInterface $embargo_storage */
$embargo_storage = $this->getEntityTypeManager()->getStorage('embargo');
$this->setValue(array_filter($embargo_storage->getApplicableEmbargoes($entity), function (EmbargoInterface $embargo) {
return in_array($embargo->getEmbargoType(), $this->getSetting('embargo_types'));
}));
}

/**
* Helper; get the entity type manager service.
*
* XXX: Dependency injection does not presently appear to be possible in typed
* data.
*
* @see https://www.drupal.org/node/2053415
* @see https://www.drupal.org/project/drupal/issues/3294266
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager service.
*/
protected function getEntityTypeManager() : EntityTypeManagerInterface {
return \Drupal::entityTypeManager();
}

}
Loading
Loading