4

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? – Melvyn Jun 27 '14 at 21:52
  • @Melvyn I have updated the question with the requested area. – jeremy.bass Jun 27 '14 at 22:25
12

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.

| improve this answer | |
  • I have updated the question to reflect your answer. I'm not quite there it seems. ideas? – jeremy.bass Jun 27 '14 at 21:21
  • 2
    You 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. – Melvyn Jun 28 '14 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-object – jeremy.bass Jul 1 '14 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? – jeremy.bass Jul 1 '14 at 15:37
  • Clear the cache – Marius Jul 1 '14 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.