I'm using a number of custom layouts that use templates from this module, which work, like so:

mytheme_basic:
  label: Basic
  description: 'Standard layout for most content.'
  category: MyTheme
  class: '\Drupal\bootstrap_layouts\Plugin\Layout\BootstrapLayoutsBase'
  type: partial
  path: ../../modules/contrib/bootstrap_layouts/
  template: templates/3.0.0/bs-2col-stacked
  library: mytheme/layouts
  regions:
    top:
      label: 'Top'
      classes:
        - col-sm-12
    left:
      label: 'Left'
      classes:
        - col-sm
    right:
      label: 'Right'
      classes:
        - col-sm-4
    bottom:
      label: 'Bottom'
      classes:
        - col-sm-12

But when I create a custom template for one of these layouts, I get "Fatal error: Call to a member function id() on null in /code/modules/contrib/bootstrap_layouts/bootstrap_layouts.module on line 83". It's trying to reference the layout at $variable['layout'] but it's no longer there for some reason. This is the layout causing that error:

mytheme_list_item:
  label: List Item
  description: 'Layout for display in a list.'
  category: MyTheme
  class: '\Drupal\bootstrap_layouts\Plugin\Layout\BootstrapLayoutsBase'
  type: partial
  template: templates/layout/sprout-list-item
  library: ma_bootstrap/sprouts-layouts
  regions:
    top:
      label: 'Top'
      classes:
        - col-sm-12
    left:
      label: 'Left'
      classes:
        - col-sm
    right:
      label: 'Right'
      classes:
        - col-sm
    bottom:
      label: 'Bottom'
      classes:
        - col-sm-12

Comments

dkosbob created an issue. See original summary.

dkosbob’s picture

This patch solves it for me, by accessing the layout and settings one level deeper in the variable if it's not found. Still not sure about the cause of this.

markhalliwell’s picture

Status: Active » Closed (duplicate)
Related issues: +#2872583: Empty "layout" and "settings" in _bootstrap_layouts_preprocess_layout()

This is a core bug, see related issue for links.

npralhad’s picture

Title: _bootstrap_layouts_preprocess_layout fails to find layout if custom template is used » Content type specific bootstrap layout
Category: Bug report » Support request
Status: Closed (duplicate) » Active

Patch worked for me too, thanks. I am trying to get the bootstrap layout overridden only for some specific content type, E.g. [article] --> [bs-1col-stacked--article.html.twig] but not able to get it working. Currently trying to get it done through layout hooks if possible.

Any assistance will be highly appreciated.

markhalliwell’s picture

Title: Content type specific bootstrap layout » _bootstrap_layouts_preprocess_layout fails to find layout if custom template is used
Category: Support request » Bug report
Status: Active » Closed (duplicate)

Don't hijack issues. I already explained that this is a core bug, not an issue with this project.

npralhad’s picture

Category: Bug report » Support request
Status: Closed (duplicate) » Active

Hi Mark

Thanks for reply. My question was about - getting the bootstrap layout overridden only for some specific content type, E.g. [article] --> [bs-1col-stacked--article.html.twig]. Is that possible ?

markhalliwell’s picture

Category: Support request » Bug report
Status: Active » Closed (duplicate)