Add a dropdown list as custom field in magento - select

I added custom fields as described in magento add custom input field to customer account form in admin
But I want a select list, not only a text input one. I don't know which kind of parameter I have to set and how to tell the list of possible values.
Please help :)
Thanks,
Plantex

Where you might do something like:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'text',
'label' => 'Customer Custom Attribute',
));
Use these values instead:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'int',
'label' => 'Customer Custom Attribute',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
));
The type is int because you will typically be storing the index of the value chosen, not the value itself. The input is select so the admin renderer knows which control to use. The source shown here is a common example, it provides an array of "Yes" and "No" values with numeric indexes.
There are many source models already in the Magento code that you can use and you can create your own too, look at any existing one to see how it returns an array. If you make your own and if it uses text indexes instead of numeric then the type will have to be changed back to text.

Try adding this at your module setup file
'value' => array('notate_to_zero'=>array(0=>'Bleu',0=>'Rouge',0=>'Vert',0=>'Violet',0=>'Noir',0=>'Orange'))
),
or look at this --> http://inchoo.net/ecommerce/magento/how-to-create-custom-attribute-source-type/

Related

How to pass params in url to a backpack create form

I'm using backpack 3.3 on a laravel 5.5 installation.
I want to prefill two create form fields with two URL passed values.
Say you create a basic backpack crud, named Image.
Normally you can go to domain/admin/image/create to view and fill in the form.
But if I add one or two params in the url, I get a 404.
I guess I should manage the routes file (admin.php)
I tried this way:
Route::group(['prefix' => 'image/{k}/{cid}'], function()
{
CRUD::resource('image', 'ImageCrudController');
});
but still get a 404.
Any suggestions?
Thanks in advance.
Almost all field types have a default option. So when you define them, you can specify a default. And you can always pass a GET parameter for that default. So you can have something like this in your EntityCrudController:
$this->crud->addField[ // Text
'name' => 'title',
'label' => "Title",
'type' => 'text',
'default' => \Request::has('title')?\Request::has('title'):false, // default value
]);
You'd then be able to send you users to yourapp/admin/entity/create?title=your+default+value and have that default value show up in the field.
Hope it helps. Cheers!
it works for me easier
http://127.0.0.1:8000/admin/resultado/create?competencia=2
$this->crud->modifyField("competencia_id",[
'label' => "Competencia",
"default"=>$this->crud->request->query->get('competencia'),
.....

Typo3 override backend classes

It's been a few weeks I work on Typo3 6.2 and I want to know how to override Typo3 Core classes.
In my case, I have to edit the way select html objects are displayed (I want to add optgroup but Typo doesn't allow us to do it). So I edited the file "FormEngine.php" (typo3/sysext/backend/Classes/Form) and now it works.
But this isn't healthy for future upgrade.
Is there a way to override core classes like any other CMS would allow us to do ?
And I haven't been able to find something on the Internet and I think it could be useful.
Thank you :)
Zisiztypo
Instead of modifying source code of CMS you can just declare a field with a user type and then point your custom userFunc
From the ref:
'tx_examples_special' => array (
'exclude' => 0,
'label' => 'LLL:EXT:examples/Resources/Private/Language/locallang_db.xlf:fe_users.tx_examples_special',
'config' => array (
'type' => 'user',
'size' => '30',
'userFunc' => 'Documentation\\Examples\\Userfuncs\\Tca->specialField',
'parameters' => array(
'color' => 'blue'
)
)
),
TIP: Using this approach, you can create ANY type of field you need, it can be i.e. Google Maps selector, set of fields with common dependencies filled by JS, etc, etc.

CakePHP Forms, where to find and how to modify?

I'm currently new to cakephp and I just want to ask how can I accomplish this,
a select box in which I'm the one determining its options,
<?php echo $this->Form->input('treat', array('class' => 'form-control')); ?>
or how can I trace the code above to know where in the MVC did he determine his options for his selectbox. tnx
#SOS as suggested by #ndm read up on the Form Helper.
There are generally two ways to pass the options to a select via the Form Helper.
First if you have baked the application the contents of the select could be in the DB.
The Form Helper recognizes Model associations and builds the forms accordingly.Thus the contents of the select should be in the DB. For example if you have User belongsTo/hasOne UserType, the userTypes select will be populated from the DB table for userTypes.
The other way is as was already said, but unclear:
one can directly pass the options parameter of the Form->input() function.
There is another function that creates selects via the FormHelper: select().
Check it here
You can use the below code to define the options -
<?php echo $this->Form->input('treat', array(
'class' => 'form-control',
'type' => 'select',
'options' => array(
'1' => 'option 1',
'2' => 'option 2'
)
)); ?>
Just specify the options in the options array. you can also specify the blank option in that by writing 'empty'=>'Please Select' in the array list.

TYPO3 modify backend table

EDIT: TYPO3 version 4.7
there is table Create Website user with many tabs.
I am able to add new tab with my own data using:
$test = array(
'tx_promconf_send_email' => array(
'exclude' => 0,
'label' => 'HAHAHA',
'config' => array(
'type' => 'input'
,)));
t3lib_div::loadTCA('fe_users');
t3lib_extMgm::addTCAcolumns('fe_users',$test,1);
t3lib_extMgm::addToAllTCAtypes('fe_users','--div--;Documents;;;;1-1-1,tx_promconf_send_email');
But I am not able to put my input to already existing tabs. Also I was not able to find some explanation of this string 'fe_users','--div--;Documents;;;;1-1-1,tx_promconf_send_email'.
Is there an option how to modify existing tabs? Where can I found the name of the tab? I tried to use instead of --div-- name of the tab and it does not work.
This weird string is hardly documented. You can find the TCA Documentation here.
If you want to insert it to an existing tab, just do it by finding a field within the desired tab where you want to put your new field after or before.
For example:
t3lib_extMgm::addToAllTCAtypes('fe_users','tx_promconf_send_email', '', 'after:last_name');
Your field will now be displayed after the field "last_name", and so within the tab "Personal Data". You can also use "before:fieldname" to insert your field before a field.

how to load data from database to my own custom field type (form)

I would like to create a custom form field. For example, select field of cities in the world.
I read this article. In this article, the data are loaded using parameter file config.ynl. I, however, I'd like to upload this data from my database.
http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html
Can somebody tell me how to do this or send the link to the example
In this case, better is to use an Entity Field instead of a Choice Field. It allows you to request your database to load your entities as follow,
$builder->add('MyField', 'entity', array(
'class' => 'MyBundle:MyEntity',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('e');
},
'property' => 'something',
));
The property option define the entity property you want to use.
You can then customize your field using the "multiple" and "exanded" options to behave the way you want. Read the documentation