I'm trying to inject a field from a behavior directly after description, before the content types own fields (non-behavior-based fields).
form.order_after(myfield = 'IBasic.description')
does not work - the field still shows up after the non-behavior fields.
form.order_before(myfield = '*')
works, but of course puts the field completely at the top.
form.order_before(myfield = '*')
form.order_after(myfield = 'IBasic.description')
the field is still at the top.
What did I miss?
form.order_before(myfield = 'first_field_from_ctype')
works, but in the nature of things the content types have different fields.
plone.app.dexterity-1.2.1
plone.dexterity-1.1.2
plone 4.2b2
The description field is in the IDublinCore behavior, so the proper code is:
form.order_after(myfield = 'IDublinCore.description')
Related
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.
I'd like to translate each node title as a string (using i18n). I'm trying this function in my theme template:
function theme_process_page(&$variables) {
$variables['title'] = t($variables['title']);
}
Yet when I refresh strings, none of my node titles are on the list. Is there something I'm missing?
And to clarify the function name is using my theme name, not the word "theme".
Title is my usual solution for this (I use Entity Translation, it works fine with Title module).
This module replaces node titles by a regular translatable text field. You can choose wich content type titles must be replaced (on the "Manage Field" forms, you'll find a "replace" link in the title row). Pretty useful.
Good luck
You should never use t() to translate user-supplied or variable strings. See the documentation on the function.
That said, there are some solutions, one is to use the built-in language support for entity fields. Following that you should be able to do something like this in a field hook (in a module, not in your template):
$langcode = $field_info['translatable'] ? $content_langcode : LANGUAGE_NONE;
$entity->{$field_name}[$langcode][0]['value'] = t("Salut!");
I'm trying to copy the content in news items to other content type that I wrote. In my script I have the news item and the project item. The second, project, is a content type defined using Dexterity. It would be wonderful if I could to copy the image and the body text from news to project in the next way.
project.text = news.text
project.image = news.image
Where text and image are defined in the project schema as RichText and NamedBlobImage. I don't know how the attributes are in the news item. I only know that I can get the image in the news item using the method getImage() but assign it to the project generates an error when rendering the project.
So I need some pointers to solve my basic questions:
How can I know the attribute names for Archetype content types. For example, in this case I need to know the name of the attribute for the body text of news item.
How can I convert an image attached to a news item to an image attached to a dexterity content type.
You use the field from the Archetypes schema to retrieve values, preferably the raw values in this case. You pass in the object then calling either .get() or .getRaw():
schema = news.Schema()
news = schema.getField('text').getRaw(news)
imageField = schema.getField('image')
image = imageField.getRaw(news)
content_type = imageField.getContentType(news)
filename = imageField.getFilename(news)
The object returned by the ImageField.getRaw() call is basically a OFS.Image instance. You can call str() on it to get the raw image data.
To set the image object, you really want to get the image field from the schema and use it's ._type attribute as a factory:
project.image = IProjectInterface.image._type(str(image),
contentType=content_type, filename=filename)
The content type here is optional; the NamedImage and NamedBlobImage types sniff out the content type automatically too.
In my multilanguage Drupal 6 website I need to make my CCK field default values translatable, i.e.
Hello - in the English version
Bonjour - in the French one
I cannot find this text with Translation Table, neither are these values in variable table so that I can use multilingual variables.
Do You know how to have different default values in different languages?
When you define the CCK field, you can enter a PHP code snippet to override the default value of the field.
Enter the following there :
return array(0 => array('value' => t('Hello')));
Now access a node add page with this CCK field from a non-English version so that it gets added to translatable strings.
Now you're able to translate it using the "Translate interface" menu (it might take a visit to the "create" page of your cck type first though). It doesn't require any extra modules in fact, just basic D6 (and it probably works in D5 and D7 as well).
This method is a bit of a hack. Im not sure I would deploy this without really considering the consequences. For a simple usecase it MIGHT be ok.
Create a custom module, lets say def_translate. To def_translate.module, add a function
function def_translate_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if($node->type == "sometype"
&& $op == "load"
&& $node->field_some_cck_field_type[0]['value'] == "your default value")
{
$node->field_some_cck_field_type[0]['value'] =
t($node->field_some_cck_field_type[0]['value']);
}
}
Ok - so what is this doing?
When a node is loaded, hook_nodeapi gets called, with $op set to "load". This gives us an opportunity to do manipulate the node before it is rendered. Before we do anything we check
Is this the right type of node?
Is our op = "load"?
Is the value our default value?
What we then do is pass the existing default value through the t() function. This will make the default string available to i18n translation table, and you can then use the normal way of translating strings.
*DISCLAIMER*
I have not tested this myself in production. Im not entirely sure what the effects will be. You probably want to think this through before implementing it, and you probably want to put some features in to look up the default values from the DB incase they are changed in the CCK UI.
Hope this helps - or possibly shakes a hint of a solution to your problem!
I like simplifying the node form. One of my tricks in the past has been to conditionally hide CCK elements on new node creation when I want to enforce some kind of default. One of my favorite tricks is to whisk away things put in place by the Prepopulate module. Unfortunately for me, it's recent move to an #after_build-based mechanism seems to be creating all kinds of collisions in how I can manipulate the widget.
This is what I used to do in hook_form_alter():
$form['field_my_nodereference_field'][0]['#type'] = 'hidden';
$form['field_my_nodereference_field'][0]['#value'] = $form['field_my_nodereference_field'][0]['#default_value']['nid'];
$form['field_my_nodereference_field'][0]['#parents'] = array('field_my_nodereference_field', 0, 'nid');
But when I try to play this game in #after_build, I run into errors with the hidden type's validation, or the nodereference_autocomplete_validation. I have resorted to conditionally adding a CSS file. This makes me sad.
Hidden is not enough. Try this one:
$form['field_my_nodereference_field'][0]['#type'] = 'nodereference_hidden';
when the type is a CCK field you have to pass this format _hidden
for instance for a simple text field I used
$form['field_srt'][0]['#type'] = 'text_hidden';
or for a filefield field I used
$form['field_myfile'][0]['#type'] = 'filefield_hidden';