Skip to content

Commit 10d6deb

Browse files
author
Mateu Aguiló Bosch
committed
[BUGFIX] Re-add links to individual items in listings
Add self link to every individual item in a listing.
1 parent a7b6175 commit 10d6deb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Plugin/formatter/FormatterJsonApi.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Drupal\restful\Plugin\formatter;
99

10+
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
1011
use Drupal\restful\Exception\BadRequestException;
1112
use Drupal\restful\Exception\InternalServerErrorException;
1213
use Drupal\restful\Exception\ServerConfigurationException;
@@ -146,6 +147,13 @@ protected function extractFieldValues($data, array $parents = array(), array $pa
146147
// In some situations when making an OPTIONS call the $resource_id
147148
// returns the array of discovery information instead of a real value.
148149
$output['#resource_id'] = (string) $resource_id;
150+
try {
151+
$output['#links']['self'] = restful()
152+
->getResourceManager()
153+
->getPlugin($output['#resource_plugin'])
154+
->versionedUrl($output['#resource_id']);
155+
}
156+
catch(PluginNotFoundException $e) {}
149157
}
150158
}
151159
if ($this->isCacheEnabled($data)) {
@@ -343,6 +351,10 @@ protected function renormalize(array $output, array &$included, $allowed_fields
343351
}
344352
}
345353
}
354+
// Set the links for every item.
355+
if (!empty($output['#links'])) {
356+
$result['links'] = $output['#links'];
357+
}
346358

347359
// Decrease the depth level.
348360
$depth--;

0 commit comments

Comments
 (0)