|
|
|
@ -19,50 +19,28 @@ namespace Drupal\islandora\ParamConverter;
|
|
|
|
|
use Drupal\Core\ParamConverter\EntityConverter; |
|
|
|
|
use Drupal\Core\ParamConverter\ParamConverterInterface; |
|
|
|
|
use Drupal\Component\Uuid\Uuid; |
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
|
|
|
use Symfony\Component\Routing\Route; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converts an UUID param (route) into an Entity. |
|
|
|
|
* |
|
|
|
|
* @ingroup islandora |
|
|
|
|
*/ |
|
|
|
|
class UuidEntityConverter extends EntityConverter implements ParamConverterInterface { |
|
|
|
|
class UuidEntityConverter extends EntityConverter { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @inheritDoc |
|
|
|
|
*/ |
|
|
|
|
public function convert($value, $definition, $name, array $defaults) { |
|
|
|
|
|
|
|
|
|
$entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); |
|
|
|
|
if ($storage = $this->entityManager->getStorage($entity_type_id)) { |
|
|
|
|
|
|
|
|
|
// Try to load fedora entity by UUID or ID depending on $value. |
|
|
|
|
if (!(is_int($value) || ctype_digit((string) $value)) && Uuid::isValid($value)) { |
|
|
|
|
$entities = $storage->loadByProperties(['uuid' => $value]); |
|
|
|
|
$entity = ($entities) ? reset($entities) : NULL; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$entity = parent::convert($value, $definition, $name, $defaults); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $entity; |
|
|
|
|
return $this->entityManager->loadEntityByUuid($name, $value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @inheritDoc |
|
|
|
|
*/ |
|
|
|
|
public function applies($definition, $name, Route $route) { |
|
|
|
|
/*if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) { |
|
|
|
|
$entity_type_id = substr($definition['type'], strlen('entity:')); |
|
|
|
|
if (strpos($definition['type'], '{') !== FALSE) { |
|
|
|
|
$entity_type_slug = substr($entity_type_id, 1, -1); |
|
|
|
|
return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE); |
|
|
|
|
} |
|
|
|
|
return $this->entityManager->hasDefinition($entity_type_id); |
|
|
|
|
} |
|
|
|
|
return FALSE;*/ |
|
|
|
|
|
|
|
|
|
return parent::applies($definition, $name, $route); // TODO: Change the autogenerated stub |
|
|
|
|
return (!empty($definition['type']) && $definition['type'] == 'uuid'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|