loogart / impact-canada

Canadian Government's Privy Council's Office Impact Canada website.
https://loogart.github.io/impact-canada/
0 stars 0 forks source link

Views PHP module #73

Open habernation opened 5 years ago

habernation commented 5 years ago

I would like the ability to update some of the user-restricted pages (for challenge jurors) to include custom contextual filters using PHP to filter content based on the logged in user and other fields.

I have used the Views PHP module in the past to do this and I'm hoping Duncan can install this module. I know using PHP can affect site performance and pose some security risks, but I don't intend to use it beyond a few custom PHP filters.

djsutter commented 5 years ago

I just installed this module on the dev site. We should make sure that nothing has broken as a result. Below is the composer log for my reference; note that there is an error about a patch but I think (hope) it's not a problem. When we're sure this is alright, I can put it into production.

$ composer require drupal/views_php
Using version 1.x-dev for drupal/views_php
./composer.json has been updated
Gathering patches for root package.
Removing package drupal/scheduled_updates so that it can be re-installed and re-patched.
  - Removing drupal/scheduled_updates (1.0.0-alpha7)
Deleting html/modules/contrib/scheduled_updates - deleted
> DrupalWxT\WxT\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Installing drupal/views_php (dev-1.x 71c13c3): Cloning 71c13c3d1a
  - Installing drupal/scheduled_updates (1.0.0-alpha7): Downloading (100%)
  - Applying patches for drupal/scheduled_updates
    https://www.drupal.org/files/issues/2018-03-12/2952011-2.patch (Fix FieldUiRouteEnhancer error)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2018-03-12/2952011-2.patch

Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
habernation commented 5 years ago

Thanks Duncan, this will also give me a chance to work on it and make sure it's what we need. Mike

On Wed, Mar 6, 2019 at 2:57 PM djsutter notifications@github.com wrote:

I just installed this module on the dev site. We should make sure that nothing has broken as a result. Below is the composer log for my reference; note that there is an error about a patch but I think (hope) it's not a problem. When we're sure this is alright, I can put it into production.

$ composer require drupal/views_php Using version 1.x-dev for drupal/views_php ./composer.json has been updated Gathering patches for root package. Removing package drupal/scheduled_updates so that it can be re-installed and re-patched.

  • Removing drupal/scheduled_updates (1.0.0-alpha7) Deleting html/modules/contrib/scheduled_updates - deleted

    DrupalWxT\WxT\ScriptHandler::checkComposerVersion Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 2 installs, 0 updates, 0 removals Gathering patches for root package. Gathering patches for dependencies. This might take a minute.

  • Installing drupal/views_php (dev-1.x 71c13c3): Cloning 71c13c3d1a
  • Installing drupal/scheduled_updates (1.0.0-alpha7): Downloading (100%)
  • Applying patches for drupal/scheduled_updates https://www.drupal.org/files/issues/2018-03-12/2952011-2.patch (Fix FieldUiRouteEnhancer error) Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2018-03-12/2952011-2.patch

Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested. Writing lock file Generating autoload files

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/loogart/impact-canada/issues/73#issuecomment-470253166, or mute the thread https://github.com/notifications/unsubscribe-auth/Asab5CzAnqVhdy1dXW9sX6eeWnDtCr7vks5vUB2UgaJpZM4bho7n .

habernation commented 5 years ago

Hi, the module doesn't seem to work. When I try adding a PHP field, I get the following error when the view is displayed: The website encountered an unexpected error. Please try again later. ArgumentCountError: Too few arguments to function Drupal\views_php\Plugin\views\field\ViewsPhp::phpPostExecute(), 0 passed in /var/www/pcocp/html/modules/contrib/views_php/views_php.module on line 178 and exactly 1 expected in Drupal\views_php\Plugin\views\field\ViewsPhp->phpPostExecute() (line 179 of modules/contrib/viewsphp/src/Plugin/views/field/ViewsPhp.php).

Any ideas?

djsutter commented 5 years ago

Yes. Looks to me like it has been abandoned. The last Drupal 8 version is from Nov 2015. I just assumed it was at least stable, probably should have checked. We might need to search for another solution. I'm not sure how hard it would be to write a custom filter in a custom module.

Open issues, if you want to see (yikes): https://www.drupal.org/project/issues/views_php?text=&status=Open&priorities=All&categories=All&version=8.x&component=All

habernation commented 5 years ago

Hi Duncan, I'm going to try a few things and see what options we might have. If we do need a custom filter, is that something you have experience with?

djsutter commented 5 years ago

Hi Mike, yesterday I did a search for custom filters and it looked like something I could do. In any case, I'm continually learning, so do let me know if you want to try this approach.

habernation commented 5 years ago

Hi Duncan, I've figured out how to do what I need without PHP and without a custom filter. Briefly, I added a field to PEOPLE to link user accounts to a specific challenge and create a view that filters content by that challenge. Everything works, except I need a way to prevent users from modifying their account details (right now people can use a URL to access and edit their account). Do you know how we can achieve this ? Thanks, Mike

djsutter commented 5 years ago

Hi Mike, as I write, I am installing the field_permissions module in the dev site. I had a look on my own dev and I think it might work (didn't actually try it though). If you haven't used it, go into the field definitions for people, edit a field, and down at the bottom of the form you should see a custom permissions button. See if this helps.

habernation commented 5 years ago

Hi Duncan, thanks, field_permissions might work but it doesn't seem to be working. Right now I don't see any options to set permissions and when I open the "Extend" page and try to configure the module, I get an error:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Class "\Drupal\field_permissions\Controller\FieldPermissionsController" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 24 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

This isn't a rush situation, if it takes a few days to get it working, that's not a problem at all. Thanks for your help, Mike

djsutter commented 5 years ago

Ok something obviously went wrong. It does work on my site; at least the permissions part does show up. But I don't see it on the dev site even though it says the module is enabled. Will have a look at this and let you know.

By the way, are there any changes on the dev site that you want to keep? One day we need to align the structure with the production site (as discussed earlier) so we don't lose anything.

habernation commented 5 years ago

If you can put the permissions module on the PROD site, I can build the view there and set everything up. You're right, the plan is to replace the DEV site content with the PROD one. I'm going to review the site with Chris today to make sure there isn't anything else on the DEV that hasn't been transfered. Mike

djsutter commented 5 years ago

Ok it's on the prod site now. I made a backup of the db just in case.

habernation commented 5 years ago

Great, thanks again Duncan!