2

I have a content type that has an entity reference field allowing you to link to other pages and add a custom image, for nice big CTAs.

However, it's come to light that some of the links may need to be to Views that show content as a list or map.

The ER field has autocomplete enabled and it can't find the view by its URL e.g /my-view

Is there a plugin that would allow the field to find Views? Or do I have to change the content type and add a Link field instead?

  • As it's an entity reference field, and views pages aren't entities (views are, but its the page display which you want to link to, not the underlying view), you cannot use this field for this purpose. A link field will be a better choice in this case. There's a plugin you can use to include views pages in the autocomplete, just hunting for it, brb. – Alfred Armstrong Jan 29 '18 at 14:13
  • Turns out I was thinking of linkit_views, which is not relevant to this case, sorry. – Alfred Armstrong Jan 29 '18 at 14:26
0

Views are config entities so you can target them to be referenced (see screenshots) and check this post.

Add new field Selecting ER field target type

The caveat is you can only point to a given entity type when using ER fields so you cannot have an ER field targeting content and config alike.

On the other hand almost any market solution referencing views aim to render it not just displaying a link pointing the view.

As you suggest using a link field can work around with your use case but the link form element only autocompletes content entities, you cannot type your views' display title and wait for it to get the proper URL for you. For that I'm afraid you need to provide your own widget/form element (and controller). Check this and this about how to build your own autocomplete widget/form element for a text field and this post from Drupal.org docs on how to build your own field formatter.

Also worth noticing that Views URL's are used on limited display types (Page, Feeds, possibly 2 more but I'm not quite sure) and is considered a route, not a path or link like when building a menu link item.

Hope this points you in the right direction.

-1

One way to handle this is to make the view page into a block, then create a node with no content that contains this block (block placement in main content with limited view to /node/. Then use this in the entity reference field.

An alternative might be to have a content type that uses one of the views fields like view reference. Then just create a view node with the desired view and use it.

  • The views_reference module allows to reference a view to render it, is not what the OP wants to achieve since the problem to solve is to generate a link element pointing to the selected view display. Thus the later can be built on top of referenced module it may not be what the OP is looking for. – d70rr3s Dec 11 '19 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.