I'm creating a new custom theme for Drupal8, based on classy theme
I have 4 regions in MY_THEME
regions:
header: 'Header'
content: 'Content'
footer: 'Footer'
hidden_block: 'Hidden Blocks'
I don't need some blocks, such as Search, Powered by Drupal, Footer menu, User account menu and etc. I use region 'Hidden blocks' to place unused blocks into it. I saw this method in drupal8_zymphonies_theme.
I found topic:
http://drupal.stackexchange.com/questions/193386/how-to-assign-blocks-to...
there is answer for my question.
So my steps next:
1. I install MY_THEME
2. Place block in regions
3. Export config files and remove from it uuid and core config hash
for example breadcrumb block block.block.MY_THEME_breadcrumbs.yml file
langcode: en
status: true
dependencies:
module:
- system
theme:
- one_page_site_theme
id: one_page_site_theme_breadcrumbs
theme: one_page_site_theme
region: hidden_block
weight: 2
provider: null
plugin: system_breadcrumb_block
settings:
id: system_breadcrumb_block
label: Breadcrumbs
provider: system
label_display: '0'
visibility: { }
4. Place config files to MY_THEME/config/install directory
5. Uninstall my theme and clear all cache
6. Install theme
Then I go to block layout and saw that configs don't apply and all blocks placed in header and content regions. And hidden_block region does not contain any blocks.
How to resolve my issue? Thx for help.
Comments
It worked
This process seems to work fine for me.
I have a theme that extends the core seven theme. At first when I installed the theme, I would get a lot of blocks in the header region that I did not want. This is because I am getting all the blocks from the default theme (ie. Bartik). If my theme doesnt have a region that the default theme has then all the blocks from that region just get dumped in the top region.
After following the steps above, not only do the blocks that I did export appear in the correct region, but none of the extra blocks that I did not want appeared. So this works exactly the way I want.
Thanks!
If I don't need some default themes regions
Yes I understand that
But if I need only next regions in my theme and need assign block to hidden region.
So my theme isn't support Bartik's regions or regions of other theme
As you said function block_theme_initialize create copy of default theme block and if my custom theme don't have this region it assign the block to the theme's default region.
My question is - how I can assign block in hide region of my theme. This region does not present in based theme.
I see decision by next way. Create the first region - hide. In this case all 'unnecessary' blocks will assign to this region. But i think it not clear decision.
Step 4 is a mistake, you
Step 4 is a mistake, you shouldn't do this unless you're absolutly certain all dependancies are met. Intead you should place block config files in:
MY_THEME/config/optional
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Place for config files does not matter
The place for config files does not matter (and I did this place in dirrectory
MY_THEME/config/optional
- this article has detailed description https://www.drupal.org/docs/8/api/configuration-api/configuration-storag...), because when theme initialize (see my previous answer) called function block_theme_initialize, this function check regions in custom theme and if region does not exist in base theme (such in my case) it puts block to default theme region.My question is: Is it possible in custom theme create custom regions , which does not present in base theme and put into it blocks?
Wrong.
This is wrong. There are reasons why Drupal core has the config/optional directory!
Lets say you have block config for Search block, but in the site the Search module is uninstalled - when you try to install the theme you will get a site error with this message:
Unable to install theme_name, block.block.theme_name_search has unmet dependencies.
What you're talking about is something entirely different.
[Sheesh, sorry for the edits, typing too fast!!!]
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
You don't catch what I mean.
I understand what you talking about, but my question is another.
So, I have custom theme MY_THEME with the regions:
and I don't want to place Search block in my regions. I want disable it. And I do next steps:
I install my theme -> Go to block layout -> place Search block to Disabled -> Save blocks -> go to configuration manager and copy config of this block -> create file block.block.MY_THEME_search.yml put into it copied config -> save file in dir
MY_THEME/config/optional
After that I uninstall my theme, clear cache and install again. Go to block layout and see that Search block placed in Header region of my theme, but it has next config:
region: -1
means that block is disable.It's very strange, because from theme tutorial page:
But this configuration is
But this configuration is impossible if the block is disabled, when you view the block configuration export, status should be false. So this is simple:
Not really,
status: false
means the block is disabled.region: -1
places the block into the "disabled" area in the block configuation.Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I made a mistake in config file
Yes of course, the Search block has next config, I made mistake:
and path
MY_THEME/config/optional/block.block.MY_THEME_search.yml
But when I install MY_THEME and go to configuration manager I see next config:
Looks like config did't apply. And of course block placed in header region.
Must be some other issue (I
Must be some other issue (I have done this many times using status false etc), so sorry, but I'm not sure what is going on in your site. The config I use is basically nearly identical to yours (I usually hide the label, thats the only difference).
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.