Looking through Menu Block while sorting out some "active-trail" issues, I came across this code

    if (!empty($menu_item['in_active_trail'])) {
      if (!empty($menu_item['localized_options']['attributes']['class'])) {
        $menu_item['localized_options']['attributes']['class'][] = 'active-trail';
      }
      else {
        $menu_item['localized_options']['attributes']['class'][] = 'active-trail';
      }
    }

You'll notice that the code is identical inside the if and inside the else, so the test is doing nothing. I assume this is some legacy code, but it could be that something else was intended. So I'm attaching a patch that cleans up the code, but the maintainers will know whether there's a logic problem that needs fixing.

if (!empty($menu_item['in_active_trail'])) {
  $menu_item['localized_options']['attributes']['class'][] = 'active-trail';
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ergophobe’s picture

Status: Active » Needs review

PS, this is based on a git pull of a few minutes ago and there is no diff between 7.x-3.x and 7.x-2.x, so despite my file name, it should apply equally to either branch.

othermachines’s picture

Status: Needs review » Needs work

That statement is checking whether the variable exists, so the change should probably be

    if (!empty($menu_item['in_active_trail'])) {
      if (!empty($menu_item['localized_options']['attributes']['class'])) {
        $menu_item['localized_options']['attributes']['class'][] = 'active-trail';
      }
      else {
        $menu_item['localized_options']['attributes']['class'] = array('active-trail');
      }
    }
Dave Reid’s picture

Status: Needs work » Needs review
FileSize
764 bytes

Actually we can just set it normally, because $menu_item['localized_options'] is always an array: http://3v4l.org/CMSU6

Status: Needs review » Needs work

The last submitted patch, 3: 2194115-simplify-class-setting.patch, failed testing.

Dave Reid’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev

Status: Needs work » Needs review

The last submitted patch, menu_block-7.x-3x-remove-extra-conditional.patch, failed testing.

  • Dave Reid committed b2dbf40 on 7.x-2.x
    Issue #2194115 by ergophobe, Dave Reid: Simplified setting active-trail...
Dave Reid’s picture

Status: Needs review » Fixed

Committed #3 to 7.x-2.x.

  • Dave Reid committed b2dbf40 on 7.x-3.x
    Issue #2194115 by ergophobe, Dave Reid: Simplified setting active-trail...
ergophobe’s picture

Thanks Dave for cleaning and committing.

I don't really care about credit on a patch like this, but I've noticed that even though committers often go to the trouble to add me in the commit message, it rarely shows up as one of my commits in my profile. Do you know why that is?

[edit - I think I know why - to make it easy for committers to give you credit, you should use git format-patch but I always just use git diff > filename.patch. As per https://www.drupal.org/node/1146430

Dave Reid’s picture

Because there were more than two people involved with submitting patchs, I don't usually attribute commits (but still mention in the commit message). If I had been able to use your patch as-is, I do always use attribution.

Dave Reid’s picture

Hrm, I now see that our patches were pretty much identical. It needed a re-roll since it no longer applied, but I probably *should* have attributed it to you. My apologies about that.

ergophobe’s picture

Dave, my patch was so simple and represented no real work. I was not at all miffed that I didnt' get credited.

I have done some patches that represented fairly significant work and don't get credit and others like this that basically fix a typo and I have sometimes gotten credit. I was just trying to understand why.

I certainly did not mean any reproach - you do so much for the community already that I hesitated to even mention it here, but was just curious. Between your answer and the link I had above I have a better understanding.

Thanks for the response and thanks, belatedly for the useful modules and zillion patches you've done. It is deeply appreciated.

Status: Fixed » Closed (fixed)

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