Problem/Motivation

The idea was to have different types of templates, like a whole page and something like a small two-column layout that you'd embed somewhere.

- #2296423-95: Implement layout plugin type in core

The contrib layout_plugin had a 'type' property intended for this, but nothing checks it, and there are no set of defined values.

Proposed resolution

Determine what values a 'type' property can have, and make the UI respect it.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

tim.plunkett created an issue. See original summary.

johnchque’s picture

In the contrib module we are adding a plugin system (#2828506: Introduce a plugin system for paragraphs types) which add fields to a paragraph when editing.

We want to split the fields to appear in two tabs (js based approach) but the user should be able to set a specific region of each field (content and plugin fields).

For doing so we tried the module added in: #2796173: Add experimental Field Layout module to allow entity view/form modes to switch between layouts and we were able to add two regions "Content" and "Behavior" to the paragraph entity form display.

The problem is that the plugin that we added is being shown in every entity form display and might be good if the layout plugins can check the entity type so we can add our layout plugin to be selected just in the paragraphs entities.

tim.plunkett’s picture

StatusFileSize
new7.48 KB

Here's a first draft of a patch.
Layouts can now specify types, as an array of strings.

Example ones are "page", "content", and "partial".

Any layout can define it's own, and any consumer of the API can ask for any type.
There's also a flag to include any layouts with no types defined.
Finally, there is a $negate flag, to be able to say "all types except this one". Not sure how useful that will be.

This should allow Paragraphs to define it's own type, sidestepping any coupling to the entity system.

berdir’s picture

+++ b/core/lib/Drupal/Core/Layout/LayoutDefinition.php
@@ -267,6 +276,27 @@ public function setDescription($description) {
+   * Returns the types this layout is suitable for.
+   *
+   * @return string[]
+   *   An array of type strings, see
+   *   \Drupal\Core\Layout\Annotation\Layout::$types for common types.
+   */
+  public function getTypes() {
+    return $this->types;
+  }

what about a hasType() method?

Re paragraphs, yes and no. It would allow us to do that with a custom layout system (although it wouldn't automatically exclude our layout type from other usages unless they limit by a specific type as well).

But that's not what we'd do, we would provide a layout for field_layout. As mentioned in IRC, we actually don't even really need a layout system... all we really care about is having two regions in the UI and were hoping to somehow rely on field_layout to help us with that.

A quick idea that I had is to add an alter hook to the provided layouts in field_layout.module that also accepts the entity type and possible more context. Then we could alter it so that paragraphs form display only gets that single layout and we'd unset it for every other entity type. That might or might not rely on this types concept.

damienmckenna’s picture

+1 for this direction.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new1.86 KB
new8.71 KB

I think #4 sounds like a useful alter hook to introduce in Field Layout itself.

Status: Needs review » Needs work

The last submitted patch, 6: 2822758-layout_types-6.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new7.85 KB

Had the patch applied locally to the wrong branch. Interdiff was right though.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Status: Needs review » Needs work

Patch works, but this is not enough.

damienmckenna’s picture

To clarify the use case, it is focused around being able to indicate that e.g. certain layouts are designed for full page displays (think: Panels Everywhere) whereas others would work better for e.g. an entity display (think: Panels or Panelizer) or even a block display (think: Mini Panels).

tim.plunkett’s picture

Priority: Normal » Major
Status: Needs work » Postponed

This is the only remaining "Must Have" blocking Layout API from being stable.
We should push forward on #2848549: Refine the layout selection UI, as it might make this obsolete.

damienmckenna’s picture

This option feels like a solution looking for a problem.

I think we should close this as "won't fix", wait to see what #2848549: Refine the layout selection UI comes up with and drive all changes from that.

tim.plunkett’s picture

Status: Postponed » Closed (won't fix)

This initial idea stemmed from some code that @Berdir added to the original layout module, the precursor to Layout Plugin:
https://github.com/frega/layout/commit/3ce31194#diff-0edab2ba7783e66405f...

After further discussion amongst the Panels-ecosystem team, we have decided not to pursue this.

Instead efforts will be focused on #2860903: Provide a mechanism for a module to restrict the allowed layouts it can use