Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2254: Add prefixes to various block titles in the 'Add block' dialog #4746

Open
wants to merge 5 commits into
base: 1.x
Choose a base branch
from

Conversation

klonos
Copy link
Member

@klonos klonos commented May 12, 2024

@backdrop-ci
Copy link
Collaborator

Related to: backdrop/backdrop-issues#2254

}
// Custom menus are coming from menu_block_info(), while system-defined menus
// from system_block_info().
if ($block_module == 'menu' || ($block_module == 'system' && isset($block_info['type']) && $block_info['type'] == 'menu')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this approach, it's a bit messy. Can we leave this as simply $block_module == 'menu' and then add the same prefix in system module for the menu blocks added?

// Custom menus are coming from menu_block_info(), while system-defined menus
// from system_block_info().
if ($block_module == 'menu' || ($block_module == 'system' && isset($block_info['type']) && $block_info['type'] == 'menu')) {
$block_info['info'] = t('Menu: @block_title', array('@block_title' => $block_info['info']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like using : more than -. Let's update the Dashboard blocks to use a :: instead ✅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR already does that @jenlampton ...did I miss a spot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you mean: make the change in the dashboard_block_info() hook implementation. Gotcha 👍🏼

// Make sure to account for blocks intended for use in dashboards that are not
// necessarily provided by the Dashboard module itself.
if ($block_module == 'dashboard' || (isset($block_info['required contexts']) && in_array('dashboard', $block_info['required contexts']))) {
$block_info['info'] = t('Dashboard: @block_title', array('@block_title' => $block_info['info']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for dashboard, the prefix needs to be added in Dashboard module.

@@ -491,6 +491,12 @@ function menu_reset_item($link) {

/**
* Implements hook_block_info().
*
* This returns the blocks for any custom menus created on the site (as opposed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why the Menu module was renamed Menu UI in Drupal 8. It doesn't provide the ability to have menus, only the UI to create them :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have now realized this 👍🏼

@@ -2595,6 +2595,12 @@ function system_user_timezone(&$form, &$form_state) {

/**
* Implements hook_block_info().
*
* Note that this also returns the system-defined menu blocks (as opposed to any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, as any module can define menu blocks. There's nothing special about System module. (I do like the new docblock for Menu module though, because people will probably look there first for menu blocks.

// types of blocks provided by the System module.
// @todo: should this be provided by a system_layout_context_info()
// implementation instead or be a 'required contexts' key?
'type' => 'menu',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be an API change. Let's not do this. Instead the 'Menu:' prefix in the name.

@@ -2908,6 +2908,7 @@ class MenuBlockTestCase extends BackdropWebTestCase {
* Test Menu Block functionality.
*/
function doMenuBlockTests($menu_name, $menu_title) {
$add_menu_block_link = 'Menu: ' . $menu_title;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this if Menu: is in the $menu_title; ;)

@@ -2931,7 +2932,7 @@ class MenuBlockTestCase extends BackdropWebTestCase {
$this->clickLink(t('Remove'), 1);
// Add a block to the sidebar (the fourth region).
$this->clickLink(t('Add block'), 3);
$this->clickLink($menu_title);
$this->clickLink($add_menu_block_link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to revert this :)

@@ -85,7 +85,10 @@ class views_plugin_display_block extends views_plugin_display {
$info = $this->get_option('block_description');
}
else {
$info = t('View: @view (@display)', array('@view' => t($this->view->get_human_name()), '@display' => t($this->display->display_title)));
$info = t('View: @view (display: @display)', array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it! The prefix comes from views module ✅

Copy link
Member Author

@klonos klonos May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't actually add the View: prefix here - I only added the display: prefix. The View: prefix was actually added already, which is actually causing problems with duplicated View: View: prefixes.

Because this is only added to certain views blocks (if there is no block_description added in the block display), you can end up with some views-provided blocks that have the prefix, and some that don't 😞 ...I had to add logic in _layout_block_add_block_title_prefix() to ensure that there aren't duplicated prefixes, while at the same time making sure that all views-provide blocks had the Views: prefix in the "Add block" dialog (so that they aren't "scattered" by the alphabetical sorting).

Copy link
Member Author

@klonos klonos May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...the reason why I added the display: prefix by the way is that we anded up with things like this (that is before any changes in this PR, and that is only one of the examples that I randomly found):
View: Layout Context Test (User account) (Block)

In the above title, you don't know what the strings in the brackets are. Which one is the name of the display? My change adds the display: prefix, so you get this instead:
View: Layout Context Test (User account) (display: Block)

@dragonbot
Copy link
Collaborator

Tugboat has finished building a preview for this pull request!

Website: https://pr4746-l8prdkpjjauybkjmhzmibcw6k6b91dv8.tugboatqa.com/
Username: admin
Password: bfc90a4b2564

This preview will automatically expire on the 13th of July, 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants