Annotations
In the previous section we have actually already seen how annotations are added to an object and that they are basically just a python dictionary. But before this is possible, we need to add one line to the configure.zcml of keywordannotator:
<include package="zope.app.annotation" />
This directive loads another zcml directive which is in the zope software directory, in the file lib/python/zope/app/annotation/configure.zcml:
<adapter
for=".interfaces.IAttributeAnnotatable"
provides=".interfaces.IAnnotations"
factory=".attribute.AttributeAnnotations"
/>
This actually concludes our strategy. All the code and configuration is now in place to add those annotations to a WeblogEntry by adapting it if it implements or provides the IMaudio interface, which is added to it by a utility if if decides that the condition is met after an event takes places that is handled by an event handler. If you understood what I just wrote, then you are very smart. :)
Adding Annotations
At this point, if you look at the state of things on the Plone level, we can add a normal WeblogEntry and give it a keyword 'audio'. Then our code makes sure that it provides the IMaudio interface. And then it stops! There is not yet a way to actually put something in the annotations. But we can arrange that. First we install a new product: CMFonFive.
That product may get assimilated into the core of CMF itself some day (Plone is based on CMF, the Content Management Framework). But for now this extra product is needed for the following lines that we add in the configure.zcml of quadapter:
<browser:menu
id="object_tabs"
title="Object tabs" />
<browser:menuItem
for="Products.quadapter.interfaces.IMaudio"
menu="object_tabs"
title="Audio urls"
action="maudio_edit"
description="Edit form for audio urls"
permission="zope2.ManageProperties"
/>
This adds a menu item in the Plone site to the object tabs of any object that implements the IMaudio interface. When you add this code, restart your Zope instance, and look at a WeblogEntry that has one of the special words and thus provides the IMaudio interface, you will see a tab that links to the action maudio_edit.
At that point we are almost done. We now need to make an edit form for that tab, that calls the code that sets the Annotations for this object. If you know how to make an edit form in html, then you should be able to make this yourself, possibly with the use of the Archetypes product.
Viewing Annotations
When you have added those links in the annotation of a WeblogEntry, you also want to be able to see them when you actually look at a WeblogEntry in your browser. We can use one more Zope 3 technique for this: the BrowserView. Essentially this also is an adapter. We need to define a BrowserView in quadapter:
<browser:page
name="audio_entry_view"
for="Products.quadapter.interfaces.IMaudio"
permission="zope2.View"
allowed_interface="Products.quadapter.interfaces.IAudioWeblogView"
class=".browser.AudioWeblogView"
/>
This basically means that for an object providing the IMaudio interface we have a python class that gives us some functions to call in an html page template. In fact, we can now copy the file entry_macros.pt from Quills and add these lines at the right spot:
<tal:imaudio tal:define="view entry/@@audio_entry_view|nothing;"
tal:condition="view">
<metal:block use-macro="here/maudio_macros/macros/extratext" />
</tal:imaudio>
This uses a maudio_macros.pt file that gets the links from the object. Now when you view a normal WeblogEntry you just see the normal page that you would otherwise see. But when you view an entry with the IMaudio interface, for which you have added links with the edit form in the previous section, you will now see some extra text containing those links. The specifics are left as an exercise to the reader as they are just standard page template techniques, which should be familiar and which are not too interesting for this tutorial. If you do not get it working, contact me. Well, okay, I have just added them in the skins folder of quadapter.
