Filter content list by 'Service contact'
Opened this issue · 19 comments
Following on from #12
Content designers would like a view showing the pages assigned to a specific service owner
Could we add a 'service contact' drop down to filter the main content view at /admin/content?
The order would be
Title / Content type / Published status / Service owner / Language
This is based on amount of use each gets - my hunch is editors would use it less than published status but more than language
Hi @MariosORION did you get chance to look at this? Thanks
Am looking for a few more issues for you if OK
@willguv yes I've tried a few things but it's proving more tricky than I thought - I'll post my findings shortly.
Am looking for a few more issues for you if OK
Yes, please do
To POC this, I've enabled localgov_workflows_notifications and created a service contact entity (associated to a Drupal user). Then, on the content View, I've added a new exposed filter "Service contacts" but only insufficient operators are available by default ("Is equal to" requires the user to enter the entity ID which is not very practical):
The operator we need here is "is one of" similarly to the content type select list but this is not available by default for entity reference fields in content (such as service contact field on LGD nodes).
I've tried Views Entity Reference Filter
; it does provide the required exposed filter operator but it comes with fatal errors when "Filter" is pressed on the enhanced content View.
There are a couple of patches available for similar issues but neither of them seems to work.
Better exposed filters doesn't provide the results required either.
I'm thinking of writing a custom filter and adding it to the content View programmatically but that's considerably more work so it makes sense to ask for alternative suggestions, if any?
following with interest
@stephen-cox is suggesting looking at a hook_form_alter on the exposed field to generate a nicer user experience.
@MariosORION if you can share the fatal error, perhaps we can fix the Views Entity Reference Filter issue ?
@rupertj has used Views Entity Reference Filter with success.
On the deployment question, we want to keep this as an optional feature for existing sites.
One option could be a different view like /admin/content-by-owner
PR #104 ready for review.
Changes:
- Adding new View page /admin/content/localgov-content-by-owner that lists content by owner (relationship to service contact required):
- Adding dynamic menu link that only gets placed if the View above is present:
- Adding dynamic local task that only gets generated if the View above is present (see below for screenshot).
I've tested this with a new user, service contact tied to that user and a service page with that service contact assigned; here's how the new View looks like (some columns are sortable just like the vanilla content View):
To add the View when localgov_workflow_notifications is already enabled, Councils can manually import the View's YML configuration (views.view.localgov_content_by_owner.yml) into their site:
views.view.localgov_content_by_owner.yml.zip
Benefits of this approach:
- No additional module required (verf). There is also a patch required for this module to avoid a fatal error when a VERF select exposed filter is added to the View (issue https://www.drupal.org/project/verf/issues/3113519)
- The "Content by owner" View can be optionally enabled and only comes to play when the localgov_workflow_notifications sub-module is enabled
Possible cons of this approach:
- The new "Content by owner" View is on its own distinct path and not integrated with the default Content View (which might be appealing for some Councils as it also keeps the main Content View clean)
Thanks for doing this @MariosORION - could you add a screenshot to this page?
Is there a composer command I can use to install this branch?
@willguv it should be something like:
composer require "localgovdrupal/localgov_workflows":"dev-feature/85-content-filter-by-service-contact" --with-all-dependencies
but I haven't tested it yet.
I've added description and screenshots from the PR in my previous comment here.
Thanks for your work on this issue @MariosORION . I've got an autocomplete filter working using your branch, a core patch and a contrib module:
If this would be a good addition to this issue, do you want to try it or I can create a commit? I see you've already considered VERF, so I'm happy to keep this as a follow-up issue.
See:
Hey @Polynya, there's actually a PR for this issue already - please see #85 (comment).
Benefits of this approach:
- No additional module required (verf).
- The "Content by owner" View can be optionally enabled and only comes to play when the localgov_workflow_notifications sub-module is enabled
Possible cons of this approach:
- The new "Content by owner" View is on its own distinct path and not integrated with the default Content View, which might be appealing for some Councils as it also keeps the main Content View clean
Your suggestion (and thank you for that!) could also work -it's just a different approach, do you have a preference over the approach in the open PR? (There are some tests failing on the PR but I'll have another go today - any help is more than welcome!).
Hi @MariosORION , I was using your PR but it doesn't allow you to see the content for just one owner. I think that the exposed filter is needed if there are a lot of pages and owners.
@Polynya true, only sorting would be available with the additional custom View but no additional module is necessary. I'm more than happy to follow the alternative approach but I feel this should be a wider decision so best to discuss on a merge call (I'll try to make it today) :)
Before finding this issue, I was working on a different approach, which is to display the pages relating to a Service Contact on their canonical page - /admin/content/localgov-service-contact/%
This would remove the need for an external filter and new module. Could we do this along with your View but with links to the Service Contact page?
I like this idea (feel free to push to this branch). I'm also thinking about permissions; would this allow all involved Drupal users (roles) to access the list of content for any given Service Contact?
@Polynya could you provide screenshots of the work you've done? Trying to get my head round this - many thanks!
(Sorry for not being present in this chat, was on holiday)
Here's the Service Contact page, showing a block that I added to @MariosORION' s view (with a contextual filter to show content for one Service Contact)
This is the "Content by owner" page using the view with the exposed filter added:
Although I used a contrib module for the entity reference filter, I don't think it's essential. It does need a core patch though, and it may be best to wait until it's merged:
https://www.drupal.org/project/drupal/issues/3347343
@Polynya Nice to see core is finally getting the ability to add entity reference filters to views. I've ended up doing hook_form_alters to get this sort of thing working in the past.
The issue seems to be quite active, so probably best to waiting to see if it gets committed soon.
In the meantime I suggest we get Marios' work on this committed and the service contact filter added later.
PR #104 tests are now clean and suggestions committed @stephen-cox @Polynya @willguv . Thanks all!