I have defined a path to a section using the menu path "tools" and field_tools_help() is inserting this:

Apply some or all fields of the current bundle to other bundles by copying the field instances.

I guess just a count on the args() would be enough:

  if ($args_reverse[0] == 'tools' && count($args_filtered) >= 3) {

This is a fairly generic keyword which would probably match other modules URLs... I was thinking menu_get_item() could be used, but nothing instantly obvious is returned to use without parsing the page callback / args. A bit verbose but maybe:

// Someone had the stupid idea to allow saving objects in the callbacks, bloating the cache and generating stale data... anyways...
if (!empty(empty($item['page_arguments'][0])) && is_scalar($item['page_arguments'][0])) {
  switch ($item['page_callback'] . ':' . $item['page_arguments'][0]) {
    case 'drupal_get_form:field_tools_bundle_fields_clone_from_form':
      return 'This is really the tools page!';
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

Issue summary: View changes
Alan D.’s picture

BTW, one menu path that this incorrectly targets is: admin/reports/fields/tools

joachim’s picture

> BTW, one menu path that this incorrectly targets is: admin/reports/fields/tools

LOL!

Thanks for reporting this and doing some digging.

IIRC this is shown on paths that will have a bundle argument in them somewhere: admin/structure/whatever/BUNDLE/fields/tools, no? Could we check $args_reverse[2ish] and see if that's the name of a bundle?

Alternatively, we could get the list of ALL field admin paths out of hook_entity_info() -- in [bundles][admin][path] -- and just see if we're in that list.

Alan D.’s picture

maybe a simple regex? less chance of conflict (but still possible)

  // Try to limit to field tool menu paths only.
  $menu_tab_root = menu_tab_root_path();
  if (preg_match('/\/%\/tools([\/clone\-from|clone\-to|export|import]+)$/i', $menu_tab_root)) {
    drupal_set_message('is one of tool sub-tabs');
  }
  if (preg_match('/\/%\/[fields|groups]+\/%\/[clone|export]+$/i', $menu_tab_root)) {
    drupal_set_message('[fields|groups]/%/export or fields/%/clone');
  }

Or even better, maybe the menu item :)

  $menu_item = menu_get_item();
  if (isset($menu_item['include_file']) && preg_match('/\/field_tools\.admin\.inc$/', $menu_item['include_file'])) {
    drupal_set_message('Has include');
  }
Alan D.’s picture

So using the menu item, something like this (leaving you to fill the blanks)?

  $menu_item = menu_get_item();
  if (isset($menu_item['include_file']) && preg_match('/\/field_tools\.admin\.inc$/', $menu_item['include_file'])) {
    $args = $menu_item['original_map'];
    if (count($args) > 3) {
      $args_reverse = array_reverse($args);
      if ($args_reverse[0] == 'tools' || $args_reverse[1] == 'tools') {
        switch ($args_reverse[0]) {
          case 'tools':
            // default tab
            break;
            
          case 'import':
            // ...
            break;
        }
      }
      else {
        switch ($args_reverse[0] . ':' . $args_reverse[2]) {
          case 'fields:export':
          case 'groups:export':
            break;
        }
      }
    }
  }
joachim’s picture

Status: Active » Fixed
FileSize
1.64 KB

Committing this patch.

  • Commit 0db55a8 on 7.x-1.x by joachim:
    Issue #2228669 by joachim: Fixed hook_help() targeting any path ending...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.