If you're using the 'add' operation, and also using EntityOperationsDefaultAdminUIController to make an admin UI for your entity type, then you get warnings on the entity admin list page.

This is because the 'add' op handler adds certain properties to its menu item to make it appear as a local task at the admin list. Eg, at /admin/content/foo, which is an admin list of Foo entities, you see a local task menu link to add a new Foo entity. This mirrors the UI for nodes.

The problem is that the local task link is to /foo/add. We force it into appearing at /admin/content/foo by setting 'tab_root' and 'tab_parent' on its menu item. (This itself is done by a fairly hacky procedure, by the 'add' op handler calling into the admin UI controller -- see menu_item_make_task()).

This causes a problem because menu_local_tasks(), when checking access to local tasks and tabs, uses the menu map for the *current menu item* to build up the arguments to pass to the access callback. In other words, the path '/admin/content/foo' is used to build the arguments to pass to the access callback for 'foo/add'. Which is completely wrong. Which then means that in our case, the access logic in our op handler gets the path item 'foo' passed in for what it expects to be the path item in 'foo/add/BUNDLE'. If you have a bundle that matches your entity type, you happen to be okay. If you don't, or if your admin UI is at a path longer than '/admin/content/foo', or something else that prevents this happy coincidence, you get a warning.

It seems to me that local tasks are not meant to have paths that are outside of their parent page's path -- it goes against the assumptions that Drupal's menu system makes.

So therefore what should probably be done instead is have the admin UI controller have its own 'add' menu item, which is essentially a copy of the one for 'foo/add'.

Comments

joachim’s picture

Status: Active » Fixed
StatusFileSize
new8.46 KB

Fixed.

And this means ripping out the hacky menu_item_make_task(), which is a Good Thing.

Side note: I've added (very basic) tests for the admin UI, and I can't get assertLink() to work. One for a follow-up.

joachim’s picture

Title: local task on content admin link causes warnings » local task for 'add' on entity admin list causes warnings

  • Commit 8835323 on 7.x-1.x by joachim:
    Issue #2238793 by joachim: Fixed local task for 'add' on entity admin...

Status: Fixed » Closed (fixed)

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