Skip to content
Snippets Groups Projects

Resolve "Add label/name all entities in the API results"

5 files
+ 183
10
Compare changes
  • Side-by-side
  • Inline

Files

@@ -12,11 +12,27 @@
*/
class RadarServicesEntityResourceController extends ServicesEntityResourceControllerClean {
/**
* Extends ServicesResourceControllerInterface::access().
*
* Default services access does not load by UUID.
*/
protected $apiVersion = '';
/**
* Set API version.
*/
public function setApiVersion($version) {
$this->apiVersion = $version;
}
/**
* Get API version.
*/
public function getApiVersion() {
return $this->apiVersion;
}
/**
* Extends ServicesResourceControllerInterface::access().
*
* Default services access does not load by UUID.
*/
public function access($op, $args) {
if ($op == 'index') {
// Access is handled per-entity by index().
@@ -177,6 +193,21 @@ class RadarServicesEntityResourceController extends ServicesEntityResourceContro
// For referenced entities only return the URI.
if ($id = $property->getIdentifier()) {
$data[$name] = $this->get_resource_reference($property->type(), $id);
if (version_compare($this->getApiVersion(), '1.2', '>=')) {
// So in common with some of our other errors the entity won't load
// here as it's a UUID. Replacing the entity controller would
// probably do it? For now fix the issue at hand.
$entity_info = entity_get_info($property->type());
$entities = entity_uuid_load($property->type(), [$id]);
$entity_label = empty($entity_info['entity keys']['label']) ? 'label' : $entity_info['entity keys']['label'];
if (!empty($entities)) {
$entity = reset($entities);
$data[$name][$entity_label] = entity_label($property->type(), $entity);
}
else {
$data[$name][$entity_label] = '';
}
}
}
}
elseif ($property instanceof EntityValueWrapper) {
Loading