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

yanniboi’s picture

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!

vadim.jin’s picture

Yes I understand that

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.

But if I need only next regions in my theme and need assign block to hidden region.

regions:
  header: Header
  content: Content
  footer: Footer
  hide: Hiding blocks

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.

Jeff Burnz’s picture

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

vadim.jin’s picture

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?

Jeff Burnz’s picture

The place for config files does not matter

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!!!]

vadim.jin’s picture

I understand what you talking about, but my question is another.

So, I have custom theme MY_THEME with the regions:

regions:
  header: Header
  content: Content
  footer: Footer

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:

langcode: en
status: true
dependencies:
  module:
    - search
  theme:
    - MY_THEME
id: MY_THEME_search
theme: MY_THEME
region: -1
weight: -5
provider: null
plugin: search_form_block
settings:
  id: search_form_block
  label: Search
  provider: search
  label_display: visible
visibility: {  }

region: -1 means that block is disable.

It's very strange, because from theme tutorial page:

Any blocks that were in regions which no longer exist (because you didn't define them) will now be disabled - specifically if you edit THEMENAME.info.yml and rebuild the cache with drush cr

Jeff Burnz’s picture

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:

status: false 
region: '-1'
region: -1 means that block is disable.

Not really, status: false means the block is disabled. region: -1 places the block into the "disabled" area in the block configuation.

vadim.jin’s picture

Yes of course, the Search block has next config, I made mistake:

langcode: en
status: false
dependencies:
  module:
    - search
  theme:
    - MY_THEME
id: MY_THEME_search
theme: MY_THEME
region: '-1'
weight: -6
provider: null
plugin: search_form_block
settings:
  id: search_form_block
  label: Search
  provider: search
  label_display: visible
visibility: {  }

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:

uuid: 8c7c3679-9644-4048-a0c9-070de6fcca3b
langcode: en
status: true
dependencies:
  module:
    - search
  theme:
    - MY_THEME
_core:
  default_config_hash: za-39d5WDUg6XvbyqSnuVYEeq6QM4qKJxW8MnoAha5A
id: MY_THEME_search
theme: MY_THEME
region: header
weight: -1
provider: null
plugin: search_form_block
settings:
  id: search_form_block
  label: Search
  provider: search
  label_display: visible
visibility: {  }

Looks like config did't apply. And of course block placed in header region.

Jeff Burnz’s picture

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).