I used to the following in a drupal 7 theme.

function mytheme_preprocess_block(&$variables) {
    // Add class to block titles.
    $variables['title_attributes_array']['class'][] = 'block-title';
    if ($variables['block']->region == 'header_top' ||
        $variables['block']->region == 'search_box' ||
        $variables['block']->region == 'footer') {
        $variables['title_attributes_array']['class'][] = 'element-invisible';
    }
}

Tried several alternatives including preprocess_layout without any success.

Most helpful answers

Layouts and themes are different in Backdrop CMS and some of the $variables attributes you are looking for are not there; that is why your function is not working. What I suggest is to install the Devel module (if you haven't already) and do the following:

function mytheme_preprocess_block(&$variables) {
  dpm($variables);
}

This will show you what is available. I think you will be able to do it by comparing the $variables['block']->uuid to the items in $variables['layout']->positions and then using that to adjust $variables['block']->settings['title_display']

Comments

Just to be clear, you are looking to proactively hide all block titles within a certain region?

Hiding the block title on a specific block can usually be done through the UI, but I think you are looking for something more general. 

I don't have an answer yet.

yes, but using the ui is cumbersome and puts on extra unnecessary divs.

Olafski's picture

Unfortunately, I'm not familiar with preprocess functions. If you're open to use a CSS workaround, you could do something like this:

.header-top .block-title,
.search_box .block-title,
.footer .block-title {
 position: absolute !important;
 clip: rect(1px, 1px, 1px, 1px);
 overflow: hidden;
 height: 1px;
 width: 1px;
}

The CSS definition is borrowed from the element-invisible class.

As you don't seem to be getting anywhere with the other suggestions, I suggest you try this.  You also try with the same selectors, but just display: none; inside.

Layouts and themes are different in Backdrop CMS and some of the $variables attributes you are looking for are not there; that is why your function is not working. What I suggest is to install the Devel module (if you haven't already) and do the following:

function mytheme_preprocess_block(&$variables) {
  dpm($variables);
}

This will show you what is available. I think you will be able to do it by comparing the $variables['block']->uuid to the items in $variables['layout']->positions and then using that to adjust $variables['block']->settings['title_display']

when i check the classes, i found inside Layout class:

  /**
   * The main array of configured blocks, keyed by a generated ID per instance.
   *
   * @var Block[]
   */
  var $content = array();

So, i think it should be preprocess_layout rather than block. But then, i dont know what to do.

You could also do a similar thing in hook_preprocess_layout, just a slightly different order: get all the block ids from the positions you are interested in, then access those block objects to change the title_display setting.

Do a similar call to look at the $variables array. To access an object child, do $variables['object']->child; to access an array child do $variables['object']['child'].

 

Those are nulls, and ive been checking every variable in both layout and block but there is nothing easy to edit.

in layout:
    foreach ($variables['layout']->content as $key => $object) {
        // 1. Check if the 'style' object exists, and then check if 'settings' exists inside it
        if (isset($object->style) && isset($object->style->settings['title_classes'])) {
            
            // 2. Access the field using object syntax for 'style' and array syntax for 'settings'
            $my_field_value = $object->style->settings['title_classes'];
            
            dpm($my_field_value, "Field value for item: " . $key);
        } else {
            dpm("Field or style settings not found for item: " . $key);
        }
    }

the title_classes is only available if the modules style is "dynamic", it is null if it is "default"

There is the "content", but it is set to private.

This should be easier to do.