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.