Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions config/install/islandora.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ broker_url: 'tcp://localhost:61613'
jwt_expiry: '+2 hour'
delete_media_and_files: TRUE
gemini_pseudo_bundles: []
fast_term_queries: TRUE
3 changes: 3 additions & 0 deletions config/schema/islandora.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ islandora.settings:
delete_media_and_files:
type: boolean
label: 'Node Delete with Media and Files'
fast_term_queries:
type: boolean
label: 'Use multiple queries for term URI lookups'
redirect_after_media_save:
type: boolean
label: 'Redirect to node after media save.'
Expand Down
10 changes: 10 additions & 0 deletions islandora.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ function islandora_post_update_delete_media_and_files() {
$config->set('delete_media_and_files', TRUE);
$config->save(TRUE);
}

/**
* Ensure `fast_term_queries` exists.
*/
function islandora_post_update_fast_term_queries() : void {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('islandora.settings');
$config->set('fast_term_queries', TRUE);
$config->save(TRUE);
}
2 changes: 1 addition & 1 deletion islandora.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ services:
arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@file_system', '@islandora.utils']
islandora.utils:
class: Drupal\islandora\IslandoraUtils
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager', '@current_user']
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager', '@current_user', '@config.factory']
islandora.entity_mapper:
class: Islandora\EntityMapper\EntityMapper
islandora.stomp.auth_header_listener:
Expand Down
11 changes: 10 additions & 1 deletion src/Form/IslandoraSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
const GEMINI_PSEUDO_FIELD = 'field_gemini_uri';
const NODE_DELETE_MEDIA_AND_FILES = 'delete_media_and_files';
const REDIRECT_AFTER_MEDIA_SAVE = 'redirect_after_media_save';
const FAST_TERM_QUERIES = 'fast_term_queries';

/**
* To list the available bundle types.
Expand Down Expand Up @@ -79,7 +80,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
public function __construct(
ConfigFactoryInterface $config_factory,
EntityTypeBundleInfoInterface $entity_type_bundle_info,
EntityTypeManagerInterface $entity_type_manager
EntityTypeManagerInterface $entity_type_manager,
) {
$this->setConfigFactory($config_factory);
$this->entityTypeBundleInfo = $entity_type_bundle_info;
Expand Down Expand Up @@ -228,6 +229,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => (bool) $config->get(self::REDIRECT_AFTER_MEDIA_SAVE),
];

$form[self::FAST_TERM_QUERIES] = [
'#type' => 'checkbox',
'#title' => $this->t('Use multiple queries for term URI lookups.'),
'#description' => $this->t('Using multiple queries to look up taxonomy terms by URI is faster in most setups. You may want to disable this if you have a term access protection module enabled.'),
'#default_value' => (bool) $config->get(self::FAST_TERM_QUERIES),
];

$form[self::FEDORA_URL] = [
'#type' => 'textfield',
'#title' => $this->t('Fedora URL'),
Expand Down Expand Up @@ -383,6 +391,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->set(self::UPLOAD_FORM_ALLOWED_MIMETYPES, $form_state->getValue(self::UPLOAD_FORM_ALLOWED_MIMETYPES))
->set(self::GEMINI_PSEUDO, $new_pseudo_types)
->set(self::NODE_DELETE_MEDIA_AND_FILES, $form_state->getValue(self::NODE_DELETE_MEDIA_AND_FILES))
->set(self::FAST_TERM_QUERIES, $form_state->getValue(self::FAST_TERM_QUERIES))
->set(self::REDIRECT_AFTER_MEDIA_SAVE, $form_state->getValue(self::REDIRECT_AFTER_MEDIA_SAVE))
->save();

Expand Down
31 changes: 30 additions & 1 deletion src/IslandoraUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Drupal\media\MediaInterface;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\islandora\Form\IslandoraSettingsForm;
use Drupal\Core\Config\ConfigFactoryInterface;

/**
* Utility functions for figuring out when to fire derivative reactions.
Expand Down Expand Up @@ -81,6 +83,13 @@ class IslandoraUtils {
*/
protected AccountInterface $currentUser;

/**
* Islandora config settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $islandoraSettings;

/**
* Constructor.
*
Expand All @@ -96,21 +105,25 @@ class IslandoraUtils {
* Language manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* Config factory.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
EntityFieldManagerInterface $entity_field_manager,
ContextManager $context_manager,
FlysystemFactory $flysystem_factory,
LanguageManagerInterface $language_manager,
AccountInterface $current_user
AccountInterface $current_user,
ConfigFactoryInterface $config,
) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
$this->contextManager = $context_manager;
$this->flysystemFactory = $flysystem_factory;
$this->languageManager = $language_manager;
$this->currentUser = $current_user;
$this->islandoraSettings = $config->get(IslandoraSettingsForm::CONFIG_NAME);
}

/**
Expand Down Expand Up @@ -261,6 +274,22 @@ public function getTermForUri($uri) {
// Add field_external_uri.
$fields[] = self::EXTERNAL_URI_FIELD;

if ($this->islandoraSettings->get(IslandoraSettingsForm::FAST_TERM_QUERIES)) {
$storage = $this->entityTypeManager->getStorage('taxonomy_term');
foreach ($fields as $field) {
$query = $storage->getQuery();
$results = $query
->accessCheck(TRUE)
->condition("$field.uri", $uri)
->execute();
if (!empty($results)) {
return $storage->load(reset($results));
}
}

return NULL;
}

$query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery();

$orGroup = $query->orConditionGroup();
Expand Down
Loading