I have a Plone 4 site where I currently use the following method to embed objects (e.g. images, videos, tables …) in user-editable HTML content:
transform
browser which takes HTML text and transforms all a
and img
elements which refer to an element by UID (i.e., which have an href="…/resolveuid/abc123…"
or src="…/resolveuid/abc123…"
).text
field and let that browser transform
it;TYPE2TEMPLATE
which has portal_type
keys and template_id
values;a
or img
which refers to an object by UID,
o = brain._unrestrictedGetObject()
t_id
is taken from the TYPE2TEMPLATE
dictmethod = o.unrestrictedTraverse(t_id)
a
or img
element.Now that I'm developing an additional customization package (which contains new object types, now using Dexterity), I wonder whether there is some more "plonish" way. Is there, for example, some embed
action?
i don't know of a package that does the same and what you're doing sounds sane to me ;-)
i just would use https://pypi.python.org/pypi/plone.outputfilters instead of your transform
BrowserView.
if it's possible to explicitly mark links that should not be auto-embedded (eg via span.noEmbed a.internal-link
selector) this could become a useful addon.
i guess for portal_type=='File' you'll need to check the mimetype too in order to decide if you're embedding a video file or something else...
other products i know of embed content outside of your plone site (eg. collective.embedly)
another approach would be a to use a tinymce plugin to genereate the proper embed html when editing the html-body of your page (i personally would not go this route because there are different tiny versions to support for 4.3 and 5.0 and we're not sure if tiny woun't be replaced as default editor in the future)