For one of my recipes, I'm adding a block programmatically in a hook.install function to four layouts. After adding the block, the title display is set to 'default' and I would like to set it to 'none."

Normally, I could change config settings in this way. However, these newly added blocks have hash numbers in path that are random, so this code does not work.

Is there a better way to change this config or how do I find the hash to build the proper path?

Again, the following does not WORK, because the hash is new each time.

    config_set('layout.layout.home', '', 'none');
    config_set('layout.layout.default', '', 'none');
    config_set('layout.layout.projects', '', 'none');
    config_set('', '', 'none');


I got some help with this in office hours today. I was adding the block in question to the layout with this command.

$default_layout->addBlock('mini_layouts', 'footer_mini_layout', 'footer');

By capturing the results in a variable, like this I would have access to the block hash or UUID in this variable $default_block->uuid:

 $default_block = $default_layout->addBlock('mini_layouts', 'footer_mini_layout', 'footer');

I was then able to do a config_set that looks like this:

config_set('layout.layout.projects', 'content.' . $default_block->uuid . '.data.settings.title_display', 'none');

In the last comment, I showed how I was able to access the uuid for a block immediately after saving the block. I'm now trying to figure out how to find the uuid for a block that already exists.

Any thoughts?

Thanks to @hosef, @docwilmot, and @argiepiano for tips and actual code to try, I ended up with the following which worked for me.

    $home_layout = layout_load('home');
    // loops through blocks in "content" region looking for portfolio_projects-block_1.
    foreach ($home_layout->content as $block_id => $block_info) {
      if ($block_info->delta == 'portfolio_projects-block_1') {
        // Once found, remove it.
    // Replace with alternative block
    $home_layout->addBlock('views', 'portfolio_projects-block', 'content');