-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose parent collection as link header #680
Comments
So it looks like we need to find a new way to add this header. |
Oops sorry, forget that. It has been made part of core. So hook_node_view_alter is still valid. |
@whikloj
|
@Natkeeran Looking good, you should probably add a check to ensure the thing you are linking to is of the bundle Last thing, is in your snippet it appears that the collection URI doesn't have < and > around it and instead has an arrow ->?? Is that just Github messing with your comment? |
@Natkeeran I wouldn't restrict based on the number of entities in field_hasmember and just iterate over all of them, adding a link header for each. Then when we open up to having multiple collection memberships we shouldn't have to touch up this code. |
@whikloj @dannylamb
One issue I did run into is that while my FF debug provides the added links as below, I could not that get the added links with POSTMAN. I was able to get that before. Not sure what changed!
|
Yes this will cost us, but that is just how it has to be. Also we can expand this loop to account for additional relationships if we so desire.
or if you should be doing
I'm not good with these syntax diagrams, https://tools.ietf.org/html/rfc5988#section-5 |
@whikloj The second. It should be separate header values per link. |
And yeah... all these checks are going to cost us. But I think it's worth doing and then seeing if it actually becomes an issue. Loading two extra entities? That's probably fine. Ten entities? We'll see. A hundred entities? That'll probably be a problem. |
@Natkeeran Feel free to make a PR at any time. And maybe Postman is caching? If you can get it with cURL, then you know it's working. You can make a HEAD request with |
@Natkeeran should be in @whikloj's later form:
The operation to get this can be a bit expensive and not sure if in tune with how the rest of drupal 8 environment does the render array stuff, kinda feel we need to look at There are over 62 implementations so plenty of examples, but mostly it's a way of adding your own What i found so far in case someone could find this uselful: https://www.drupal.org/docs/8/api/render-api/bubbleable-metadata Filters can also make use of bubbleable-metadata So maybe, doing the following mix? Lastly, question about that implementation, is $build['#attached']['http_header'] = ... Not overwriting existing, possibly added by other modules or core, headers? Not sure. |
@DiegoPino I took your post as an opportunity to investigate the interplay between adding link headers and D8 render array caching, and it looks like we're in the clear. The alter won't run unless the cache is invalidated, and D8 core has already set that up appropriately. Any time the underlying node is edited, the render array (along with our headers) is regenerated. This operation will not run on every page load, and it will also not serve a stale link header in case someone edits And yes, I find the @Natkeeran Please feel free to issue a PR with what you have. You shouldn't have to do anything extra w/r/t caching. |
I'll create a PR. There is a minor difference with respect to how the Links get displayed in CURL vs FF.
FF
Method
|
@Natkeeran could you accumulate this count($entity->get('field_memberof')->getValue()) into a temporary var and reuse it? Instead of if ($entity->hasField('field_memberof') == false || count($entity->get('field_memberof')->getValue()) == 0) {
return;
} and then later again maybe it is my environment, which is pretty much on debug mode, but i get twice the same entity field query in your code which makes the alter hook a bit more expensive. By calling $collection_members = $entity->get('field_memberof')->getValue() only once, and reusing the value in the conditional (for counting) and then later for iterating (at least here) i get one SQL query (which joins a few tables!) less. Just if possible of course, if you don´t see that behavior just discard my message. Good work, Thanks! |
@Natkeeran Not sure what the difference between cURL and FF is other than FF aggregates all the link headers. That's nothing to worry about. And heads up, looks like you're missing the ';' between the url and the 'rel' extension. |
@DiegoPino Yes, your suggestion makes sense. More efficient. |
Resolved via 615b62b |
* DSID not datastream. * Catch the typed exception and return FALSE for a deprecation cycle. * Move the exception for easy removal later. * Update as per code review feedback. * Update README. * May. * English.
Every time a node is viewed, check to see if it has field_memberof, and if it does, add the url to referenced collection as a link header.
You have access to the node and can add link headers in hook_node_view_alter like so:
function islandora_node_view_alter(&$build, EntityInterface $node, EntityViewDisplay $display) {
$build['#attached']['http_header'] = [
['Link', 'http://islandora.ca; rel="awesome"'],
];
}
Use the existing rel of "collection" to describe the link.
The text was updated successfully, but these errors were encountered: