0

I'm writing my custom module, and i'me searching the possibility to add a custom grid to admin tag edit form to handle my_entity-to-tag relation. Anyone knows how to implement that?

5
  • Does default magento has similar solution anywhere? Do you need smth like Catalog / Category / <tab Products> ?
    – zhartaunik
    Commented Apr 15, 2015 at 8:42
  • No, i need section exactly in tag edit form in admin
    – Styopchik
    Commented Apr 15, 2015 at 8:46
  • Like this? prntscr.com/6tyk98 "Products 1111111"
    – zhartaunik
    Commented Apr 15, 2015 at 8:52
  • Yes, exactly. I need section like "Products tagged by Administrator"
    – Styopchik
    Commented Apr 15, 2015 at 8:54
  • Ok, give me some time. I'm writing solution
    – zhartaunik
    Commented Apr 15, 2015 at 9:04

1 Answer 1

0

Assigning tabs magento do in _prepareLayout method.

You can see an example here:

Mage_Adminhtml_Block_Tag_Edit_Assigned

To add your own tab you need to use, for example event core_block_abstract_prepare_layout_after

add following to your module etc/config.xml :

<adminhtml>
    <events>
        <core_block_abstract_prepare_layout_after>
            <observers>
                <add_new_tab>
                    <type>singleton</type>
                    <class>company_module/observer</class>
                    <method>addTabToTag</method>
                </add_new_tab>
            </observers>
        </core_block_abstract_prepare_layout_after>
    </events>
</adminhtml>

Don't forget include in your event check like this:

$yourBlock instanceof Mage_Adminhtml_Block_Tag_Edit_Assigned

At all code of your observer will be like this:

public function addTabToTag($observer)
{
    $block = $observer->getBlock();
    if($block instanceof Mage_Adminhtml_Block_Tag_Edit_Assigned)
    {
        $tagModel = Mage::registry('current_tag');

        $block->addItem('custom_tab', array(
            'title'         => Mage::helper('tag')->__('Custom Tag'),
            'ajax'          => true,
            'content_url'   => $block->getUrl('*/*/assigned', array('ret' => 'all', 'tag_id'=>$tagModel->getId(), 'store'=>$tagModel->getStoreId())),
        ));
    }
}

As you can see you have here $this->getUrl('*/*/assigned'

You need to replace it with some another controller action.

To be continued ....

As far as I can see this controller/action has only load and render layout. You need to rewrite this controller (if you need help - just tell) and add following method:

public function customAction()
{
    $this->_initTag();
    $this->loadLayout();
    $this->renderLayout();
}

Then you need to add content to this block. It makes by layout. Open /app/design/adminhtml/default/default/layout/tag.xml and you can see examples there:

<adminhtml_tag_product>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="adminhtml/tag_product_grid" name="adminhtml.tag.product.grid"/>
    </block>
</adminhtml_tag_product>

<adminhtml_tag_customer>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="adminhtml/tag_customer_grid" name="adminhtml.tag.customer.grid"/>
    </block>
</adminhtml_tag_customer>

In block class Mage_Adminhtml_Block_Tag_Customer_Grid you can see an example how to create your own grid.

If you have any question - just ask.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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