3 users online. Create an account or sign in to join them.Users

Search

I’ve been working on my Color Chooser Field extension and I’ve really trimmed down the code to be more efficient, but I’ve started getting an error in the log:

2009/08/24 13:31:36 > WARNING: 512 - MySQL Error (1146): Table 'sym_test.sym_entries_data_' doesn't exist in query "DELETE FROM sym_entries_data_ WHERE  `entry_id` = '123'" in file /Users/jnichols/Sites/sym-test/symphony/lib/toolkit/class.mysql.php on line 401

I get this error every time I save an entry that contains the color chooser field. Any ideas on what I did wrong? I’m a bit lost right now.

Here’s my code:

<?php

if (!defined('__IN_SYMPHONY__')) die('<h2>Symphony Error</h2><p>You cannot directly access this file</p>');

require_once(TOOLKIT . '/fields/field.input.php');

Class fieldColorChooser extends Field{

            function __construct(&$parent){
                parent::__construct($parent);
                $this->_name = 'Color Chooser';
                $this->_required = true;
                $this->set('required', 'no');
            }       

            function displaySettingsPanel(&$wrapper, $errors=NULL){
                parent::displaySettingsPanel($wrapper, $errors);

                $this->appendRequiredCheckbox($wrapper);
                $this->appendShowColumnCheckbox($wrapper);
            }

            function displayPublishPanel(&$wrapper, $data=NULL, $flagWithError=NULL, $fieldnamePrefix=NULL, $fieldnamePostfix=NULL){

                //Waiting on documentation on how to efficiently add scripts to the admin area.
                //$this->_engine->Page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/farbtastic.js', 180);
                //$this->_engine->Page->addScriptToHead(URL . '/extensions/color_chooser_field/assets/color-chooser.js', 185);
                //$this->_engine->Page->addStylesheetToHead(URL . '/extensions/color_chooser_field/assets/farbtastic.css', 'screen', 190);

                $value = $data['value'];        
                $label = Widget::Label($this->get('label'));
                $label->setAttribute('class', 'color-chooser');
                if($this->get('required') != 'yes') $label->appendChild(new XMLElement('i', 'Optional'));
                $label->appendChild(Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (strlen($value) != 0 ? $value : '#')));

                if($flagWithError != NULL) $wrapper->appendChild(Widget::wrapFormElementWithError($label, $flagWithError));
                else $wrapper->appendChild($label);
            }

            function checkPostFieldData($data, &$message, $entry_id=NULL){
                $message = NULL;

                if($this->get('required') == 'yes' && strlen($data) == 0 ){
                    $message = "This is a required field.";
                    return self::__MISSING_FIELDS__;
                }
                // The Farbtastic needs a value in the field to work. '#' is the default value placed by the js.
                if($this->get('required') == 'yes' && $data == "#" ){
                    $message = "This is a required field.";
                    return self::__MISSING_FIELDS__;
                }
                // Make sure the value entered is a valid hex color, '#' or '' is OK
                if($data !== '#' && strlen($data) !== 0 ){
                    if(!preg_match("/^#[0-9a-f]{6}$/i" , $data)){
                        $message = "This is not a valid 6 character hex color value.";
                        return self::__MISSING_FIELDS__;
                    }
                }

                return self::__OK__;

            }       

        }

    ?>

Thanks!

It seems like there is an ID missing somewhere as sym_entries_data_ should be something like sym_entries_data_123. Are you sure this only happens with your field?

Other sections without the field don’t throw the error until I add a color chooser field.

I also noticed that I can’t filter or sort by the color chooser field in the DS editor. It looks like I have to add

function isSortable(){
                return true;
            }

            function canFilter(){
                return true;
            }

            function allowDatasourceOutputGrouping(){
                return true;
            }

            function allowDatasourceParamOutput(){
                return true;
            }

back in. I thought I could inherit this stuff from the default input field. :-/

Is it possible that you have to extend ‘fieldInput’ instead of ‘Field’?

Niles, I think you were right.

Well, my original code doesn’t give any errors. I’ll stick with that for a while longer. Every time I make a change, something else breaks, so I’ll hold off on optimizing until extension documentation is more complete.

Thanks for the help!

I noticed your field has no createTable() function. Currently, Symphony assumes that all field, when added to a section, will create a table for storing the entry data. E.G. the selectbox function looks like:

function createTable(){

    return Symphony::Database()->query(

        "CREATE TABLE IF NOT EXISTS `sym_entries_data_" . $this->get('id') . "` (
          `id` int(11) unsigned NOT NULL auto_increment,
          `entry_id` int(11) unsigned NOT NULL,
          `handle` varchar(255) default NULL,
          `value` varchar(255) default NULL,
          PRIMARY KEY  (`id`),
          KEY `entry_id` (`entry_id`),
          KEY `handle` (`handle`),
          KEY `value` (`value`)
        ) TYPE=MyISAM;"

    );
}

So, when Symphony tries to manipulate an entry, it looks for this table.

I noticed your field has no createTable() function.

But if you extend an existing field, that has its own createTable() function, shouldn’t this function be used then?

Eh, yes true.

So then

class fieldColorChooser extends fieldInput { }

should work.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details