Drupal Views an NodeReferences: Linking to URL in referenced node - drupal

I have a cck-node with some node-references like PDF-files, videos and so on. Now I want to build a view that lists all those files, which i already have. Yet I can only get the links linking to the referenced node. I'd like to have them link to the file in the referenced node.
Hope a generic example makes it clearer:
--
A Sample Product
Lorem Ipsum…
Relating Files:
Manuals
Manual A (should link to file instead of node)
Manual B (should link to file instead of node)
Movies
Movie (should link to file instead of node)
--
Hope someone can help me with this.
Note: Client preferes to have it build only with views - no template files or such because he's familiar with drupal but not with templates etc.

Try this module: http://drupal.org/project/nodereference_views - lets you format a nodereference field to show different pieces of the referenced node.

Related

Create page structure one time for all languages

I'm testing the Django CMS and I'm looking for a way to create the pages one time for all languages. Currently I have to create a new page for each languages and the content/plugin/structure is not shared between the different languages.
Is there a way to achieve this?
Thanks in advance
The built-in management command ./manage.py cms copy lang copies the entire page tree from one language to another. The page tree stays unchanged and the plugin trees are transferred. That is fine if you want to bootstrap a new language for the entire site.
If you want to copy the plugin trees for only one page, you can use the language menu from the toolbar: Language -> Copy all plugins if you are viewing the target language. This is fine, if you only have one page.
If you want to bootstrap a language for a page tree, i.e. a page and all its children, then you either have a lot of clicking to do, or use this short management command I created based on the original DjangoCMS ./manage.py cms copy long command. It allows to specify a page to copy either by its id or by its name in the source language (attention: it has to be unique).
Copy this snippet into any of your application's command folder: my_app/management/commands/. Once you've copied the file you'll have a new Django management command available: ./manage.py copylang. Usage examples:
./manage.py copylang --from-lang=en --to-lang=nl --tree="Home"
./manage.py copylang --from-lang=en --to-lang=nl --tree_id=36 --force
The page id needed for the --tree_id option can be easily inferred from the page admin by hovering over the page's preview icon. The page id is part of the link: .../page/page_id/lang/preview/...
If you leave out the --treeand the --tree_id options the command will revert to DjangoCMS's original cms copy lang behaviour.
The management command provided by #Fabian is quite useful.
I updated the command code here to reflect the changes in django-cms API:
# pages = [head] + list(head.children.drafts())
pages = [head] + list(head.get_child_pages().drafts())
Tested against django-cms 3.5.3 and 3.7.4.
All credits go to #Fabian.

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.

Listing contents of subfolders in a Plone folder view

On a Plone site with the structure
root
+-topic1
| +-page1
| +-page2
|
+-topic2
+-page3
+-page4
I want to have a view for folder root that lists the contents of the subfolders, like:
[http://host/plone/root/]
TOPIC1
- page1
- page2
TOPIC2
- page3
- page4
with "TOPIC1" and "TOPIC2" as headings and "page1" etc. linking to the actual pages.
Simply using a collection aggregating the pages in the topic1 and topic2 folders is not enough since it doesn't generate the subheadings.
I have searched the Plone products repository as well as the web for an extension providing a view like this, with no success. There are sources saying this can be done with custom Display Views, but since I am new to Plone, I hesitate to dig into hacking these.
Is there a Plone product/extension that can provide such a view on subfolder contents?
Or is there even a built-in solution that I am not aware of?
I figured it out.
Basically, what you want to do is extend the folder_summary_view template to include a content list for folder and collection items.
Create a copy. In the ZMI, go to portal_skins/plone_content/folder_summary_view and hit Customize. Go to the copy at portal_skins/custom/folder_summary_view and rename it to (for example) list_contents.
Activate it as folder view. Go to portal_types/Folder and manually add list_contents to the list in Available view methods.
Make sure the view only shows folders and collections. Wrap the code that generates the entry details in <tal:general_check condition="python: item_type in ('Folder', 'Topic')"> GENERATE ENTRY </tal:general_check>
Add the code for listing the item contents. You can steal it from portal_skins/plone_content/folder_listing since this already does what is needed. Copy the <metal:listingmacro> ... <metal:listingmacro> part, but replace the folderContents definition in <tal:foldercontents> with this line to retrieve the contents:
folderContents folderContents|nothing;
folderContents python:item_object.queryCatalog(**contentFilter) or
item_object.getFolderContents(contentFilter, batch=True, b_size=limit_display or 100);
(all in one line)
Note: item_object is the name given to the item in the outer listing.
If you activate list_contents as a folder view now, it works exactly as demanded in the question.
Warning: This is a copy-paste-hack by a Plone novice that works for me™. Use at your own risk.
You can also achieve this just via the Plone-UI:
Install Products.ContentWellPortlets and assign two collection-portlets below the content to your portal's default-view-item (f.e. 'front-page' as by default).
You could use a Collection here, with the two paths configured as criteria.
And if you want to, you could use this collection as default view for "root". Have a look at the default "news" and "events" folders and collections, located in it.
http://plone.org/documentation/manual/plone-4-user-manual/using-collections/adding-collections

Drupal6: View that shows a directory structure

I've built a content type to handle document upload. My content type uses a Book node to handle directories/subdirectories and I would like to show a couple of Views that shows the directories structure. When clicking on a directory I would like to show, in another view, all the documents inserted in that directory.
Do you know any existing examples of Views/Panels? That shows a similar structure, as in the Windows Explorer, using Views2?
You can use this module: views_tree
Also tree-like can be built via argument handlers...

cck remote file (image) field - I want to keep the cached copy of the image when the node is deleted

I use the Remote File module for a cck field displaying a remote image. It works with a known issue: images are reloaded on every edit http://drupal.org/node/395256
And as i do tests with lots of nodes and delete them afterwards, the images cached in filesystem become deleted too. Is there a way to tell filefield(?) not to delete them?
edit
Meanwhile found http://drupal.org/project/filefield_sources which works very nice on manually created or edited nodes. But there is no way to make filefield fetch the image on assigning the url to the place where it shows up when i let print_r($node) show it to me.
See also my post to this (wont-fix)issue http://drupal.org/node/590756#comment-2774472
Yes, there is.
You'd need to create an interface between your node and the file so when you delete the node, the file stays in place. Effectively, you're just deleting the association, not the file.
Perhaps this module saves to the files table and the reference to the file exists already.
You could develop a third party module that stores all your external files and has a GUI or some other interface to select them again for new nodes
Or, you could create a specific content type and save the files as separate nodes. Then you'd use node reference to join them.
Alternatively, the developer of that module says he'll add features if you pay him. However he does not guarantee it from what I can see :)

Resources