Problem using eZYuiColorPicker with eZContentFunctions::createAndPublishObject

Author Message

Damien MARTIN

Monday 25 January 2010 8:44:13 am

Hi there,

I use an "old" datatype extension to allow my users to pick colors with a nice color picker made with YUI.

http://ez.no/fr/developer/contribs/datatypes/ez_yui_color_picker

Inside the eZ publication system it works very well, but I have to create new objects from an extension.

So, this a shorten piece of code :

public static function nouvelleTache($vars){
        
    // Paramètres de l'objet
    $params = array();
    $params['parent_node_id'] =     $vars->variable("parent_node_id");
    $params['class_identifier'] =   'tache';
    $params['creator_id'] =         234;
    $params['section_id'] =         1;
    
    // Attributs de l'objet
    $attributesData = array();
    $attributesData['nom'] = $vars->variable("nom");
    // ...
    $attributesData['couleur'] = $vars->variable("attribut_couleur_picker");
    
    $params['attributes'] = $attributesData;
    
    $objet_cree = eZContentFunctions::createAndPublishObject($params);
    
    if($objet_cree != null)
        return true;
    
    return false;
    
}

So the problem would be at the line :

$attributesData['couleur'] = $vars->variable("attribut_couleur_picker");

Where $vars->variable("attribut_couleur_picker") correctly contains the hexa of the color (without the leading #).

But when the object is created the value stills empty...

It took a look at the class of the datatype (extension/ezyuicolorpicker/datatypes/ezyuicolorpicker/ezyuicolorpickertype.php) for the function who should be used.

But :

  • I never wrote a DataType extension
  • I don't know what should be the function (I excpected something like "fromString" :) )

Could you help me with that ?

Thanks,

Damien

Damien Pobel

Monday 25 January 2010 3:40:21 pm

Hi Damien,

It seems that this datatype does not support the fromString/toString feature that's why you're attribute is always empty when you create your object with eZContentFunctions::createAndPublishObject(). The value of an ezyuicolorpicker attribute is stored in the data_text column so if you add the following fromString() method to the datatype class (the same as in the ezstring datatype in fact) it should work :

function fromString( $contentObjectAttribute, $string )
{
    return $contentObjectAttribute->setAttribute( 'data_text', $string );
}

Hope that helps.

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Damien MARTIN

Tuesday 26 January 2010 12:20:20 am

Thank you very much Damien,

It works very well !

Maybe it would be great to update the DataType to add the fromString to other users...

But the project seems to be abandoned since a long time.

Do you think we should create a new project on projects.ez.no ?
Or maybe the color picker will be added by default with eZ 4.3 ? (as I understood that the admin will be rewritten using AJAX and YUI).

Thanks,

Damien

Damien Pobel

Tuesday 26 January 2010 2:17:05 am

Feel free to create a project on http://projects.ez.no if you want to share your modiication. You can also contact the author of the project (Arnaud Georgin) to tell him that you put the extension on projects.ez.no.

I took a quick look at the extension code, I see some minor issues/possible improvements :

  • The code should be ported to PHP5 to not throw Strict errors messages
  • use ezjscore to load Javascript more quickly (if you use eZ Publish 4.2)
  • "Sélectionner une couleur :" label in the edit template can not translated

and there's probably others.

Cheers !

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.