0

I have a very odd problem that cropped up yesterday on one my sites. The site is Drupal 7 with the stock toolbar module installed. When you access the site for the first time logged in as an admin user, the Content menu link does not work. All the other menu links work fine. When you go to the Structure page next, the Content menu works correctly.

Looking at the source, the A tag for the Content menu does not have an HREF attribute. All the other menu links do. When you go to the Structure page, the Content menu has an HREF attribute as expected.

I looked at the menu_links table and everything looks good.

I ran debug through the toolbar.module and the array data is correct.

I ran debug into the toolbar.tpl.php file calling render($toolbar['toolbar_menu']). The array data is correct.

I'm now looking to see what else might be causing the HREF to "disappear" from the Content menu.

Has anyone seen this before?

The first commenter mentioned looking at the static page source (great idea...DevTools has made me lazy ;) )

<li class="menu-9 path-admin-content">
<a href="/admin/content" id="toolbar-link-admin-content" title="Find and manage content.">
<span class="icon"></span>Content 
<span class="element-invisible">(Find and manage content.)</span></a></li>

So the HREF is in the A tag. I'm looking at all the Javascript on the site now.

** UPDATED ** I added the following code (from http://addyosmani.com/blog/mutation-observers/):

var observer = new MutationObserver(function (mutations) {
  // Whether you iterate over mutations..
  mutations.forEach(function (mutation) {
  // or use all mutation records is entirely up to you
    var entry = {
      mutation: mutation,
      el: mutation.target,
      value: mutation.target.textContent,
      oldValue: mutation.oldValue
   };
   console.log('Recording mutation:', entry);
  });
});
var options = {
  childList: true,
  attributes: true,
  characterData: true,
  subtree: true,
  attributeOldValue: true,
  characterDataOldValue: true,
  attributeFilter: null
};
var target = document.querySelector('#toolbar-link-admin-content');
observer.observe(target,options);

This is the output which confirms that something is modifying the DOM.

Recording mutation: Object {mutation: MutationRecord, el: a#toolbar-link-admin-content, value: "Content (Find and manage content.)", oldValue: "/admin/content"}
Recording mutation: Object {mutation: MutationRecord, el: a#toolbar-link-admin-content, value: "Content (Find and manage content.)", oldValue: ""}

How do I go about finding what is causing the change? What code fired the observer?

  • View the page source (statically, not in dev tools) - is the href in there? If so, there's javascript acting on that link. If not, something is acting on the rendered output of the page or toolbar template – Clive Jan 6 '15 at 16:37
  • @Clive Thanks for the comment. I edited the OP so that I could include the source code. – spdaly Jan 6 '15 at 16:57
  • No worries - you should be able to find the culprit by adding a bit of JS yourself, using Mutation events – Clive Jan 6 '15 at 16:58
  • @Clive I edited the OP to include the JS code I installed to determine if the A tag is being modified. It is. How do I go about finding what did it? Anything better than just searching the JS files? I don't see anything in the call stack. – spdaly Jan 12 '15 at 18:09
0

I found the answer to my original problem.

I went through the .info file and commented out JS files until the console no longer reported a mutation event. Turns out that there was some odd JS code:

jQuery( "li:nth-of-type(2) > a" ).removeAttr("href");

The selector is too vague. Guess what number the LI containing the Content menu is? It's 2! And this little bit o'code took the HREF right off!

Thanks to @Clive for suggesting mutation observers. Learned a lot from this bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.