Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the main page content block to layouts that do not have "main page content" #2636

Closed
klonos opened this issue Apr 11, 2017 · 21 comments
Closed

Comments

@klonos
Copy link
Member

klonos commented Apr 11, 2017

Main page content block not available for the Home page layout.
Why is that?

@Al-Rozhkov
Copy link
Member

I guess, there is no context for it. Nothing to show.

@klonos
Copy link
Member Author

klonos commented Apr 11, 2017

Yeah, that makes sense.

@klonos klonos closed this as completed Apr 11, 2017
@bd0bd
Copy link

bd0bd commented Apr 11, 2017

Hm, why there is no Main page content block in the Sutro layout? There is area CONTENT but there is no Main page content block for this area.

@klonos
Copy link
Member Author

klonos commented Apr 12, 2017

@bd0bd Sutro is a layout template. Which layout are you trying to apply it to? ...if it is the "Home page" layout, then see @Al-Rozhkov answer above ^^

@bd0bd
Copy link

bd0bd commented Apr 13, 2017

Basic page.
I create a basic page and switch from default layout - Moscone Flipped - to Sutro.

img_20170413_141656

@markabur
Copy link
Member

@bd0bd It's confusing, but when you add a custom layout using a node/[nid] path like that, it doesn't work the way you expect. In general, any layout that has a non-wildcard path will not have a "content" block as there's no place for the content to come from (just like in your home page layout). When you create a custom layout using node/5 as the path, you are completely circumventing the system's built-in way of handling the "node/5" path, which actually makes the node content inaccessible -- not what you want.

Instead, configure the Contact layout to have "node/%" as the path, and "Node NID is 5" as a visibility condition. That way the system will still go through its normal process for loading node/[nid] content, and you'll have a content block available in your layout.

screen shot 2017-04-13 at 10 03 59 am

@bd0bd
Copy link

bd0bd commented Apr 13, 2017

Thank you very much! 👍

@markabur
Copy link
Member

Ya, this trips me up too sometimes and the only I was going to remember was to type it up myself... thanks to @quicksketch for original explanation in #735.

@docwilmot
Copy link
Contributor

What if we automatically fixed this for the user? Meaning if a user types in entity/numeric we automatically converted this to entity/% and added a condition for entity id = numeric ?

Any downside? @jenlampton?

@jenlampton
Copy link
Member

That sounds awesome :)

Can we add a condition for path instead of entity ID? I feel like that's going to be more in line with what people expect to happen.

We should also add a message saying "A condition has been added for this layout to match the path you entered" so that people don't think it's a bug.

But yes, a big +1 for this!!

@Al-Rozhkov
Copy link
Member

Al-Rozhkov commented Apr 13, 2017

Please somebody native english speakers specify better title, I'm struggling to formulate it :)

It is also become a feature request.

@stpaultim
Copy link
Member

stpaultim commented Aug 11, 2020

This issue was closed and then reopened with the suggestion 3 comments up. I don't think that the title of this issue is very helpful (anymore) and I don't understand the suggestion that @docwilmot made enough to edit the title myself. Any help?

Is this related to: #3750 - Layouts: Add support for custom contexts

@docwilmot
Copy link
Contributor

Layout provides the Main content block only if that layout is overriding an existing path (a path that is in a hook_menu() somewhere). So if you create a layout with path:

  • admin/content => MCB available
  • node/% => MCB available
  • path/provided/by/contrib/module/% => MCB available
  • previously/nonexistent/path => MCB not available

No module provides a path "home" in any hook_menu(), so no MCB.

My comment there had nothing to do with the original title sorry, was just a response to #2636 (comment)

To fix this issue, and provide the MCB on the home layout, I suppose we could add a "home" path entry to system(or layout)_menu() with node_page_default() as the page callback. Side effects uncertain.

@klonos
Copy link
Member Author

klonos commented Oct 25, 2021

@docwilmot perhaps you are the most appropriate person to answer this: I see that the blocks defined by the Dashboard module via dashboard_block_info() specify 'required contexts' => array('dashboard'), which effectively only allows them to be added in Dashboard layouts. In #4673 I would like to allow the "Welcome to Backdrop CMS" block to also be placed in the home page (layout), so I figured that I needed to change that property for that block to something like 'required contexts' => array('dashboard', 'home') instead. However, I realized that the home page layout (or Backdrop core in general) does not offer a home context out of the box.

When I try to edit the contexts of the home layout via the admin UI, this is what I am given as options:

So, do I need to programmatically create a new, custom layout context home (same as the Dashboard module provides the dashboard context)? If so, then how do I do that? Can you please point me to some example code?

Thanks

Side-question: why isn't the dashboard context provided as an available option when creating new layouts?

@bugfolder
Copy link

Just out of curiosity, I replaced the 'required contexts' => array('dashboard') with 'required contexts' => array() in my sandbox and the dashboard still loaded happily. So that makes me wonder: do we need to require this context for these blocks?

@bugfolder
Copy link

The DashboardLayoutContext doesn't seem to do a whole lot.

@bugfolder
Copy link

@klonos, from your question 3 comments up, should there be a new issue like "Make blocks defined by Dashboard module available to any layout?" 'Cuz it seems like it's easily done if there's a need.

@klonos
Copy link
Member Author

klonos commented Nov 14, 2021

Not sure if all Dashboard-provided blocks would make sense being added anywhere else other than the Dashboard layout, but the reason for my comment above was that I had the need to be able to add a specific Dashboard block to the home layout.

@docwilmot
Copy link
Contributor

Sorry missed the mention here. We left off dashboard from the list of available contexts, for no proper reason whatsoever. That context should be available to any other layout, you're right, since we discussed, when planning the dashboard, that users should be able to use another layout as their own dashboard.

In fact in layout.contex.admin.inc line 81 if you simply delete 'dashboard' from the line if (!in_array($key, array('string', 'overrides_path', 'dashboard'))) {, the layout settings UI doesnt show that it works, but it does, without error. Dashboard then shows up in the list, and you can addd dashboard blocks to any layout with this added context, and the blocks show in the front end.

As it is now though, the only way dashboard context is available to any layout is by path, unfortunately, specifically admin/layout. And there isnt a hook_layout_context_info_alter() either.

So short term, dont think this is doable without hacking. Long term we should:

  • add 'dashboard' as an available context in the custom context UI
  • change the menu path for dashboard context to include a wildcards like admin/dashboard/%, dashboard/%, user/dashboard/% etc
  • and add a hook_layout_context_info_alter()

@klonos
Copy link
Member Author

klonos commented Nov 14, 2021

Thanks for the insight/summary @docwilmot 🙏🏼

Would you like me to create a separate issue for all that?

@jenlampton jenlampton changed the title Main page content block not available for the Home page layout. Add the main page content block to layouts that do not have "main page content" Mar 12, 2022
@jenlampton
Copy link
Member

jenlampton commented Mar 12, 2022

To fix this issue, and provide the MCB on the home layout, I suppose we could add a "home" path entry to system(or layout)_menu() with node_page_default() as the page callback. Side effects uncertain.

I'm not sure we should change this behavior.

If we provide a "main page content" block on a page that has no main page content, then that block would print nothing, so it would not show up at all. This might create an even more confusing experience than not being able to add the empty block to the page.

I've created #5539 to address the issue of what happens when people create the wrong type of layout by accident.

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

No branches or pull requests

8 participants