Problem/Motivation
Linkit is an awesome module that has almost the possibility to create suggestions for everything. Not totally since Views displays that has "uses_route" (for instance page display) cannot be added in the suggestions.
This is a big flaw since Views is part of core and an important tool to create pages that could be referenced in nodes.
I would emphasis this feature is needed from the two following indicators:
- it used to be possible in former versions
- the number of followers on this issue
Proposed resolution
A new matcher plugin for view having a path is proposed as a solution.
As described in #6 and according to my own researched, it will require an API change since we will need some extra information on the
substitution plugin side to target the appropriate display. In is commonly assumed indeed that a view can have multiple page type display.
It will also require a new deriver to authorize EntityMatcher for config entities. This is done to reuse EntityMatcher as a base class for the ViewDisplayMatcher to reuse code.
Remaining tasks
- provide a functionnal patch
- review the patch and agree on a functionnal solution
- update tests accordingly
- review the whole patch
- enjoy
User interface changes
A new matcher (suggestion type) will be available from the UI: 'View display'.
API changes
\Drupal\linkit\SubstitutionInterface getUrl() method has to accept one more parameter.
This may break custom matcher plugins written by DX
Data model changes
None
--------------
EDIT: Original post:
Hi
How can I link pages created using views using Linkit module.
Thanks
Nijil
Comment | File | Size | Author |
---|---|---|---|
#29 | linkit-views.patch | 21.22 KB | Kevin N |
#28 | linkit-views.patch | 20.68 KB | Kevin N |
#25 | linkit-views.patch | 21.21 KB | Kevin N |
#23 | interdiff_18-23.txt | 2.11 KB | BryanDeNijs |
#23 | add_views_suggestions--2867647-23.patch | 21 KB | BryanDeNijs |
Comments
Comment #2
anonUnfortunately this is not possible at the moment.
You can create a new feature request issue, or convert this into on if you like.
Comment #3
droprocker CreditAttribution: droprocker commentedComment #4
ikeigenwijs CreditAttribution: ikeigenwijs commented++!
Comment #5
frazac CreditAttribution: frazac commented++!
Comment #6
gwagroves CreditAttribution: gwagroves commentedHaving a look at this.
linkit.autocomplete.js
only allows us to set (as I understand it) three data attributes for a suggestion:data-entity-type
,data-entity-uuid,
data-entity-substitution
.Views are entities, so we can build a Matcher that passes the entity type "view" and the view uuid to the autocomplete if criteria (e.g. view name) are matched. So far so good.
We then need a custom substitution plugin "view" to handle the entity type. (We set
data-entity-substitution="view"
and theLinkitFilter
will load it.) The substitution plugin can load the ViewExecutable and can generate a URL using it. However, there is no way to pass in a display id as a data attribute, so currently I'm just linking topage_1
as a default.If
linkit.autocomplete.js
would allow an extra field, e.g.data-entity-meta
, theLinkitFilter
could pass the meta data to the substitution plugin which could use it to generate the url.(Ignoring the title attribute for now.)
Comment #7
gwagroves CreditAttribution: gwagroves commentedSolved this using a different approach, using a custom configuration entity to store Drupal route information:
Create a custom config entity "Linkit custom link" that stores the route data (name, parameters, query string, etc.).
Create a custom Matcher to match custom links using the label (e.g. "Events list" is mapped to
view.events.page_1
.)Create a custom Substitution class for custom links. The
getUrl()
method receives the custom entity we created from Linkit. We can now use the stored route information to build and return the URL. All of the required meta data is in the custom entity.Site builders can define any number of custom links as long as they use a Drupal route, so Linkit can then provide editors with links to custom controllers, views.
The custom link entity could also accept external URLs, so that external links (e.g. "service portal") could be provided and updated centrally.
Comment #8
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedPatch attached and issue summary updated
This patch is functionnally OK, but I did not update any tests for now. I would like first an approval on the direction by module maintainer before further work.
Comment #9
jacobbell84 CreditAttribution: jacobbell84 commentedI did some testing on my sites, and one issue I ran into is that it's trying to process views that require arguments in their paths. This causes the Url::fromRoute call to throw an exception. I don't think there's a use case to support views like that, since we'd have no way to know what the argument is, so I'm just filtering them out of the result set for now.
Comment #10
jacobbell84 CreditAttribution: jacobbell84 commentedFixing the linting issue with the previous patch
Comment #11
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedI still add the error after upgrading to #10.
Symfony\Component\Routing\Exception\RouteNotFoundException : Route "view.portfolio." does not exist.
Notice the extra point "." at the end of the route. It comes from
"view.{$entity->id()}.$extra"
where $extra is always empty.
The reason is an uproper key in my patch #8 which leads to no substitution-extra added to the WYSIWYG.
Fixing that in attached patch.
Comment #12
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commenteddamn... I forgot to include the new files in patch #11.
Comment #13
BryanDeNijsThanks for this great patch.
I have made some improvements:
- There was a small issue with the "Include disabled views" setting. It didn't get saved when submitting the config form. This is now fixed.
- The view storage is now a class variable, set by the __construct.
- Made an extra setting to make it possible to only allow a selection of the views to be used by LinkIt.
Hope you like it :)
Comment #14
BryanDeNijsI have made a new patch with some more improvements to be more in line with the other matchers.
Comment #15
BryanDeNijsFor a client, we have now implemented the patch of comment #14. But after a bit of testing, our client requests the possibility to search by display title instead of only the view label or display path.
I added the option. Here is a newer version of the patch.
Comment #16
BryanDeNijsSorry, something went wrong while creating te previous patch.
Here is te correct one.
Comment #17
cedeweyFrom a sitebuilding perspective, this is working great. This is a very helpful feature to have. Thank you to everyone who has worked on this. I'm going to leave it as Needs Review for someone else to do a code review.
Comment #18
BryanDeNijsHere is a new version of the patch. After some time running the patch from #16, we noticed some errors in the logs about non-existing routes:
Symfony\Component\Routing\Exception\RouteNotFoundException: Route "view.news_overview." does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (regel 206 van /app/web/core/lib/Drupal/Core/Routing/RouteProvider.php).
This was caused by a text-format with the html-filter enabled. The
data-entity-substitution-extra
attribute was not in the allowed attributes for the<a>
tag, so the html-filter deleted it.The old patch did not check if the display_id (which should be stored in the
data-entity-substitution-extra
attribute) was present, so I did some improvements:data-entity-substitution-extra
contains a view display ID.Another important note:
The patch (old+new) has a change in the
SubstitutionInterface
. Any other (custom) modules that uses this interface will break if this patch is applied, because of the new$extra
parameter that was added to thegetUrl
method. So that is something to remember to put in the changelogs!Comment #19
BryanDeNijsOops, I accidentally re-uploaded the old patch instead of the new one. Here is the new version.
Comment #20
BryanDeNijsComment #23
BryanDeNijsAnother iteration of the patch. The matcher now also matches the view displays by matching path aliases. So for example, the path of the view display page is
/news
, but there is a translated path alias/nieuws
, the view display will now also be found when searching for/nieuws
.Comment #24
undersound3 CreditAttribution: undersound3 commentedDoes anybody know if there is something like this available for 6.x or can we use this patch as a base to create a patch for the 6.x version?
Comment #25
Kevin N CreditAttribution: Kevin N at Kodamera AB commentedI did a quick update of the patch for 6.0.0-rc1, haven't tested it much, but it seems to work.
Comment #26
jeff.hartman CreditAttribution: jeff.hartman commentedMy experience with the patch is that it works well with one main caveat... the "data-entity-substitution-extra" attribute is not automatically added to the
<a>
when choosing the view.If I add it manually in source, save, and then go to add another link to a view, the second link will have it added automatically.
Seems very odd and have been banging my head against the wall trying to figure out why.
Comment #27
robcarrLike the idea of this patch and it's a shame the functionality isn't already there (pretty much every other entity type can be matched). Doesn't apply to 6.0 branch.
Comment #28
Kevin N CreditAttribution: Kevin N at Kodamera AB commentedDid another quick tweak of the patch for 6.0.2 support.
Haven't tested it more than to see that linking views still work locally.
Comment #29
Kevin N CreditAttribution: Kevin N at Kodamera AB commentedNoticed an issue with the patch at #25 so i made an update for it (This is for 6.0.0-rc1)