How add a plugin with data to a page using the add_plugin (API)? - django-cms

i'm trying to add a plugin in a placeholder of a page when i save a model. But i don't know how to pass the parameter "data" to add_plugin() function of the API.
This is how i'm calling the function
page = create_page(self.title, 'page.html', 'es', parent=query_pages[0])
placeholder = page.placeholders.get(slot='News Header')
add_plugin(placeholder, 'ArticlePluginPublisher', 'es', **query_art[0].article)
And when i call add_plugin appears the next error
add_plugin() argument after ** must be a mapping, not Article

Did you check the docs? **query_art[0].article doesn't match the expected arguments as it's an instance;
placeholder (cms.models.placeholdermodel.Placeholder instance) – Placeholder to add the plugin to
plugin_type (string or cms.plugin_base.CMSPluginBase sub-class, must be a valid plugin) – What type of plugin to add
language (string) – Language code for this plugin, must be in LANGUAGES
position (string) – Position to add this plugin to the placeholder, must be a valid django-mptt position
target – Parent plugin. Must be plugin instance
data (kwargs) – Data for the plugin type instance
Data is expected to be something like a dictionary, or something that supports the ** unpacking syntax;
add_plugin(placeholder, 'ArticlePluginPublisher', 'es', **{'article': query_art[0].article})
Check out this example of data or kwargs in a function call;
https://stackoverflow.com/a/1769475/1199464

Related

Fetching translated allowed_values of non-translatable list_string field

I'm attempting to get the allowed_values of a non-translatable list_string field. The allowed_values of this field are translated though and we want to get those allowed_values into a specific language & not the current UI one.
Here is my draft attempt:
// Override language before loading field configuration.
$this->languageManager->setConfigOverrideLanguage($this->languageManager->getLanguage('fr'));
// Load the field configuration in the language forced before.
$field_info = $this->fieldConfigStorage->load('profile.customer.field_title');
$label = $field_info->getLabel();
$allowed_values = $field_info->getSetting('allowed_values');
// Dump values for debugging.
dump($label);
dump($field_info);
dump($allowed_values);
With my current code, I get the proper forced label (here fr) but when I use the ::getSetting('allowed_values') I receive the allowed_values in the current UI language instead of forced one.
Does any one have any idea ?
Many thanks.

Configuration of plugins

I try to use the following plugins in local mode:
s.Util.cookieRead https://marketing.adobe.com/resources/help/en_US/sc/implement/util_cookieread.html
s.Util.cookieWrite https://marketing.adobe.com/resources/help/en_US/sc/implement/util_cookiewrite.html
When I type in console i.e. s.Util.getQueryParam I take back the function which seems that the configuration in file it is allright.
s.Util.getQueryParam
AppMeasurement.a.Util.getQueryParam(c, b, d)
How ever when I go to add the example in plugin function
s.campaign = s.Util.getQueryParam("cid");
when I run my site I can't see anything of this plugin
Also when I use the
getNewRepeat https://marketing.adobe.com/resources/help/en_US/sc/implement/getNewRepeat.html
plugin it always shows me as New visitor.
Is there any special configuration I should make in order to make them to work properly?
// set a session cookie named foo to value 'bar'
s.Util.cookieWrite('foo','bar');
// look for cookie named 'foo' and return value if found, and assign it to prop1
s.prop1 = s.Util.cookieRead('foo');

How do I make a node title translatable?

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!");

Issue in accessing package variable in Dreamweaver Template

I am facing a issue in accessing a package variable in DWT of Page Template.
I have a compound page template with 4 TBB's as follows:
1) Constant TBB - This TBB reads all values of a component(Embedded multivalued component) as key-value pairs and pushes them to a package.
E.g :
Item item = this._package.CreateStringItem(contentType, "test");
this._package.PushItem("key", item);
2) C# DLL of Page Template - This contains the logic of Page Template
3) DWT of Page Template - All package variables are outputted here.
4) Default Finish Actions
The issue I am facing is as follows:
In my DWT ,I want to compare the Metadata of Component template with the package variable set in Constant TBB.
The syntax I am using is :
<!-- TemplateBeginIf cond="ComponentTemplate.Metadata.section_name = key" -->
where key is the package name set in constant TBB having value "test"
But somehow this package variable "key" is giving a value of 0 and not test.
Can someone let me know where exactly I am going wrong.
You should specify the type of item that you're adding to the package by replacing:
Item item = this._package.CreateStringItem(contentType, "test");
with
Item item = this._package.CreateStringItem(contentType.Text, "test");
You should also confirm that the variable is being passed properly to DWT by using
##test##
outside of the condition. This will show the value that you're comparing it to.
Please check following.
Check if there more than one variable in a package with "Key" name.
check if you verifying at correct place in package.

Drupal 6: how to make CCK default values translatable?

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!

Resources