Symfony i18n field and admin generator - php

I use symfony 1.4.15 with doctrine. I have module and there are two i18n field. So in my form class I make:
$this->languages = sfConfig::get('app_cultures_enabled');
$langs = array_keys($this->languages);
$this->embedI18n($langs);
foreach($this->languages as $lang => $label)
{
$this->widgetSchema[$lang]['name'] = new sfWidgetFormTextarea(array(), array('cols'=>40,'rows'=>2));
$this->widgetSchema[$lang]['description'] = new sfWidgetFormTextarea(array(), array('cols'=>80,'rows'=>5));
}
And it is work perfect!
But I have many fields in my form, so I need to make some "groups" in my form. So I make next in my generator.yml:
config:
form:
display:
Main info:[active,position,сoverage_id,basis_id,durability_id,comfort_id,weight_coating,thickness_coating,height_of_pile,segment_id,width_rolls_one,width_rolls_two,width_rolls_three,standart_width_rolls,max_width_rolls,min_width_rolls]
Price: [price,margin_on_roll,margin_on_cutting,special_discount,discount_for_residues]
Market: [certificate]
And I can not display two i18n field "name" and "description". I try
Market: [name_i18n] and name_i18n_uk and many other. So is is to possible to make?If not are there other way to group filed in form?
Thank you!

What you can do is something like this in the generator:
form:
display:
Market: [certificate, pt, en, es, ...]

Related

Add custom entity type for custom field in Shopware 6

In Shopware 6.4.0.0 it is possible to add custom fields which are based on Entities.
The list of entity types is limited:
Is it easily possible to add additional entity types, such as a list of available product properties?
EDIT https://github.com/shopware/platform/blob/trunk/src/Administration/Resources/app/administration/src/module/sw-settings-custom-field/component/sw-custom-field-type-entity/index.js#L9
It is enough to add something like
{
label: "Product Property Group",
value: 'property_group'
}
to the select
https://github.com/shopware/platform/blob/trunk/src/Administration/Resources/app/administration/src/module/sw-settings-custom-field/component/sw-custom-field-type-entity/index.js#L9
Then it is possible to create a custom field that lets us chose product properties.
Next we have to make this change persistent.
See https://developer.shopware.com/docs/guides/plugins/plugins/administration/customizing-components
Component.override('sw-custom-field-type-entity', {
computed: {
entityTypes() {
const types = this.$super('entityTypes');
types.push(
{
label: 'Product Property Group',
value: 'property_group'
}
);
return types;
}
}
});

SilverStripe change field label from parent class

Within SiteConfig there is a TextField Site title. I'm trying to change the label of this textfield $titleField through a SiteConfig extension in class SiteConfigExtension extends DataExtension.
Here is the code from siteconfig/code/model/ where it's created:
$fields = new FieldList(
new TabSet("Root",
$tabMain = new Tab('Main',
$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
....
Q: What's the easiest way to replace the SiteTitle label without having to remove the field in the SiteConfig extension and re-add it again with the desired label?
You could make use of the implemented _t() function. Put following in your mysite/lang/{LANG_CODE}.yml file:
{LANG_CODE}:
SiteConfig:
SITETITLE: 'My new title'
Replace {LANG_CODE} with the admin language(s) being used (eg sv for Swedish, or en for English). Keeping your strings separated from the code comes with many benefits. Remember to run ?flush after updating YAML files.
https://docs.silverstripe.org/en/3.4/developer_guides/i18n/
Updating the title from SiteConfigExtension uses updateCMSFields...
class SiteConfigExtension extends DataExtension {
public function updateCMSFields(FieldList $fields) {
if ($titleField = $fields->dataFieldByName('Title'))
$titleField->setTitle('my title');
}
}

Magento How to use translation on attribute label?

I use Magento and I need help to use in frontend the translation of an attribute label !
I use this on my marketplace.phtml to load the attribute label
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'etat_verres');
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) { if($instance['label']) {
echo $instance['value'] // to show the value
echo $instance["label"] // to show the label
} }
?>
The problem is that Magento use Admin Value and not french value or english value.
Thanks in advance !
Sincerely yours,
John
Using the $this->__ is the core Magento helper which also contains the translation functionality, now assuming your module has extends the core Magento helper this will work. Now you can use a theme translate.csv file to translate your text.
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'etat_verres');
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach($allOptions as $instance)
{
if ($instance['label'])
{
echo $this->__($instance['value']) // to show the value
echo $this->__($instance["label"]) // to show the label
}
}
Also keep in mind, translating the "labels" should not be necessary as you can use the Magento admin store view translations within Catalog->Manage Attributes Select your attribute and manage attributes per store view, however, I'm not entirely sure of the context. While what I provided should work, having context will provide a better solution.

Symfony: embedding collection of forms

I'm trying to embed collection of forms into one based on this cookbook: http://symfony.com/doc/current/cookbook/form/form_collections.html
I have following database shcema: product ---< POS shortcut >--- POS item
in controller i'm initiatig form like this:
$pos = new PosList();
for ($i=0;$i<10 ;$i++ ) {
$scut1 = new PosShortcut();
$pos->addPosShortcut($scut1);
}
$form = $this->createForm(new PosListType(), $pos);
Then i have form for POSShortcut:
$builder
->add('posList','hidden')
->add('product','entity',array(
'required'=>false,
'empty_value'=>'Choose product...',
'label'=>'Shordcut product',
'class'=>'StockBundle:Product',
'property'=>'name'
));
And of course main form, what includes PosShortcut form:
<...>
->add('posShortcut','collection',array('type'=>new PosShortcutType()))
<...>
Now the problem is that for a POS shortcut item, POSList id is set to NULL when it's written in database. Reason is very simple, i haven't set PosList value for new shortcut when i'm creating them in controller at firstplace. But the issue is that i can not do that in this state, because POS item does not exists in database yet.
How to get over this problem ?
class PosList
{
public function addPosShortcut($shortcut)
{
$this->shortcuts->add($shortcut);
$shortcut->setPosList($this); // *** This will link the objects ***
}
Doctrine 2 will take care of the rest. You should be aware that all 10 of your shortcuts will always be posted.

Symfony backend: Load data on combo box depending on another

Im starting with symfony and im a little lost here. Of course nothing that a good tutorial can manage. However i've come to a point that my tutorial doesn't cover.
Creating the backend i write this generator.yml
...product/config/generator.yml
generator:
class: sfDoctrineGenerator
param:
model_class: Product
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: product
with_doctrine_route: true
actions_base_class: sfActions
config:
actions:
fields:
product_type_id: {label: Product Type}
product_name: {label: Product Name}
list:
display: [product_type_id, category, product_name, created_at, updated_at]
filter: ~
form: ~
edit: ~
new:
display: [product_type_id, product_name, url, description, _category]
The last field is rendered throught a custom file _category.php
<?php
echo '<HTML CODE><select><option>...</option>';
$query = Doctrine_Core::getTable('category')
->createQuery('c')
->where("id <> 1");
$quer= $query->fetchArray();
foreach($quer as $q) {
echo '<option value="'.$q['id'].'">'.$q['category_name'].'</option>';
}
echo '</select> </HTML CODE>'
?>
It give a simple form to introduce the data, and its ok. But i was trying that the first combo box on the "new" action (product_type_id) allow me to modify the query of categories to display only those that match.
I wonder if i can access the value of product_type_id invoking some sfFuction or doctrine... or something.
Thanks in advance for your help.

Categories