Skip to content

Instantly share code, notes, and snippets.

@labbydev
Created April 5, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labbydev/95af4639a9c06e21955ad8717520a43d to your computer and use it in GitHub Desktop.
Save labbydev/95af4639a9c06e21955ad8717520a43d to your computer and use it in GitHub Desktop.
Running notes from my findings from investigating and experimenting with Layout Builder in Drupal 8.5.1

Layout Builder Spike

Ticket Branch

Goals

  • Enable Layout builder
  • Turn it on for a news article page
  • Theme the page
    • We're going to be working on the Press Release template because that content type has fields.
    • Without being able to create a custom layout I'm pretty much blocked on this.
  • Report your findings

Notes

Layout Builder

Steps to build a layout

  1. Enable layout builder
  2. Assign global blocks to the correct global regions
    • Turns out that things were kind of confusing because all of the default blocks where being put in the content region. Moving these out to their appropriate regions (and removing/disabling some) was a necessary step in order to "get my head on straight."
  3. Manage layout for News Article content type
    • This is somewhat confusing especially without seeing the header and footer clearly defined.
    • Using the page title doesn't seem to actually print the page title when I save the layout. This could be because the page title is already being rendered above that.
    • I need to figure out how to add layouts to layout builder.
    • When trying to place the subtitle in a region above the rest of the content it's extremely difficult and rather annoying to try and move past the different options. Also it took me a minute to remember that I cannot "place fields" the way that I would place a block, but in stead I have to drag them from their current place to the desired place. Generally speaking, long text fields are just extremely difficult to maneuver to the correct location.
      • On the default layout, all of the fields are being set with some filler content, so all content is extended to some of it's longest possible options.
      • Moved the subtitle to a new region, attempted to configure it to hide the label (which never seemed to disappear from the default layout - I assumed this happened because it was there to say what that was regardless since otherwise it's all just lorem ipsum), and this seems to have broken all of the layouts for that content type resulting in the following error: Drupal\Component\Plugin\Exception\ContextException: Required contexts without a value: entity. in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 96 of /var/www/ama-d8.local/docroot/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).
      • So I'm not really sure what's going on there but that needs some more testing
      • It looks like when I try to configure the Subtitle field to hide the label that the AJAX doesn't quiet fire and actually save the settings when I click the button. Reloading the page has resulted in a WSOD (same error as above). When this happens the best result I have is to re-import my last saved config in order to get rid of the error.

Field Layout

Originally I didn't want to turn on Field Layout because I'm not too sure of what it does. But it seems that I can't place specific fields in different layout sections unless this is on.

Turning it on has created a WSOD, however clearing caches seems to have resolved it.

Layout Library

According to this video, there should be a "Layout Library" module that allows you to create custom layouts through the admin UI. However, this module isn't included in core. When google-ing some I found:

Layout Library Module

Layout Library with no release information. It says that the requirements are Layout Discovery, Layout Builder and Field Layout. I currently meet all of those requirements locally. In the "known problems section you see":

It will eventually become a for-real project. See the issue queue for remaining work. Please use the issue queue to report any issues.

There are a handful of issues in the queue one major, the rest are normal. The major one hasn't been updated in weeks and the normal ones haven't been updated in months. Without this functionality I'm not sure how I can define custom layouts for layout builder.

In order to test it out I cloned the branch. This would be something we would have to either create our own custom module for or contribute back to this module in order to get it included in core or as a contrib module. We may want to see if Lee is at DrupalCon and discuss what the path for this is with him there, if we're interested in getting the AMA team involved.

Steps to create a layout

  1. See comments above to acquire the Layout Library module
  2. Enable the module
  3. Navigate to /admin/structure/layouts
  4. Click "Add Layout" button
  5. Set the label and entity bundle to use the layout and Click "Save"
    • At this point the page gets a WSOD with the error Symfony\Component\Routing\Exception\RouteNotFoundException: Route "layout_builder.layout_library.node.view" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 202 of /var/www/ama-d8.local/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php).
    • This issue has already been logged in the issue queue, but there is little action and no resolution at this time.
    • According to the video:

    This is done by creating a plugin that implements the section storage plugin interface and essentially you're just responsible for telling Drupal that okay this is a new way of storing layout that's associated with the particular paradigm. Once you implement the interface and tell us some paths for the routing you can essentially use the same way I build and install however you like. So, the default storage for example of manage display is it's stored in the view display entity. So the config entity that's deployed when you do manage display. The implementation for the article level is it's stored in a field on the content entity....

    • Basically rambling and then "look at examples from the core layouts"
  6. Create a layout
    1. Navigate to core/modules/layout_discovery.layouts.yml
      • Copy this and pull it into the theme to define the layout options for that theme.
    2. Give it a name and label
    3. List the regions
    4. With that provide a twig template
    5. Output the regions in the twig template

So I've gone through and created a ama-one.layouts.yml and the layout file for what would be the Press Release, but I still cannot seem to get past the routing error. I have included the code that I wrote for the layout but I didn't include the config. Also the module would have to be manually added elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment