plone.app.multilingual: Access Translated Object's Attributes - plone

Environment: Plone 4.3.3, plone.app.multilingual 2.0a4 (checkout from github), in my case, two languages (en and zh) are enabled, ie a bilingual site.
My custom Dexterity type has a field remoteUrl, its definition looks like this:
<field name="remoteUrl"
type="zope.schema.TextLine">
<title i18n:translate="">URL</title>
<description i18n:translate="">Link to the Resource.</description>
<default>http://</default>
<required>False</required>
</field>
My scenario is like this: When creating the item in the zh folder (zh/my_item), the remoteUrl field is filled, it will be displayed according to the template. Then, when translating the item into en language (en/my_item), I want it display the value from zh/my_item if the remoteUrl field unfilled in en/my_item. On the other hand, if filled in en/my_item, its value will be used and displayed for the remoteUrl field.
The existing Language Independent Field does not meet my needs, because the filled value will affect both zh/en items. How do I access zh/my_item remoteUrl value from en/my_item context? Any hints or sample snippets for the view class / template will be appreciated.

if you just want to display an alternative value from the other language, you can access translations from catalog index TranslationGroup. Just an idea.

Related

Sonata bundle editable date field

Sonat admin bundle allow to edit only text fields and boolean, i would like to know if there a way to override sonata make it edit datetime/date fields.
Thank you in advance!
At this time , they only support scalar types :
Theses types accept an editable parameter to edit the value from within the list action. This is currently limited to scalar types (text, integer, url...).
https://sonata-project.org/bundles/admin/master/doc/reference/field_types.html
I guess to have to digg more into the documentation to get it working. ( See how scalar types are dealt with and try to write similar logic )
Not sure in which version they added this (can't find it in the change log), but in admin bundle 3.8.0 adding 'editable' => true' to a date field in a list makes it editable alright. The value becomes underlined with a dashed line and clicking it opens a jQuery date selector.

Adding fields dynamically to Share form

I want to add a text field for each file that is added to the attached package items in alfresco to write notes regarding each file, is it possible to do?
I have implemented something that could be reused for your use case.
You can define a property with multiple values that will contain the list of notes associated with each attachment.
There is a simple trick to post a property with multiple values: add "[]" to the name of the property. For example:
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_0"
name="prop_someco_notes[]"
tabindex="0"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_1"
name="prop_someco_notes[]"
tabindex="1"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
As you can see, the name of the input ends with []. Both input textfields have the same name.
The Alfresco Form Engine will consider these two inputs as the value for the property with multiple values: "someco:notes".
The bigger problem is that you need to generate this html with some smart javascript and free marker template.
You can write a custom free marker template to render the initial html: if a user opens a task on which documents have been already attached, you will need to generate the list of inputs using a custom control (you can of course start from textfield.ftl).
It won't be easy to generate the initial list because unfortunately Alfresco returns the list of values as a single comma separated value.
You can customise the webscript that injects the model in the free marker template "org.alfresco.web.scripts.forms.FormUIGet" to pass an array instead of a csv.
A quicker and dirtier solution is to split the csv value. In share-config-custom.xml, you can specify what textfield.ftl show use as a separator instead of the comma.
When a user adds/remove elements from the package, you can intercept the update and add/remove the correspondent note. Notice that I have added the filed "noderef" to each input so it is possible to know the relation between the notes and the nodes in the package.
UPDATE:
For the associations (used for example to define the package in a workflow task), Share uses a javascript library called "object finder" (or "object picker"). This library fires an event called "formValueChanged" that you can intercept:
YAHOO.Bubbling.fire("formValueChanged",
{
eventGroup: this,
addedItems: addedItems,
removedItems: removedItems,
selectedItems: selectedItems,
selectedItemsMetaData: Alfresco.util.deepCopy(this.selectedItems)
});

Z attribute in field:input Spring Tag

I'm building an app using SpringRoo, I've generated the repositories, the services and I've done the scaffold of my model classes.
Now I want to customize my User Interface (e.g. create.jspx form), and I cannot understand some behavior in this part:
<field:textarea field="cocFile" id="c_com_project_name_domain_ObjectModel_file" z="Wo9RZ7vKscJS74aMwIMY1mqfCsU="/>
I cannot see the purpose of the z attribute, and I cannot either integrate my own html template in the generated vues. so what z stands for in this case, and is it possible to override all generated views by springRoo with custom jsp views.
As Anton responded, the z attribute indicates if the item has been modified by the user. To indicate that the item has been personalized must change the value of attribute z by "user-managed" and Roo detect changes made by the user.
You have three options to customize your view jspx:
1- Customize "textarea.tagx".
2- Create a new tagx:
Make a copy of "textarea.tagx" in the same folder and rename it to "textarea2.tagx".
Customize the new tagx created.
To use it you must change "texarea" with "textarea2" in label element, as follows: <field:textarea2 field = "cocFile" id = "c_com_project_name_domain_ObjectModel_file" z = "user-managed" />
3- Modify the "render" and "z" attributes:
<field:textarea field="cocFile" id="c_com_project_name_domain_ObjectModel_file" render="false" z="user-managed"/>
This item is no longer show on the page, and Roo will not generate. Now you can generate your custom code in the jspx page.
Description in spring documentation is -
The z attribute represents a hash key for a given element.
The hash key attribute is important for Roo because it helps determining if a user has altered a Roo managed element.
This is the secret to round-trip support for JSPX files, as you can edit anything at any time yet Roo will be able to merge in changes to the JSPX successfully.
The hash key shown in the "z" attribute is calculated
Read spring mvc doc.

How are keywords in metadata stored?

I'm researching options to synchronize external data to a Category and Keyword list.
I have a metadata field with a states field that uses a category called US States.
When I preview my component with a simple XSLT component template (<xsl:copy-of select="." />), I can see:
<tcm:Content>
...
</tcm:Content>
<tcm:Metadata><Metadata xmlns="http://createandbreak.net/schema/generic">
<states>California</states>
<states>New York</states>
</Metadata></tcm:Metadata>
When I update the keyword and preview, I can see updated values.
<tcm:Content>
...
</tcm:Content>
<tcm:Metadata><Metadata xmlns="http://createandbreak.net/schema/generic">
<states>Californias</states>
<states>New York</states>
</Metadata></tcm:Metadata>
Which is great. It looks like we do not need to synchronize components (open, edit, and save) to use updated keywords. Is that a safe assumption?
If I update a keyword, do I need to update components that use it in order to publish component presentations with the updated values?
Do I need to also be careful when moving components with content porter?
No, you don't need to do anything manually for those Keyword fields to be "Content Porter"-safe. Tridion stores the link from your Keyword field to the Keyword definition (in the category) as a so-called managed link (a TCM URI).
The reason you don't see this value in your XSLT has to do with the way Tridion traditionally exposes the Keywords in WebDAV: it hides the TCM URIs there and instead just exposes the value of the selected keyword. Since Keyword values must be unique within their category, this will always allow you to look up the correct TCM URI if needed.
But when exporting (and in general when you're using the API to access content) you should retrieve the Component XML with the TCM URIs in place. Check the API documentation for your programming language to see which Filter/ReadOption you need to specify for that.

show all contents of specific content type

For every taxonomy term I can access a page (I am not using the Views module) showing all contents that are tagged with the specific term by using the a path like this: www.example.com/taxonomy/term/1.
Now, I wonder if I could do the same with content-types (e.g. for showing all contents of content type article), using a URL such as www.example.com/content/type/1.
I'm assuming Views 3. You could create a View and supply a contextual filter in the URL to dynamically display all nodes of that content type.
Add "Content: Type" as a contextual filter. Under "When The Filter Is Not Available" section, select "Provide default value", and then Raw value from url. For your example, you would select "3" for the path component.
You can set the Path to "/content/type/%" where the % is the name of the content type. I'm not sure if it will work with numeric values, however.
Without using the Views module, you should create a custom module for doing that, which would be doing what Views is already doing.
If you don't need all the features present in Views, then you can create your own module, even if I would not suggest doing it when Views already exists.
Your module should associate a menu item to a path like "content/type/%" and render a page containing all the nodes of that content type.
For rendering the nodes you could use node_view_multiple(). For retrieving the list of the nodes, and rendering it, you could use code similar to the following one:
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', $content_type)
->propertyCondition('status', 1)
->execute();
$nodes = entity_load('node', array_keys($entities['node']));
return node_view_multiple($nodes, 'teaser');
$content_type is the string passed to the menu item.
The code I reported would not use a pager, but it would show all the nodes in a single page.

Resources