[kupu-dev] Creating Archetype Reference When Creating Internal Link In Kupu

Duncan Booth duncan.booth at suttoncourtenay.org.uk
Mon Nov 6 10:03:58 CET 2006


Tim Knapp <duffyd at kokorice.org> wrote:

> For a client project, we were thinking one potential way of keeping
> track of 'broken internal links' would be to modify kupu so that it
> creates a reference in the reference_catalog each time you create an
> internal link, i.e. via the link drawer (also potentially the back ref
> could be deleted when the 'red cross' is clicked). This would allow us
> to create an object action that lists all pages that link to the current
> object (by doing a getBackReferences). Does this kind of functionality
> sound feasible?

Yes it is perfectly feasible. We list all forward and backward references 
from an object on our workflow tab, and we use the references to 
automatically workflow certain types of object (images, link objects) which 
are referenced from the html when the main document is workflowed. See the 
kupu documentation (documentation tab in the configlet or 
kupu/doc/PLONE2.txt):

References from HTML text
-------------------------
Kupu can be made to store archetypes references for any HTML field.
You can use these references for a variety of purposes, e.g. when
publishing a document you could automatically publish all the
contained images.

To enable this feature for a particular field, you need to  change the
type of the field from ``TextField`` to ``ReftextField``::

    from Products.kupu.plone.ReftextField import ReftextField

then define your field as::

        Reftextfield('bodyCopy',
            required=1,
            searchable=1,
            relationship='bodyCopy',
            widget=RichWidget
            (description='Please paste or type your article here',
                label='Body Copy',
                parastyles=(
                 ('div|pullQuote','Pull Quote'),
                 ('div|Caption','Caption'),
                 ('div|contactInformation','Contact Information'),
                 ('div|notesToEditors','Notes to editors'),
                ),
            ),
        ),

the ``ReftextField`` type is identical to the existing ``TextField``
except that it also extracts references from the HTML text whenever
the field is saved. The relationship used to hold the references may
be specified as shown, but if omitted it defaults to the field name.

If the HTML contains an invalid reference, e.g. a link to an object
that has since been deleted, ``ReftextField`` will completely ignore
that link.






More information about the kupu-dev mailing list