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