|
|
@ -235,12 +235,32 @@ class IslandoraUtils { |
|
|
|
* Calling getStorage() throws if the storage handler couldn't be loaded. |
|
|
|
* Calling getStorage() throws if the storage handler couldn't be loaded. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function getTermForUri($uri) { |
|
|
|
public function getTermForUri($uri) { |
|
|
|
$results = $this->entityQuery->get('taxonomy_term') |
|
|
|
// Get authority link fields to search. |
|
|
|
->condition(self::EXTERNAL_URI_FIELD . '.uri', $uri) |
|
|
|
$field_map = $this->entityFieldManager->getFieldMap(); |
|
|
|
|
|
|
|
$fields = []; |
|
|
|
|
|
|
|
foreach ($field_map['taxonomy_term'] as $field_name => $field_data) { |
|
|
|
|
|
|
|
if ($field_data['type'] == 'authority_link') { |
|
|
|
|
|
|
|
$fields[] = $field_name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add field_external_uri. |
|
|
|
|
|
|
|
$fields[] = self::EXTERNAL_URI_FIELD; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query = $this->entityQuery->get('taxonomy_term'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$orGroup = $query->orConditionGroup(); |
|
|
|
|
|
|
|
foreach ($fields as $field) { |
|
|
|
|
|
|
|
$orGroup->condition("$field.uri", $uri); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$results = $query |
|
|
|
|
|
|
|
->condition($orGroup) |
|
|
|
->execute(); |
|
|
|
->execute(); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($results)) { |
|
|
|
if (empty($results)) { |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $this->entityTypeManager->getStorage('taxonomy_term')->load(reset($results)); |
|
|
|
return $this->entityTypeManager->getStorage('taxonomy_term')->load(reset($results)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -258,16 +278,33 @@ class IslandoraUtils { |
|
|
|
* be created. |
|
|
|
* be created. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function getUriForTerm(TermInterface $term) { |
|
|
|
public function getUriForTerm(TermInterface $term) { |
|
|
|
if ($term && $term->hasField(self::EXTERNAL_URI_FIELD)) { |
|
|
|
$fields = $this->getUriFieldNamesForTerms(); |
|
|
|
$field = $term->get(self::EXTERNAL_URI_FIELD); |
|
|
|
foreach ($fields as $field_name) { |
|
|
|
if (!$field->isEmpty()) { |
|
|
|
if ($term && $term->hasField($field_name)) { |
|
|
|
$link = $field->first()->getValue(); |
|
|
|
$field = $term->get($field_name); |
|
|
|
return $link['uri']; |
|
|
|
if (!$field->isEmpty()) { |
|
|
|
|
|
|
|
$link = $field->first()->getValue(); |
|
|
|
|
|
|
|
return $link['uri']; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getUriFieldNamesForTerms() { |
|
|
|
|
|
|
|
// Get authority link fields to search. |
|
|
|
|
|
|
|
$field_map = $this->entityFieldManager->getFieldMap(); |
|
|
|
|
|
|
|
$fields = []; |
|
|
|
|
|
|
|
foreach ($field_map['taxonomy_term'] as $field_name => $field_data) { |
|
|
|
|
|
|
|
if ($field_data['type'] == 'authority_link') { |
|
|
|
|
|
|
|
$fields[] = $field_name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add field_external_uri. |
|
|
|
|
|
|
|
$fields[] = self::EXTERNAL_URI_FIELD; |
|
|
|
|
|
|
|
return $fields; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Executes context reactions for a Node. |
|
|
|
* Executes context reactions for a Node. |
|
|
|
* |
|
|
|
* |
|
|
|