How to customize dexterity-through-the-web-content view? - plone

I created a content in my Plone 4.3 site (no grok here) with the very nice Dexterity through-the-web editor. Now I'd like to customize the default view for this content.
I've read Martn Aspelli's book but the problem is that through-the-web content does'nt have a specific interface (so I can't use it to create my specific view).

If you want to do this all through-the-web, then do the following:
Create a template for your view in the "custom" folder of
portal_skins (through the ZMI). You'll probably want to start with a
copy of something like the page template
(portal_skins/plone_content/document_view). Give it a name like
your_content_type_view. Test it by appending /your_content_type_view
to the URL for a sample object.
Edit the Factory Type Information (portal_types/your_content_type/Default
view method) to be your_content_type_view.
What you will have done is create a skin-level view for the type. This is different from the browser views that Martin is discussing, which do indeed require a class. The Dexterity development team is working on a way to provide TTW maintenance of browser views, but that's for a later version of Plone.
Meanwhile, if you later transfer your Dexterity content type to a Python add on, you'll be able to use your template, possibly unmodified for a browser view.

Related

Plone setuphandler- In a setuphandler, how can I programatically add/create a folderish content type at root of Plonesite?

I have have made a folderish content type called supplier_folder, which displays a list of suppliers that can be added under it, and their information. I can add it through the navigation bar, but I would like to add it programatically during setup.
I have been following the tutorial on custom installer code (http://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py) and have looked at creating objects programatically (http://docs.plone.org/develop/plone/content/creating.html).
Unfortunately, the second article says I need to have a folder created. How can I get around this and add the supplier_folder object at the Plone Site outside of a folder?
IIRC, only users with role Manager or Site Administrator can add content to the root of the site; you can overcome this limitation in two ways:
by using the _constructInstance method as it bypasses the permissions when creating an item
by switching roles inside your code with plone.api.env.adopt_roles
I personally prefer the second one.
you can see an example of a pretty complex setuphandlers.py in interlegis.portalmodelo.policy package.
When you create a new Plone site, it's also creating some default content types.
Look at how Plone do: https://github.com/plone/Products.CMFPlone/blob/1471828ee97a8dd84396bad4a3286be514819869/Products/CMFPlone/setuphandlers.py#L119
There are a couple of ways to achieve this. The buildin mechanism is to use GenericSetup in combination with "structure" folder as described here: http://koansys.com/tech/create-plone-initial-content-with-generic-setup
In short you need the following:
Create a folder "structure" in your Generic Setup profile (in general, under profiles/default)
Create a .objects file with the following content: "suppliers,supplier_folder"
in "structure" create a folder "suppliers" with a .properties file and content:
[DEFAULT]
title = Suppliers
description = Some usefull description text
As far as I remember this is ok for simple structures likes your. If you have complex structures with folders and sub-folders and want more specific control you probably need to write python code. I made some stuff here: https://github.com/collective/zettwerk.setup/blob/master/zettwerk/setup/structure.py
But zettwerk.setup is not yet released, but you should be able to integrate the structure.py right into your project. Than you can the handle_structure method into your setuphandlers.py and passing a structure dict like this:
handle_structure(portal, [{'id': 'suppliers', 'portal_type': 'supplier_folder'}])
The advantage of this method is, that you can also control metadata like workflow state, default page setting, portlets, local roles and some others.

Plone 4 EEA Faceted Navigation - How to register a custom view

I have installed eea.facetednavigation and it works fine so far. But I want to register a new result view and don't know how to hook here.
Do I have to use a non-grokked view? Or is there a special interface that could be used for grok.context (This is what I've tried so far with IFacetedNavigable, but no success)
Update
As recommended, I declared my view with faceted:view in my configure.zcml
It does not work at all. I am on Plone4.3. I'm pretty shure that I declared the view as described in the example, but cannot select it in the dropdown. When I construct a request that tries to set my custom view, I get an Invalid view id error.
I can test the view, by appending the view name to a url with a folderish content. It works. Just the registration is not done entirely. I get some kss errors too, when I reinstall the affected addon. There may be a relation.
Update II
After deactivating and activating facetednavigation, the view appeared.
Look in eea.facetednavigation.views there is an example. Basically you'll need to register your view with zcml faceted:view meta directive.
I customized the eea.facetednavigation view only once, but it was really simple by using z3c.jbot (no need of ZCML or grok in this case).

XPM / UI : Creating new pages based on Page Type with copied components

I relatively simple question regarding XPM this time. It's about creating Page Type which editors could use to base their new website page on. When defining a Page Type, you can use an exisiting page to enable this as an example page, including its components. You can copy these components to enable editors to edit these freely without tampering with existing pages using these components as well.
On the SDL Live content docs they explain the following:
Change the setting from Include this Component Presentation to
Include a Component Presentation that contains a copy of this
Component. If you use this Component in multiple Component
Presentations on this Page, then saving the Page causes all of those
Component Presentations to have the setting you configured last for
any of those Component Presentations. A number of new controls appear.
This means that whenever an editor clicks 'new page' within XPM, this page type is available and the components that are defined inside it are copied with user-specific prefixes. You can define this inside the page defined as a Page Type itself, by clicking on the component presentations tab, then clicking on a component and selecting Page Type settings. note the following:
As you can see, the copy of the content is being created in 050 - Web - Global, which is, in our blueprint, the wrong publication. However, in the popup you cannot select the correct content location, only the one where the page type is residing.
I've tested this, also with the UI -specific blueprint context settings, where you should define where content and pages are created. However, when creating a new page, the components are copied inside 050 - web - global; the wrong publication. As we're moving to a training, I'd imagine that dynamically created components like this might clog the CMS with content in the wrong location, making it unusable for other publications. Is there a reason for this behaviour, and if so, a way to make this work properly?
If you set the BluePrint Context for Components to the Publication where you want them to be created, it should work as you expect.

how to make Plone Dexterity container look like Archetypes folder

I've created a Dexterity product that includes container and non-container Dexterity content types. Having discovered collective.documentviewer (yay! thanks! huzzah!), I'd like to use its dvpdf-group-view, but that is registered in ZCML as being for Folders, and my Dexterity containers don't qualify. I've looked through the web interfaces available on my container type, added SiteRoot, and that enabled the view to be applied, but is also completely wrong.
I'm confident there's a right way to do this, and I'm pretty sure it's central to the whole adapter/interface mechanism, but I just can't find it in any of the books.
Anyone care to try an explanation? First, the line or two that would enable a Dexterity container to pretend it's also a Folder; second, how to change the default view of a single instance of a Dexterity type so that it presents a foreign component's view?
Thanks.
1. Register the view for dexterity containers too
The view is registered for the Archetypes folder interface (Products.CMFCore.interfaces._content.IFolderish), but your dexterity container does not provide this interface (but plone.dexterity.interfaces.IDexterityContainer).
The reason may be that the product and/or the view is not compatible with dexterity.
Anway, you can try it out yourself by registering the view also for the the IDexterityContainer interface by putting a little ZCML in the configure.zcml in your package (see also the Creating a package section of the Dexterity Developer Manual):
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<configure package="collective.documentviewer">
<browser:page
name="dvpdf-group-view"
for="plone.dexterity.interfaces.IDexterityContainer"
class=".views.GroupView"
template="templates/group-view.pt"
permission="zope2.View"
layer=".interfaces.ILayer" />
</configure>
</configure>
The <browser:page> is copied from the collective.documentviewer configure.zcml but I've changed the interface for= to the dexterity container interface, so that the view also works for dexterity containers.
The inner <configure package="collective.documentviewer"> tells the ZCML parser that the configuration should be applied as if the configure.zcml would be directly in collective.documentviewer - this allows you for example to use the original template (otherwise you would have to copy it or do some nasty things).
I did not test it myself: it may still be that the view needs an archetypes container and does not work with a dexterity container. It may also be that you have to register more components from the documentviewer for dexterity containers (maybe the menus? take a look at what is registered in the original configure.zcml.
If everything works well you should consider doing the changes in collective.documentviewer on github directly and make a pull-request to the author (be aware that dexterity is not plone-core yet). But first ask if and how you should do it :-)
2. Changing the default view
With plone it is possible to define multiple views for a specific type. The view can then be selected in the display menu per instance of this type. If you open up http://localhost:8080/Plone/portal_types/manage_main and click on your type, there is a field Available view methods, where you can add the view-name (dvpdf-group-view) on a seperate line.
After you create a new object of your type or visit an existing one, you have a "Display"-menu which should list the view. Select it and this object now has this view as default.
(If you want to make the view not selectable on other objects of this type you could just remove it from the type configuration so that it is not selectable anymore - the existing configuration of your object will stay).

How would one set the default view of content that is imported via Generic Setup (structure)

I already know how to programatically set the default view content, in my specific case, a Folder, or how to use the Plone UI to do it. In my case, I am creating a large skeleton of content via GenericSetup and I need a set of folders to have a specific content item in each folder be the default view.
So, I have a folder structure like so:
folder1/
-- .properties
-- page1
-- homepage1
folder2/
-- .properties
-- page2
-- homepage2
I would think that in:
profile/default/structure/folder1/.properties
you would be able to add:
DefaultView = homepage1
or similar. So the question is: "Is it possible to set the default view of a content item using Generic Setup?"
This answer might also work; I haven't tried it yet because I'd like some feedback on my question before moving away from GS to using ZCML.
How to define default views in Plone
The GS structure importer doesn't support this; it has no idea about the (Plone specific) Dynamic Layout support.
You'll have to write your own custom GS step to do this, I am afraid, or perhaps use something like plone.app.transmogrifier (it includes support for browser defaults and collective.transmogrifier includes a GS step) to configure this.

Resources