Forums / Developer / [Solved] Problem with embed tag in XMLBlock

[Solved] Problem with embed tag in XMLBlock

Author Message

Damien MARTIN

Monday 08 March 2010 7:59:11 am

Hi,

I have a problem with an XMLBlock filled from PHP :

$params = array();
$params['parent_node_id'] = 2;
$params['class_identifier'] = 'article';
$params['creator_id'] = 14;
$params['section_id'] = 1;
             
$attributesData = array();
            
$attributesData['title'] = 'My article';
$attributesData['body'] = $content;

$params['attributes'] = $attributesData;
$contentObject = eZContentFunctions::createAndPublishObject( $params );

The content of $content is a valide ez xml code :

<?xml version="1.0" encoding="utf-8" ?>
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" 
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">

<header level="1">My Title</header>
 
<link href="http://my.url.tld/pages/infos.php">
    <embed align="left" view="embed" size="medium" href="ezobject://372"/>
</link>

Hello World

</section>

Note : The ezobject with ContentObjectID = 372 has been created just before from the same extension. (It's an image)

The problem is :

  • When I watch the preview of the article from the admin, there is no image.
  • When I edit the article with the online editor, it stops at the link (No "Hello World" string)
  • When I edit directly the source, the href attribute is empty :
<embed align="left" view="embed" size="medium" href=""/>

But if I modify the embed tag and put ezobject://372, the image appears correctly.

So, the question is : Why does eZ don't take my embeded object correctly at the article creation while editing it to put the same value works ?

I can't do it manually on each page, because their will be a lot of page imported by the extension (500+).

Thanks in advance,

Damien

Damien MARTIN

Monday 15 March 2010 7:30:49 am

Hi there,

It looks like my problem isn't so funny :p

I'm looking at the source code of ezodf and I saw the wonderfull eZContentObject::addContentObjectRelation() method.

I think it could save my life but I still don't understand how to use it.

I created my pictures, stored their content object id and tryed a pretty looking :

$o->addContentObjectRelation($object);

Where $o is the newly created "Article" where my XMLBlock is written.

But it don't still works...

The pictures appears in the related objects but the href attribute of the embed tag is still empty.

NB : I also tryed

$o->addContentObjectRelation($object, false, 0, eZContentObject::RELATION_EMBED);

Could someone help me ?

Thanks in advance,

Damien

Nicolas Pastorino

Monday 15 March 2010 8:26:13 am

"
$o->addContentObjectRelation($object, false, 0, eZContentObject::RELATION_EMBED);
"

Hello Damien,

The above looks ok to me, but for the first parameter: you need to pass the object ID, and not the eZContentObject object. What exactly does the $object variable contain in your example ?

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Damien MARTIN

Monday 15 March 2010 8:57:59 am

Hi Nicolas,

$object is the result of :

$my_object = eZContentFunctions::createAndPublishObject($params);

if($my_object != null)
    return $my_object->ID;

But this part works (I can see the related image in the last panel of the editor "Related objects" ).

My problem is that the href attribute of my ezxml is still empty...

When I update it by hand (disabling "online editor" ), the image is well integrated in my XML Block...

I thought addContentObjectObjectRelation was the solution to my problem, but it looks like eZ do something more and I don't know what.

Thanks,

Damien

Damien MARTIN

Wednesday 17 March 2010 2:26:46 am

Hi there,

I finaly found what was wrong :

When you add the tag for embeding images, you should not use the href attribute, but an object_id attribute.

so :

<embed align="left" view="embed" size="medium" href="ezobject://372"/>

become :

<embed align="left" view="embed" size="medium" object_id="372"/>

And eZ will do everything !!!

Nicolas Pastorino

Wednesday 17 March 2010 3:07:35 am

Wow, that actually rocks.

Thanks for the investigation, i'm sure it will help others :)

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye