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

Custom Fieldtype Data

Development and Programming

Wes Rice's avatar
Wes Rice
103 posts
16 years ago
Wes Rice's avatar Wes Rice

I’m writing a fieldtype and I need for it to have some custom field options. It is my opinion that exp_channel_fields should have an additional field called ‘field_options’ so developers can store a their options with the field. Storing the options in a separate table doesn’t really make sense to me, being that nearly all custom fields will have some custom field options.

function display_settings($data)
    {
        // If the 'field_options' column does not exist, add it to hold the field options        
        if (!$this->EE->db->field_exists('field_options', 'channel_fields'))
        {
            // Load the dbforge class
            $this->EE->load->dbforge();
            
            // Create the field
            $fields = array(
                'field_options' => array('type' => 'TEXT')
            );
            
            // Add the column to the table
            $this->EE->dbforge->add_column('channel_fields', $fields);
        }
        
        // Check if the User ID has been previously entered
        $field_options = ($data['field_options'] == '') ? '' : $data['field_options'];
        
        // Load in the langauge file
        $this->EE->lang->loadfile('vimeeo');
        
        // Input for User ID
        $this->EE->table->add_row(
            lang($this->EE->lang->line('ft_vimeo_user_id')),
            form_input(array('id'=>'field_options','name'=>'field_options', 'size'=>8,'value'=>$field_options))
        );
        
    }

The code above works, but I am wanting storing a serialized array of multiple form inputs in my ‘field_options’ column. I was assuming that I could capture the post data of the the fields and serialize an array in the save_settings function, but apparently the data is stored to the database before the save_settings function is called.

So here are my questions: 1) Would my method of creating the field_options column in the exp_channel_fields database be considered a best practice? If not, what should I be doing?

2) How can I intercept the post data before it is saved to the database?

Thanks!

       
Wes Rice's avatar
Wes Rice
103 posts
16 years ago
Wes Rice's avatar Wes Rice

Anyone? Anyone? Anyone?

       
Wes Rice's avatar
Wes Rice
103 posts
16 years ago
Wes Rice's avatar Wes Rice

Question #2 was answered with a bugfix in the newest build.

However, I’m still in the dark about where I should be saving my field options. I wish a mod would speak up.

       
Derek Hogue's avatar
Derek Hogue
317 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Here here. Why should EE-native fields get all the settings (each with its own distinct field even)? If the Custom Field API is going to replace FieldFrame, settings are a must. As it stands, this is broken for me.

       
Newism's avatar
Newism
30 posts
16 years ago
Newism's avatar Newism
Here here. Why should EE-native fields get all the settings (each with its own distinct field even)? If the Custom Field API is going to replace FieldFrame, settings are a must. As it stands, this is broken for me.

Check out the readme for NSM TinyMCE. I figured out how to enable per field settings. You can use my code as an example of how to save / read them as well. It’s all really well commented.

       
Derek Hogue's avatar
Derek Hogue
317 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Thanks Leevi, just checked it out, very nice. I’ll probably wait it out until official supported methods are out on this one, and focus time on extensions I can port hack-free for the moment.

       
Wes Rice's avatar
Wes Rice
103 posts
16 years ago
Wes Rice's avatar Wes Rice

I really hope they have some official supported methods on this soon. I would hate for their to be an influx of different fieldtypes with different ways to save the fieldtype options. It would be a hot mess.

I’m going to go ahead and report this thread to the bug tracker. Hopefully we can get some answers.

       

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.