Friday, August 18, 2006

Componentising the content menu

I have an unstated personal vendetta for Plone 3.0 - make the UI more pluggable. There are a few places where people are forced to do very invasive template overrides because Plone doesn't provide any proper way for them to plug in the UI they want. This in turn makes us dependent upon having certain types of customisations in CMFPlone proper, rather than letting them be managed by add-on components. discouraging certain type of innovation in the wider community.

A big part of that will be viewlets - a way of composing snippets into a full page. Alec Mitchell did a ton of great work on making these work in Five, and I'm sure their impact will be felt in very positive way for Plone 3.0.

The other one is metadata - how many people would like to be able to apply a standard (perhaps required) field to every content type without having to sub-class every single one of them? At least for Archetypes, a solution is within reach, thanks to some great work by David 'whit' Morriss, which I adapted and used here. Daniel Nouri, the new Archetypes release manager, is interested in this as well, so with a bit of luck and work, we'll get that one done in time.

The last bit is a template with which I'm rather too familiar - global_contentmenu. This is the code that controls the green bar with the actions, display, add item and state menus.

Take a look at the code. This is a prime example of the stuff you should not do with ZPTs. There is more logic in there than in pretty much any other page template, it's brittle, it's completely untested, and it's hard to maintain. But more than that, if you want to add a new menu or change one of the existing ones, you have to override the entire template. LinguaPlone does this to get a translate menu. BernArticle does it, apparently, for who-knows-what reason. CompositePack apparently uses JavaScript DOM manipulation to get another item in there. Nice.

Now look at the bundle for PLIP142. This does a number of interesting things:
  • The menu is rendered as a content provider (the Zope 3 component that underpins viewlets) by means of a 'provider:' expression at the bottom of global_contentviews.
  • This invokes a view component that prepares a ZPT-friendly structure.
  • The rendering of this data structure is now sane. Compare this template with the old global_contentmenu.
  • All the logic is implemented in Zope 3 components. These can be tested! There are now 50-odd tests covering the logic that used to be in one template (scary...)
The components in this case use the Browser Menu infrastructure. This consists of one menu called plone.contentmenu which represents the horisontal bar. This has a number of menu sub-menu items representing each of the actions, display, add (aka factories) and workflow menus. Each of the sub-menu items in turn points to another menu that fetches the items to display in the drop-down. All of this is registered in ZCML.

Notice how the sub-menu items are implemented as adapters. This is because they need additional logic beyond what the standard Zope 3 subMenuItem ZCML directive can provide (and also because that directive doesn't seem to work in Five, at least it didn't in Zope 2.9). The implementations are found in menu.py.

It is possible to register your own menus or override existing menus simply by registering new components in any package. For example, you could:

  • Override the entire menu by providing a more specific adapter or an override for the plone.contentmenu content provider. See the bottom of configure.zcml and the adapts() specification for ContentMenuProvider - anything more specific than Interface could cause a different renderer altogether to be invoked.
  • Override a specific sub-menu item. Again, a more specific adapter registration could override the sub-menu items. The default items are simply registered for all content types, but you could choose to have a specific implementation of one of the menus for a specific content type.
  • Add a new sub-menu, either for all contexts or just those providing a given interface. Notice how the sub-menu item implementations all have an order attribute, and that they are ordered with gaps - 10, 20, 30, 40. Add a new sub-menu item and register it as providing IContentMenuItem with an order between any of those numbers, and you can control whether it appears before or after all the existing menus, or in-between two of them.
The work is not quite finished, and there will be a lot of testing to be done, but already the bundle functions for the majority of use cases. Specifically, what remains is:
  • Make the JavaScript warning on the Delete action work
  • Fix line breaks in the Display menu
  • Ensure the selected item in the Display menu is properly marked as such
  • Test with non-structural folders, folders with a single addable type, and with various combinations of permissions and roles to ensure the new menu behaves like the current one does.
We also need to decide whether existing customisations of global_contentmenu should be allowed to override the default or whether we break all of them. Alec nearly has me convinced that breaking existing customisations is the right thing to do, since any customised version would break any other product that used the "new style" customisation techniques outlined above, and since the existing template is just scary.

However, pending framework team review, I hope to see this in Plone 3.0. I'll miss having days like these trying to figure out how to make the Display menu work under various conditions with some serious TAL voodoo, though...

2 comments:

sexy said...

情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣用品,情趣,情趣,情趣,情趣,情趣,情趣,情趣,情趣,按摩棒,跳蛋,充氣娃娃,情境坊歡愉用品,情趣用品,情人節禮物,情惑用品性易購

免費A片,AV女優,美女視訊,情色交友,免費AV,色情網站,辣妹視訊,美女交友,色情影片,成人影片,成人網站,A片,H漫,18成人,成人圖片,成人漫畫,情色網,日本A片,免費A片下載,性愛

A片,色情,成人,做愛,情色文學,A片下載,色情遊戲,色情影片,色情聊天室,情色電影,免費視訊,免費視訊聊天,免費視訊聊天室,一葉情貼圖片區,情色,情色視訊,免費成人影片,視訊交友,視訊聊天,視訊聊天室,言情小說,愛情小說,AIO,AV片,A漫,av dvd,聊天室,自拍,情色論壇,視訊美女,AV成人網,色情A片,SEX

情趣用品,A片,免費A片,AV女優,美女視訊,情色交友,色情網站,免費AV,辣妹視訊,美女交友,色情影片,成人網站,H漫,18成人,成人圖片,成人漫畫,成人影片,情色網


情趣用品,A片,免費A片,日本A片,A片下載,線上A片,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人文章,成人影城,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,臺灣情色網,色情,情色電影,色情遊戲,嘟嘟情人色網,麗的色遊戲,情色論壇,色情網站,一葉情貼圖片區,做愛,性愛,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,美女交友,做愛影片

av,情趣用品,a片,成人電影,微風成人,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,愛情公寓,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,aio,av女優,AV,免費A片,日本a片,美女視訊,辣妹視訊,聊天室,美女交友,成人光碟

情趣用品.A片,情色,情色貼圖,色情聊天室,情色視訊,情色文學,色情小說,情色小說,色情,寄情築園小遊戲,情色電影,色情遊戲,色情網站,聊天室,ut聊天室,豆豆聊天室,美女視訊,辣妹視訊,視訊聊天室,視訊交友網,免費視訊聊天,免費A片,日本a片,a片下載,線上a片,av女優,av,成人電影,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,成人文章,成人影城,成人網站,自拍,尋夢園聊天室

will said...

A片,A片,成人網站,成人漫畫,色情,情色網,情色,AV,AV女優,成人影城,成人,色情A片,日本AV,免費成人影片,成人影片,SEX,免費A片,A片下載,免費A片下載,做愛,情色A片,色情影片,H漫,A漫,18成人

a片,色情影片,情色電影,a片,色情,情色網,情色,av,av女優,成人影城,成人,色情a片,日本av,免費成人影片,成人影片,情色a片,sex,免費a片,a片下載,免費a片下載

情趣用品,情趣用品,情趣,情趣,情趣用品,情趣用品,情趣,情趣,情趣用品,情趣用品,情趣,情趣

A片,A片,A片下載,做愛,成人電影,.18成人,日本A片,情色小說,情色電影,成人影城,自拍,情色論壇,成人論壇,情色貼圖,情色,免費A片,成人,成人網站,成人圖片,AV女優,成人光碟,色情,色情影片,免費A片下載,SEX,AV,色情網站,本土自拍,性愛,成人影片,情色文學,成人文章,成人圖片區,成人貼圖

情色文學,色情小說,色情,寄情築園小遊戲,AIO交友愛情館,情色電影,一葉情貼圖片區,色情遊戲

言情小說,情色論壇,色情網站,微風成人,成人電影,嘟嘟成人網,成人,成人貼圖,成人交友,成人圖片,18成人,成人小說,成人圖片區,微風成人區,成人網站,免費影片,色情影片,自拍,hilive,做愛,微風成人,微風論壇,AIO