The "Add a block" link toggles the user between seeing the list of available blocks and the actual homebox page. This is confusing (at least it was for me at first), because when you are at the page that lists available blocks to add and you add and save them, there's really no indication that you have to click on that same link to go back to the page. What should happen is that the link text should change depending on the page content, so that when the available blocks are added, the link text changes to something like "Back to page".

Currently the text of the link is hardcoded in homebox.tpl.php:

<div id="homebox" class="<?php print $classes ?>">
  <?php if ($user->uid): ?>
    <div id="homebox-buttons">
      <?php if (!empty($add_links)): ?>
        <a href="javascript:void(0)" id="homebox-add-link"><?php print t('Add a block') ?></a>
      <?php endif; ?>
      <?php print $save_form; ?>
    </div>
  <?php endif; ?>

and then this code in homebox.js alternatively shows/hides the #homebox-add div when clicked, which contains the markup for each available block:

$homebox.find('#homebox-add-link').click(function () {
  $homebox.find('#homebox-add').toggle();
});

and shoves the actual blocks on the page aside to make room for them.

I will write a patch for this, but I'm unsure where/how to do this. My thought is to do it in the jQuery so that when the link is clicked and the .toggle method is used, that the link text is toggled accordingly. After doing some searching, I came up with this:

$homebox.find('#homebox-add-link').click(function(ev) { 
  $('#homebox-add').toggle(); 
    this.html(($('#homebox-add-link').text() == 'Add a block') ? 'Back to page' : 'Add a block');
  })

but it's not working. Any thoughts from a jQuery guru?

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wonder95’s picture

Title: Change "Add a block" text depending on content » Change "Add a block" text depending on context
Status: Active » Needs review
FileSize
966 bytes

Got the code figured out to change the link text. Patch is attached.

wonder95’s picture

Patch re-rolled to be consistent with existing .find.

drumm’s picture

Status: Needs review » Needs work

The surrounding changes to JS syntax should not be done, they are correct as-is:

  • The space after function.
  • The semicolon at the end.

Any English text should run through Drupal.t() so it is translatable.

Anybody’s picture

Status: Needs work » Closed (won't fix)

Please create a new Drupal 8+ (3.0.x) issue, referencing this one, if this is still relevant for Drupal 8+ (3.0.x).

As this issue was created for Drupal 7 which is close to EOL and won't receive any new features here anymore (unless someone implements them or sponsors development) I'm closing this issue for cleanup now.

If anyone works on this or has a solution, feel free to reopen! :)
Thank you.