Problem/Motivation

While working on #3583128: Views DOM ID class is missing for Ajax-enabled views, we discussed about adding a new ViewTemplateSource for slots

PageLayout already has PageLayoutSource which is rendering page.html.twig and is automatic injected with the existing block layout configuration by BuilderDataConverter

If we add something like that for Views, we can:

  • initialize each View display managed by Display Builder with the exact same look at the same display without Display Builder (if there is specific CSS template(s) in themes, they are still rendered, and view theme hook preprocesses are still executed)
  • allow builders to remove the node from the tree if they don't want it, and go the full display builder way

Proposed resolution

Add modules/display_builder_views/src/Plugin/UiPatterns/Source/ViewTemplateSource.php:

  • for view context
  • not configurable
  • with slots: title, header, exposed, attachment_before, rows, empty, pager, attachment_after, more, footer and feed_icons
  • rendering #theme => 'view' or #type => 'view'

Replace default_view.yml fixtures by a BuilderDataConverter service which build the tree according to the current display configuration.

Other task

A good opportunity to review and cover display_builder_views/src/Hook/PreprocessViewsView.php.

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

pdureau created an issue. See original summary.

pdureau’s picture

Status: Active » Needs work

I have started playing around. I hope it can help someone willing to take the task.

It is important than the '#theme' => 'views_view' returned by ::getPropValue() is loading the expected template suggestions: views-view--{view-name}--{display-id}.html.twig this was not tested and we may need a specific ViewTemplateSourceTest

No need to replace default_view.yml fixtures by a BuilderDataConverter service, just adding some information to the fixture may be enough.

mogtofu33 made their first commit to this issue’s fork.

mogtofu33’s picture

Assigned: Unassigned » mogtofu33
mogtofu33’s picture

Issue summary: View changes
mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs work » Needs review

Problem I think with this approach is we now have views regions fixed when giving Views options (ajax/class) available to the rendered view.

  • Display builder managed fully - Use ajax and views class from views settings not available
  • View source - Ajax and class works but regions are fixed by template, Display builder partially manage

But we want mostly to provide: Display builder managed fully - Views ajax and class from UI working.

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs review » Needs work

Initial proposal

This ticket was initially authored to address this situation:

  1. An user has already built a view display the "old way" (template suggestion, like views-view--{view-name}--{display-id}.html.twig and sometimes other view templates and related preprocesses)
  2. They switch to display builder for this specific view display, do nothing, or nothing special, maybe just adding a button here or there
  3. The view display is broken: the old markup is not rendered anymore

With a ViewTemplateSource and the corresponding change in fixtures/default_view.yml:

  1. the user will have as a starting point the same view they have are already built, with the same template and preprocess, which are working as expected
  2. until they decide to rebuild something in Display Builder UI, free from the constraints of views-view.html.twig, without needing the preprocess anymore.

Current proposal

The current state of the MR is now targeting something different: always print the wrapping attributes additions and alterations from #[Hook('preprocess_views_view')](changed in views-view.html.twig).

Am I understanding right?

However:

  • does those attributes make sense without the rest of the template? Genuinely asking.
  • if we keep/use ViewTemplateSource, those attributes will be rendered twice
  • how does it help users with a sensible starting point?

Moreover, with the changes in fixtures/default_view.yml, the ViewTemplateSource plugin seems to be useless now, because it is not shown in the libraries (until we decide to extend component library to all plugins implementing SourceWithSlotsInterface, but that will be another ticket). Am I missing something?

So, it seems we are in-between two different strategy here, and we need to decide:

  • do we always want to render the legacy stuff (template suggestions and preprocess) ?
  • do we never want to render the legacy stuff?
  • do we only want to render the legacy stuff in a specific source plugin automatically imported as a starting point?
  • something else?

(Footnote: ViewTemplateSource plugin doesn't have contexts and is loading the view from settings, it is "normal" until we switch to a proper context system in #3542796: Preview of view sources)

pdureau’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs work » Postponed
Issue tags: -display_builder-1.0.0-beta

Following today weekly, we are splitting the work:

  • The present ticket will stay focus on ViewTemplateSource, but postponed as a nice-to-have for 1.0.0 scope.
  • A ticket dedicated to the template suggestions issue discussed during meeting has been created: #3618110: Override views view template suggestions
  • A ticket dedicated to the AJAX issue will be created
mogtofu33’s picture

A ticket dedicated to the AJAX issue will be created

Fixed with #3583128: Views DOM ID class is missing for Ajax-enabled views.