possible to add custom brick without editing brick.php ?

Discussion in 'aMember Pro v.4' started by customcodegeek, Feb 10, 2012.

  1. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    I have made a custom brick by adding another xx extends Am_form_brick class to the library/Am/Form/Brick.php file but is there a way to add a custom brick without editing this file so my custom code wont be overwritten on an upgrade?
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    sure. to make it efficient, it must be done from a separate file in the plugin.

    file application/default/plugins/misc/myplugin/myplugin.php

    PHP:
    class Am_Plugin_Myplugin extends Am_Plugin
    {
         function 
    onLoadBricks(Am_Event $event)
         {
              require_once 
    dirname(__FILE__) . '/brick.php';
         }
    }
    file application/default/plugins/misc/myplugin/brick.php

    PHP:
    class Am_Form_Brick_Mybrick extends Am_Form_Brick
    {
        protected 
    $labels = array(
            
    'Tada',
        );
        public function 
    __construct($id null$config null)
        {
            
    $this->name ___("Sample Myplugin Brick");
            
    parent::__construct($id$config);
        }
        public function 
    insertBrick(HTML_QuickForm2_Container $form)
        {
             
    // using HTML_QuickForm2 elements
             
    $form->addText('_testfield')->setLabel($this->___('Tada'));
        }
    }
  3. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    awesome. thanks a lot!

Share This Page