Store Custom Datatype attribute with CreateandpublishObject API

Author Message

Jitesh Rana

Wednesday 17 August 2011 7:19:02 am

I have a class in which custom datatype attribute. How to store data in that attribute by using createAndPublishObject API.

Following Code I have,

 <?php
$attributeList = array( 'id' => '202.1.2', //Custom DataType 
     'label' => $label);
$params = array();
$params['parent_node_id'] = $parentNodeID;
$params['creator_id'] = $creatorID;
$params['class_identifier'] = 'conditions';
$params['attributes'] = $attributeList;

$contentObject = eZContentFunctions::createAndPublishObject( $params );
?> 

Marko Žmak

Wednesday 17 August 2011 8:31:23 am

If your custom datatype supports the fromString method then the code you provided should work.

If it doesn't support fromSteing, then it depends on the custom datatype.

If this custom datatype is developed by you I suggest you implement the fromString method.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Jitesh Rana

Wednesday 17 August 2011 10:36:52 pm

Hello Marko,

There is already fromstring method implemented in custom datatype. Is this the right implementation of fromstring method for custom datatype?

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

Marko Žmak

Thursday 18 August 2011 3:51:51 am

Your code seems to be fine. It should work.

Did you put the right attruibute identifier in $attributeList?

Does your other attribute (label) get stored OK?

<span style="color: #ff0000;">$attributeList</span>

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Jitesh Rana

Thursday 18 August 2011 7:24:55 am

Hi Mark,

Yes, I have put the right attribute identifier in $attributeList. Other attribute(label) stored successfully.

following methods are there in custom datatype

     function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
    if ( $http->hasPostVariable( $base . "_data_oscar_identifier_" . $contentObjectAttribute->attribute( "id" ) ) )
        {
            $data = $http->postVariable( $base . "_data_oscar_identifier_" . $contentObjectAttribute->attribute( "id" ) );
            $contentObjectAttribute->setAttribute( "data_int", $data );
            $contentClassAttribute = eZContentClassAttribute::fetch( $contentObjectAttribute->attribute( 'contentclassattribute_id' ));
            $contentObjectAttribute->setAttribute( "data_text", $contentClassAttribute->attribute('data_text1').$data );
            return true;
        }
        return false;
    }
    /*!     Store the content. Since the content has been stored in function fetchObjectAttributeHTTPInput(),
     this function is with empty code.    */ 
   function storeObjectAttribute( $contentObjectattribute )
    {
    }
 

André R.

Tuesday 23 August 2011 5:59:28 am

According to your code from fetchObjectAttributeHttpInput it uses data_int AND (for some strange reason) data_text. This does not seems to be reflected in the fromString code.

And as Marco asked about I assume 'id' is the identifier of the attribute with this datatype as setup in the Content Class(?).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

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

eZ debug

Timing: Jan 18 2025 00:00:45
Script start
Timing: Jan 18 2025 00:00:45
Module start 'layout'
Timing: Jan 18 2025 00:00:45
Module start 'content'
Timing: Jan 18 2025 00:00:45
Module end 'content'
Timing: Jan 18 2025 00:00:45
Script end

Main resources:

Total runtime0.6568 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 588.1719152.6563
Module start 'layout' 0.00550.0026 740.828139.5313
Module start 'content' 0.00800.6473 780.3594622.5625
Module end 'content' 0.65540.0014 1,402.921915.6250
Script end 0.6568  1,418.5469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.5550160.0002
Check MTime0.00140.2205160.0001
Mysql Total
Database connection0.00110.170110.0011
Mysqli_queries0.592590.1993680.0087
Looping result0.00080.1232660.0000
Template Total0.629295.820.3146
Template load0.00280.432820.0014
Template processing0.626495.361120.3132
Template load and register function0.00030.041710.0003
states
state_id_array0.00050.080810.0005
state_identifier_array0.00110.165220.0005
Override
Cache load0.00230.3521300.0001
Sytem overhead
Fetch class attribute can translate value0.00090.138730.0003
Fetch class attribute name0.00110.168980.0001
XML
Image XML parsing0.00110.170730.0004
class_abstraction
Instantiating content class attribute0.00000.002990.0000
General
dbfile0.00100.1507250.0000
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs