I need to add a field that I did to the customer, but also to the admin user. I have the customer one working,
$installer->addAttribute('customer', 'ldap_user', array(
'type' => 'int',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'label' => 'Has AD account',
'visible' => true,
'required' => false,
));
$attr = Mage::getSingleton( 'eav/config' )->getAttribute( 'customer', 'ldap_user' );
$attr->setData( 'used_in_forms', array( 'adminhtml_customer' ) );
$attr->save();
But I can't seem to find anything on how to do one for the admin user and all attempts so far to convert this to the admin/user model has failed. Any ideas on the correct way to add this field?
*UPDATE Base on @Marius answer I'm closer. The install part works, and the column was added. The tab prepare Form is not yes right. I put
\app\code\local\Wsu\NetworkSecurities\Block\Adminhtml\Permissions\User\Edit\Tab\Main.php
<?php
class Wsu_NetworkSecurities_Block_Adminhtml_Permissions_User_Edit_Tab_Main extends Mage_Adminhtml_Block_Permissions_User_Edit_Tab_Main {
protected function _prepareForm() {
parent::_prepareForm();
$form = $this->getForm();
$fieldset = $form->getElements()->searchById('user_base_fieldset');
$fieldset->addField('ldap_user', 'select', array(
'name' => 'is_active',
'label' => Mage::helper('adminhtml')->__('LDAP user'),
'id' => 'is_active',
'title' => Mage::helper('adminhtml')->__('LDAP user'),
'class' => 'input-select',
'style' => 'width: 80px',
'options' => array('1' => Mage::helper('adminhtml')->__('Yes'), '0' => Mage::helper('adminhtml')->__('No')),
));
$this->setForm($form);
return $this;
}
}
But I am not seeing it. I can see also I think I need to rewrite system_account/index too I would think?
/etc/config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Wsu_NetworkSecurities>
<version>0.1.0</version>
</Wsu_NetworkSecurities>
</modules>
<global>
<blocks>
<wsu_networksecurities>
<class>Wsu_NetworkSecurities_Block</class>
</wsu_networksecurities>
<adminhtml>
<rewrite>
<permissions_user_edit_tab_main>Wsu_NetworkSecurities_Block_Adminhtml_Permissions_User_Edit_Tab_Main</permissions_user_edit_tab_main>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
That is what I have for the blocks.
UPDATE
So this works to add a new fieldset and add the field, but it never could get in the main fieldset, but it works.
protected function _prepareForm() {
parent::_prepareForm();
$form = $this->getForm();
$fieldset = $form->addFieldset('LDAP', array(
'legend' => Mage::helper('adminhtml')->__('User Info'),
'class' => 'fieldset-wide'
));
$fieldset->addField('ldap_user', 'select', array(
'name' => 'is_active',
'label' => Mage::helper('adminhtml')->__('LDAP user'),
'id' => 'is_active',
'title' => Mage::helper('adminhtml')->__('LDAP user'),
'class' => 'input-select',
'style' => 'width: 80px',
'options' => array('1' => Mage::helper('adminhtml')->__('Yes'), '0' => Mage::helper('adminhtml')->__('No')),
));
return $this;
}
}
-
What's the config.xml for the module, especially the part that rewrites that block?user4351– user43512014年06月27日 21:52:58 +00:00Commented Jun 27, 2014 at 21:52
-
@Melvyn I have updated the question with the requested area.Quantum– Quantum2014年06月27日 22:25:49 +00:00Commented Jun 27, 2014 at 22:25
1 Answer 1
You will need to add a column to the admin_user table.
$installer->getConnection()->addColumn($installer->getTable('admin/user'), 'ldap_user', array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'length' => 256,
'nullable' => true,
'default' => null,
'comment' => 'Ldap user'
));
Then, if you want to add/edit this field from the backend you need to rewrite the method Mage_Adminhtml_Block_Permissions_User_Edit_Tab_Main::_prepareForm and add a new element in there:
$fieldset->addField('ldap_user', 'select', array(
'name' => 'is_active',
'label' => Mage::helper('adminhtml')->__('LDAP user'),
'id' => 'is_active',
'title' => Mage::helper('adminhtml')->__('LDAP user'),
'class' => 'input-select',
'style' => 'width: 80px',
'options' => array('1' => Mage::helper('adminhtml')->__('Yes'), '0' => Mage::helper('adminhtml')->__('No')),
));
Clear the cache and it should work.
-
I have updated the question to reflect your answer. I'm not quite there it seems. ideas?Quantum– Quantum2014年06月27日 21:21:54 +00:00Commented Jun 27, 2014 at 21:21
-
2You haven't rewritten the block. It's not enough to extend the class, you need to tell Magento to use yours. I'll leave the details to @Marius.user4351– user43512014年06月28日 07:07:37 +00:00Commented Jun 28, 2014 at 7:07
-
so I added the rewrite to the config, although atm I'm running down why I have a fault
addField() on a non-objectQuantum– Quantum2014年07月01日 01:43:58 +00:00Commented Jul 1, 2014 at 1:43 -
@Marius I thought this was working, but when I go to add ` $user->load($username, 'username');$user->setLdapUser(1)->save();` The value is not saving. Any idea?Quantum– Quantum2014年07月01日 15:37:15 +00:00Commented Jul 1, 2014 at 15:37
-