We customized the News Item-type and replaced the embedded image with an ExtendedReferenceField (we use a central image repository).
Is there a way to activate link integrity checking on that field so that when one tries to delete the image a warning is triggered?
(Yes, link integrity checking is enabled in @@editing-controlpanel and works just fine when I insert links and images in the content body).
Condensed code for the schemaextender field used:
from zope.interface import implements
from archetypes.schemaextender.interfaces import ISchemaExtender
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from archetypes.schemaextender.field import ExtensionField
from Products.Archetypes import atapi
from archetypes.referencebrowserwidget.widget import ReferenceBrowserWidget
class ExtendedReferenceField(ExtensionField, atapi.ReferenceField):
""" Extention reference field. """
class ImageReferenceExtender(object):
implements(ISchemaExtender, IBrowserLayerAwareExtender)
layer = IPackageSpecific
fields = [
ExtendedReferenceField(
name= 'imageref',
required = False,
multiValued=False,
allowed_types=('Image', ),
relationship='image',
keepReferencesOnCopy=True,
widget = ReferenceBrowserWidget(
...
)),
]
def __init__(self, context):
self.context = context
def getFields(self):
return self.fields
This happens in Plone version 3.3.6 as well as 4.1.6.
Link integrity works by adding references named
isReferencingbetween objects, but it only does this for HTML links within TextFields, whenever an object is modified.To support individual reference fields, you have 2 options:
Add
isReferencingrelationships whenever you add yourimagerelationship, remove them again when theimagerelationship is gone, using events or the extender. Link integrity will then kick in.Track the removal of an
imagerelationship as an integrity breach. You’d need to check if the referring object is being removed.Take a look at the handlers.py module of the
plone.app.linkintegritypackage. ThereferenceRemovedevent handler is called whenever any Archetypes reference is deleted. It updates theILinkIntegrityInfostorage, adding both source and target of aisReferencingrelationship, and this storage is consulted when handling content object deletion.Create a new event handler for your
imagereference and it’ll be handled in the same way; delete a referenced image and the link integrity warning will be raised:registered with ZCML: