Browse Source

remove deprecated entity query

d9_islandora
Eli Zoller 4 years ago
parent
commit
2b726b9446
  1. 4
      islandora.services.yml
  2. 32
      src/IslandoraUtils.php
  3. 14
      src/MediaSource/MediaSourceService.php

4
islandora.services.yml

@ -48,10 +48,10 @@ services:
- { name: 'context_provider' }
islandora.media_source_service:
class: Drupal\islandora\MediaSource\MediaSourceService
arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@entity.query', '@file_system', '@islandora.utils']
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', '@entity.query', '@context.manager', '@flysystem_factory', '@language_manager']
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager']
islandora.gemini.client:
class: Islandora\Crayfish\Commons\Client\GeminiClient
factory: ['Drupal\islandora\GeminiClientFactory', create]

32
src/IslandoraUtils.php

@ -8,7 +8,6 @@ use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Site\Settings;
@ -48,13 +47,6 @@ class IslandoraUtils {
*/
protected $entityFieldManager;
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* Context manager.
*
@ -83,8 +75,6 @@ class IslandoraUtils {
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* Entity query.
* @param \Drupal\context\ContextManager $context_manager
* Context manager.
* @param \Drupal\flysystem\FlysystemFactory $flysystem_factory
@ -95,14 +85,12 @@ class IslandoraUtils {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
EntityFieldManagerInterface $entity_field_manager,
QueryFactory $entity_query,
ContextManager $context_manager,
FlysystemFactory $flysystem_factory,
LanguageManagerInterface $language_manager
) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
$this->entityQuery = $entity_query;
$this->contextManager = $context_manager;
$this->flysystemFactory = $flysystem_factory;
$this->languageManager = $language_manager;
@ -157,7 +145,7 @@ class IslandoraUtils {
->load('media.' . self::MEDIA_OF_FIELD)) {
return [];
}
$mids = $this->entityQuery->get('media')
$mids = $this->entityTypeManager->getStorage('media')->getQuery()
->condition(self::MEDIA_OF_FIELD, $node->id())
->execute();
if (empty($mids)) {
@ -217,10 +205,12 @@ class IslandoraUtils {
);
// Query for media that reference this file.
$query = $this->entityQuery->get('media', 'OR');
$query = $this->entityTypeManager->getStorage('media')->getQuery();
$group = $query->orConditionGroup();
foreach ($conditions as $condition) {
$query->condition($condition, $fid);
$group->condition($condition, $fid);
}
$query->condition($group);
return $this->entityTypeManager->getStorage('media')
->loadMultiple($query->execute());
@ -252,7 +242,7 @@ class IslandoraUtils {
// Add field_external_uri.
$fields[] = self::EXTERNAL_URI_FIELD;
$query = $this->entityQuery->get('taxonomy_term');
$query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery();
$orGroup = $query->orConditionGroup();
foreach ($fields as $field) {
@ -504,7 +494,7 @@ class IslandoraUtils {
array_walk($term_fields, $remove_entity);
array_walk($node_fields, $remove_entity);
$query = $this->entityQuery->get('media');
$query = $this->entityTypeManager->getStorage('media')->getQuery();
$taxon_condition = $this->getEntityQueryOrCondition($query, $term_fields, $term->id());
$query->condition($taxon_condition);
$node_condition = $this->getEntityQueryOrCondition($query, $node_fields, $node->id());
@ -531,7 +521,7 @@ class IslandoraUtils {
* Array of fields.
*/
public function getReferencingFields($entity_type, $target_type) {
$fields = $this->entityQuery->get('field_storage_config')
$fields = $this->entityTypeManager->getStorage('field_storage_config')->getQuery()
->condition('entity_type', $entity_type)
->condition('settings.target_type', $target_type)
->execute();
@ -593,11 +583,7 @@ class IslandoraUtils {
* The file URL.
*/
public function getDownloadUrl(FileInterface $file) {
$undefined = $this->languageManager->getLanguage('und');
return $file->url('canonical', [
'absolute' => TRUE,
'language' => $undefined,
]);
return $file->createFileUrl(FALSE);
}
/**

14
src/MediaSource/MediaSourceService.php

@ -3,7 +3,6 @@
namespace Drupal\islandora\MediaSource;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
@ -43,13 +42,6 @@ class MediaSourceService {
*/
protected $languageManager;
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* File system service.
*
@ -73,8 +65,6 @@ class MediaSourceService {
* The current user.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* Entity query.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* File system service.
* @param \Drupal\islandora\IslandoraUtils $islandora_utils
@ -84,14 +74,12 @@ class MediaSourceService {
EntityTypeManagerInterface $entity_type_manager,
AccountInterface $account,
LanguageManagerInterface $language_manager,
QueryFactory $entity_query,
FileSystemInterface $file_system,
IslandoraUtils $islandora_utils
) {
$this->entityTypeManager = $entity_type_manager;
$this->account = $account;
$this->languageManager = $language_manager;
$this->entityQuery = $entity_query;
$this->fileSystem = $file_system;
$this->islandoraUtils = $islandora_utils;
}
@ -293,7 +281,7 @@ class MediaSourceService {
}
$directory = $this->fileSystem->dirname($content_location);
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable");
}

Loading…
Cancel
Save