Forums / Developer / createandpublishobject : links in ezxmltext
Benjamin Plaquevent
Thursday 20 August 2009 1:37:24 am
Hi,
I wrote a script to import data in a Exponential site.
I encounter issues when I want to store a link in a ezxmltext attribute :
At first, all links are OK but after edition of any object, all imported links desappear. I found that it was because urls are stored in ezurl table but nothing in ezurl_object_link.
Why doesn't eZContentFunctions::createAndPublishObject method store anything into ezurl_object_link in this case?
Is there something to do after eZContentFunctions::createAndPublishObject to create the correct record into ezurl_object_link table?
My code:
$text = '<a href="' . $href . '" target="_blank">' . $link_text . '</a>'; $attributes["body"] = $this->getXML($texte); // a method returning valid Exponential XML $param_creation = array( 'parent_node_id' => $parent_node_id, 'class_identifier' => 'breve', 'creator_id' => $creator_id, 'attributes' => $attributes); $object = eZContentFunctions::createAndPublishObject($param_creation);
Friendly,
Ben.
Benjamin Plaquevent Project Manager Smile
Thursday 20 August 2009 2:00:09 am
I solved this issue :
$url_id = eZURL::registerURL($href); $text = '<a href="' . $href . '" target="_blank">' . $link_text . '</a>'; $attributes["body"] = $this->getXML($texte); // a method returning valid Exponential XML $param_creation = array( 'parent_node_id' => $parent_node_id, 'class_identifier' => 'breve', 'creator_id' => $creator_id, 'attributes' => $attributes); $object = eZContentFunctions::createAndPublishObject($param_creation); $data_map = $object->dataMap(); $object_attribute_id = $data_map['body']->attribute('id'); $object_attribute_version = $data_map['body']->attribute('version'); if (!eZURLObjectLink::fetch($url_id, $object_attribute_id, $object_attribute_version, false)) { $link_object_link = eZURLObjectLink::create( $url_id, $object_attribute_id, $object_attribute_version); $link_object_link->store(); }
I'm not sure this is the right way to do things so feel free to give me a better solution.
I steel don't understand why eZContentFunctions::createAndPublishObject method didn't create a record in ezurl_object_link table...