I'm currently working on a simple LMS in D8 and have already defined the fundamental content types. Among them is a content type called Course
, which can be considered "Premium" content, i.e. all users may access those fields that contain more general information, but the users will have to buy a subscription for accessing the full content.
To make that possible without any Premium module (which, at the moment, have not been ported to Drupal 8), I created a simple grid-view and deactivated "SQL rewriting", which works perfectly, so far. For displaying the nodes in this view, I have created a new view mode, called gallery, so that the nodes that are displayed can be styled in a template.
I would like to apply different CSS styles to those nodes in the view that the user may access. I'm not sure if this can be done in the view itself.
Anyway, I'm currently thinking of checking the view permission inside node--course--gallery.html and I would like to add a class to the article tag, if access is permitted.
Unfortunately, I can't seem to find the right function for this. I set it up like this:
{%
set classes = [
node.bundle|clean_class,
node.isPromoted() ? 'is-promoted',
node.isSticky() ? 'is-sticky',
not node.isPublished() ? 'is-unpublished',
view_mode ? view_mode|clean_class,
user.hasPermission('view nodes') ? 'is-permitted',
node.access('view') ? 'is-permitted',
'clearfix',
]
%}
Neither user.hasPermission('view nodes') ? 'is-permitted'
nor node.access('view') ? 'is-permitted'
seem to have any effect.
Do you have any idea?