We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help creating my own field type

Development and Programming

designbuddy's avatar
designbuddy
6 posts
14 years ago
designbuddy's avatar designbuddy

I want to create a new field type - a basic textarea with a button, when the user taps the button they get a pop-up allowing them to select from a drop down some text that will be pasted into the textarea.

I have been following the module development documentation here: http://ellislab.com/expressionengine/user-guide/development/modules.html#the-tab-file-tab-module-name-php but quickly get lost on the tab file, control panel and the core module. I’ve had a look around the forums and done a general google search looking for help with how to proceed. Can anyone help to guide me the right direction?

So far I have my update file:

<?php if ( ! defined('APP_VER')) exit('No direct script access allowed');

class Textarea_paster_upd {

    var $version        = '0.1';

    function __construct()
    {
        $this->EE =& get_instance();
    }
    
    function install()
    {
     $data = array(
         'module_name' => 'Textarea_paster' ,
         'module_version' => $this->version,
         'has_cp_backend' => 'y',
         'has_publish_fields' => 'y'
     );
     
         $this->EE->db->insert('modules', $data);
         
         /*Optionally add the publish page tab fields to any saved publish layouts. This is ONLY used if the module adds a tab to the publish page and it requires the tabs() function:
         
         $this->EE->load->library('layout');
         $this->EE->layout->add_layout_tabs($this->tabs(), 'textarea_paster');*/
    }
    
    function update($current = '')
    {
        if (version_compare($current, '0.1', '='))
        {
            return FALSE;
        }
    
        if (version_compare($current, '0.1', '<'))
        {
            // Do your update code here
        }
    
        return TRUE;
    }
    
    function uninstall()
     {
      // remove row from exp_modules
      $this->EE->db->delete('modules', array('module_name' => 'Textarea_paster'));
    
      // drop the exp_wygwam_configs table
      $this->EE->load->dbforge();
      $this->EE->dbforge->drop_table('wygwam_configs');
    
      return TRUE;
     }
}

and my language file:

<?php if ( ! defined('APP_VER')) exit('No direct script access allowed');

$lang = array(

// Required for MODULES page

'my_module_module_name'     => 'Textarea Paster',
'my_module_module_description'  => 'Textarea Paster adds a new fieldtype that enables the pasting of expression engine code into the field',

//----------------------------------------

// Additional Key => Value pairs go here

// END
''=>''
);

Thanks for any help

       
designbuddy's avatar
designbuddy
6 posts
14 years ago
designbuddy's avatar designbuddy

UPDATE

So I am still working at it and feel like I am getting closer, but I am still missing I feel key parts of the puzzle.

MCP:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Textarea_paster_mcp {

    function __construct()
    {
        $this->EE =& get_instance();
    }
    
    function index()
    {
     $this->EE->load->library('javascript');
        $this->EE->load->library('table');
        $this->EE->load->helper('form');
    
        $this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('textarea_paster_module_name'));
    
      /*  $vars = array();
        if (empty($this->settings['htaccess_path']) || empty($this->settings['htaccess_template']))
        {
            $vars['need_settings'] = $this->EE->lang->line('need_settings');
        }
        else
        {
            $vars['need_settings'] = false;
            $vars['link'] = "<a >".$this->EE->lang->line('generate')."</a>";
        }*/
        return $this->EE->load->view('index');
    }
    
}
// END CLASS

/* End of file mcp.textarea_paster.php */
/* Location: ./system/expressionengine/third_party/modules/textarea_paster/mcp.textarea_paster.php */

mod:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Textarea_paster
{
    public $return_data = "";

    public function __construct()
    {
        $this->EE =& get_instance();
        $this->return_data = "Hello World";
    }
}

and I now have the beginnings of a fieldtype modification:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Textarea_paster_ft extends EE_Fieldtype {

    var $info = array(
        'name'      => 'Textarea paster',
        'version'   => '0.1'
    );

    // --------------------------------------------------------------------

    function display_field($data)
    {
        return form_input(array(
            'name'  => $this->field_name,
            'id'    => $this->field_id,
            'value' => $data
        ));
    }
}
// END textarea_paster_ft class

/* End of file ft.textarea_paster.php */
/* Location: ./system/expressionengine/third_party/textarea_paster/ft.textarea_paster.php */
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.