For some reason, the block module prints the title (subject) directly out of the block object

<?php if ($block->title): ?>
  <h2<?php print $title_attributes; ?>><?php print $block->title ?></h2>
<?php endif;?>

instead of having a nice, easy-to-read title variable for use in the block template, like nodes.

<h2<?php print $title_attributes; ?>>
  <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
</h2>

Also related #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer.

Comments

jenlampton’s picture

Status: Active » Needs review
Issue tags: +Novice
StatusFileSize
new1.23 KB

The more I think about this, I think we should backport it to 7 too. All old themes will still work since block will still be available in the template files for printing the old way, but we can still make new people happy by being consistent :) win win!

jenlampton’s picture

Issue summary: View changes

updated indenting

Status: Needs review » Needs work

The last submitted patch, provide_block_title_for_template-1591832-1.patch, failed testing.

nielsonm’s picture

Here's the patches for D8 and a backport for D7.

nielsonm’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: -Novice, -consistency

The last submitted patch, provide_block_title_for_template-1591832-3.patch, failed testing.

nielsonm’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Novice, +consistency

The last submitted patch, provide_block_title_for_template-1591832-3.patch, failed testing.

mjonesdinero’s picture

Assigned: Unassigned » mjonesdinero
mjonesdinero’s picture

Here's an updated patch for D8..

mjonesdinero’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, provide_block_title_for_template-1591832-9.patch, failed testing.

mjonesdinero’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB

another update

Status: Needs review » Needs work

The last submitted patch, provide_block_title_for_template-1591832-12.patch, failed testing.

mjonesdinero’s picture

Status: Needs work » Needs review
StatusFileSize
new1.52 KB

another format..hopefully this will be okie

Status: Needs review » Needs work

The last submitted patch, provide_block_title_for_template-1591832-14.patch, failed testing.

mjonesdinero’s picture

Assigned: mjonesdinero » Unassigned
Status: Needs work » Needs review
mjonesdinero’s picture

hopefully this one will work now..sorry for to many failed this just want to make my first commit in d.o

Status: Needs review » Needs work

The last submitted patch, provide_block_title_for_template-1591832-17.patch, failed testing.

mjonesdinero’s picture

Status: Needs work » Needs review

ops, seems i have to study more before attempting a patch again..

mjonesdinero’s picture

Another try.. test this in my clone d8 in my local..hope this will be okay now

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

Works great for me, thanks for working on the patch :)

catch’s picture

Assigned: Unassigned » David_Rothstein
Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs backport to D7

How does this fit in with #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer?

Not sure if this is backportable or not - it's a "data structure addition", if it is then I don't object to it going into 8.x first, but assigning to David since I'd rather go with #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer for 8.x and close this altogether if not.

David_Rothstein’s picture

Assigned: David_Rothstein » Unassigned

As much as I'd like to see this in Drupal 7, I'm not sure it's actually safe for backport. The first part of the patch is a "data structure addition", but the second is really a "data structure change". It replaces $block->subject with $title assuming they're the same thing, but they could easily have been altered along the way.

For example, what if someone has code like the following (I see this kind of thing pretty often):

function MYMODULE_preprocess_block(&$variables) {
  // Alter the block's title before printing.
  if ($variables['block']->module == 'some_module' && $variables['block']->delta == 'some_delta') {
    $variables['block']->subject = t('@subject, specially prepared for you, @name!', array(
      '@subject' => $variables['block']->subject,
      '@name' => format_username($GLOBALS['user']),
    ));
  }
}

This patch will break that, because the alteration to $block->subject will never be used in the template.

mjonesdinero’s picture

So, guys what are we going to do with this?
Thanks for your feedback here,
I am a beginner and hope to have my first commit in drupal.

David_Rothstein’s picture

I'm sure it will happen soon, @mjonesdinero - good luck!

I think the first half of the above patch (which just makes the 'title' variable available) is safe for Drupal 7, if we only wanted to do that... It's less exciting if we can't actually use it in the core templates, but at least we could document its availability. Not sure if it's actually worth doing that.

Otherwise, unless my example above is wrong, we can't do much here for Drupal 7, but for Drupal 8, the patch at #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer is definitely a good way to go and a more comprehensive solution to the problem, and that patch still needs people to help work on it a bit more.

The change to a straight $title in the template (rather than $block->title) in Drupal 8 could either happen as part of that issue or here as a followup, I guess.

mjonesdinero’s picture

@David_Rothstein thanks for that feedback.

this will add some knowledge on my self.

David_Rothstein’s picture

It occurred to me that another way to achieve the goal of this issue (in Drupal 7) might be something like #1158090: Separate usage of hide(), render(), and other template features from print statements to enable non-developers to create themes . Since that issue would move all the ugly logic in PHP templates to the top of the file, out of the way of the HTML, and something like $title = $block->subject; could definitely go at the top with the rest of the ugly stuff, so that $title could then be used in the actual main part of the core template.

That's a big issue, and I had been meaning to get back to working on it at some point, but then I started maintaining Drupal core which took up my time instead :)

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs backport to D7

I still think this and #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer are two separate issues. That other one is renaming the thing everywhere it exists, but if we stop there then the block template will still print it's subject/title directly from the object instead of using a nice friendly variable. So for D8, I think we should pursue this solution. (changing status back)

For D7, maybe we should hold off until we have a chance to work on #1158090: Separate usage of hide(), render(), and other template features from print statements to enable non-developers to create themes but yeah, if we can get all the complex structures turned into strings in the template files themselves, then changes made in a theme's preprocessor would still cary across - and this issue won't even need a backport. (removing tag)

mjonesdinero’s picture

@jenlampton
Thanks again with your feedback..so what are the next step that we will make with this issue?

webchick’s picture

Assigned: Unassigned » catch

I'm going to throw this in catch's pile, as I'm not sure exactly what he wants to do here.

catch’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Since David doesn't think this can be backported, I'm going to mark this as duplicate of #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer, hopefully we can get the patch over there moving.

catch’s picture

Issue summary: View changes

change related text