Forums / Developer / Problem using eZYuiColorPicker with eZContentFunctions::createAndPublishObject

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

eZ debug

Timing: Jan 29 2025 13:45:49
Script start
Timing: Jan 29 2025 13:45:49
Module start 'content'
Timing: Jan 29 2025 13:45:49
Module end 'content'
Timing: Jan 29 2025 13:45:49
Script end

Main resources:

Total runtime0.1254 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 588.3125180.7813
Module start 'content' 0.00490.0053 769.093898.7422
Module end 'content' 0.01020.1151 867.8359532.5000
Script end 0.1253  1,400.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00342.7352200.0002
Check MTime0.00141.1472200.0001
Mysql Total
Database connection0.00050.422710.0005
Mysqli_queries0.085768.38061410.0006
Looping result0.00100.80061390.0000
Template Total0.114891.510.1148
Template load0.00090.744110.0009
Template processing0.113890.778510.1138
Override
Cache load0.00070.573510.0007
Sytem overhead
Fetch class attribute can translate value0.00070.571210.0007
XML
Image XML parsing0.00020.193010.0002
General
dbfile0.00453.5860200.0002
String conversion0.00000.004230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs