Forums / Developer / Empty an ezkeyword field in PHP ?

Empty an ezkeyword field in PHP ?

Author Message

Benoit Vodkaster

Wednesday 14 October 2009 1:28:32 pm

Hello,

In a content class, I have an ezkeyword field ('my_field') which Id like to update in PHP

I use the usual fromString() function

$contentObjectAttributes = $contentObject->fetchAttributesByIdentifier(array('my_field'), $new_version_id, $languageCode);

foreach($contentObjectAttributes as $key => $contentObjectAttribute)
{
  $contentObjectAttribute->fromString($my_new_value);
  $contentObjectAttribute->store();
}

... which works fine when <b>$my_new_value</b> is not set to ''
but it does not change anything when <b>$my_new_value</b> is empty

I've had a look in <b>classes/datatypes/ezkeyword/ezkeywordtype.php</b> and I've found this circa line 285

function fromString( $contentObjectAttribute, $string )
{
  if ( $string != '' )
  {
    $keyword = new eZKeyword();
    $keyword->initializeKeyword( $string );
    $contentObjectAttribute ->setContent( $keyword );
  }
  return true;
}

... which explains why nothing happens in my fromString when <b>$my_new_value</b> is empty

So my question is : <b>how do I empty in PHP an ezkeyword field ?</b>

Thanks a lot in advance
Benoit

Piotrek Karaƛ

Wednesday 14 October 2009 9:33:27 pm

Try investigating eZKeywordType::deleteStoredObjectAttribute() method.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Benoit Vodkaster

Thursday 15 October 2009 7:14:11 am

Thanks Piotrek

I just did a

  $dataType = $newContentObjectAttribute->dataType();
  $dataType->deleteStoredObjectAttribute($newContentObjectAttribute);

and it works fine
Thanks

Hugues Charleux

Wednesday 29 September 2010 3:36:28 am

Sorry to up this one year old topic but I just ran into the same issue (except I did not notice this behavior before production stage x( )

I just filled up a ticket on issues.ez.no [1] as I think we should not have to make a workarround for this but fromString should empty attribute if an empty param is given (as it does for other datatypes).

[1] http://issues.ez.no/IssueView.php?Id=17352&activeItem=1