|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|