Problem/Motivation

I just tried to update the module from 2.0.0 to 2.1.8
In Version 2.0.0 i used the following condition to check if paywall access is given or not:

{% if content.paywall %}

If that condition was true, the paywall curtain was shown.

I used that condition to render the paywall curtain block at a specific place inside a node twig template and used the condition to render a few more things regarding the paywall. Is there any condition i can use to check if paywall access is given or not with this module?

Steps to reproduce

Proposed resolution

Add documentation how to use twig condition if it exists. If it does not add a hook where to check if access is given or not.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

makkus183 created an issue. See original summary.

makkus183’s picture

Issue summary: View changes
akoepke’s picture

Hi @makkus183, thanks for your feedback. You are right, there was a regression in functionality here.

The paywall field was removed as part of my rewrite of the code, its main purpose was used to display the paywall block which is now being handled by Drupal itself via a block condition.

The only way to check if the paywall was active was to see if a field that is blocked has a value. I realise this can lead to issues if someone changes the fields which are being hidden.

Because of this, I have added an element to the $build array in role_paywall_entity_view(). This can then be used in a preprocess hook to set a variable in the template.

I have added a preprocess hook for node entities to the module so there is now a role_paywall_has_access variable available in the templates. This contains the result from the access checks performed so will be true if the person has access to the content (no paywall) and false if the paywall will be displayed.

akoepke’s picture

I have added a new release with this fix.

Can you please update to the latest version and let me know if things work as expected after you have updated your template.

akoepke’s picture

Assigned: Unassigned » akoepke
Status: Active » Fixed

makkus183’s picture

Hi @akoepke ,

thanks a lot for looking into this and maintaining this project now! I can confirm that the mentioned variable is now set and the condition is working as expected:

{% if role_paywall_has_access is defined and role_paywall_has_access is empty %}

I was testing the latest version on a project which was still runing on PHP 7.3. because i skipped updating this module on our other projects already. There i got a fatal error when calling a node whith paywall curtain:

Fatal error: Declaration of Drupal\role_paywall\Plugin\RolePaywallAccessRule\RolePaywallUserRole::checkAccess(Drupal\Core\Session\AccountInterface $account, $entity_type, Drupal\Core\Entity\ContentEntityInterface $entity) must be compatible with Drupal\role_paywall\Plugin\RolePaywallAccessRulePluginInterface::checkAccess(Drupal\Core\Session\AccountProxyInterface $account, $entity_type, Drupal\Core\Entity\ContentEntityInterface $entity) in /var/www/html/web/modules/contrib/role_paywall/src/Plugin/RolePaywallAccessRule/RolePaywallUserRole.php on line 22

Thats why i made https://git.drupalcode.org/project/role_paywall/-/merge_requests/5 in this issue, as it is not really related to this topic.

akoepke’s picture

Hi makkus183,

Thanks for picking up that issue. The changes you proposed are not the correct solution though.

I had originally used AccountProxyInterface in RolePaywallUserRole but it actually should be AccountInterface as per the documentation.

It is generally more useful to use \Drupal\Core\Session\AccountInterface unless one specifically needs the proxying features of this interface.

Looks like I forgot to go through and change the other instances in the module.

akoepke’s picture

I have made these changes as a new commit and closed the merge request.

https://git.drupalcode.org/project/role_paywall/-/commit/552b15720b3ab27...

Once the automated tests have finished running I will create a new release.

EDIT: Release 2.1.10 has been made.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.