relations in xml text

Author Message

Ben Pirt

Friday 20 January 2006 2:39:12 am

Hi there,
Thanks for all of the replies on my last question about creating a new node without a draft. Here's another tricky one I think...

Is it possible to be able to tell which related nodes are used in xml text fields for a node and which ones are ust related.

Why?

I am building a site where the owner is able to link up all kinds of related content to a particular page, which then gets automatically linked up in a list in the right hand column. However, sometimes he uses some of these relations in an xml text field (e.g. embedding images) and so they now show up twice on the page. If I could tell which ones were linked to the xml text area then I could choose not to show them in the RH column.

Any ideas? Short of writing an extension to return an array of related nodes to an xml field.

Cheers,

Ben

Xavier Dutoit

Friday 20 January 2006 1:14:52 pm

I made this extension extactly for the need you discribe.

http://ez.no/community/contribs/template_plugins/getobjects_extension

The name of the tag (object) has changed on 3.6, you'd have to update the code. That's simple, but I don't have the time to do it and test it... but I'd be more than happy to add the modification you're going to do on it ;)

You can find it on pubsvn too.

X+

http://www.sydesy.com

Ben Pirt

Tuesday 24 January 2006 11:18:22 am

Thanks Xavier,
Great extension and absolutely perfect for my needs. Hopefully it will be included in eZ before too long. As suggested I made some changes, which were basically to check for dom elements called "embed" and to also check if they have an attribute of "object_id". So the function "modify" is now as follows:

function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        if (!isset($namedParameters['xmlattribute']->DataText))
            return "should be an attribute";
         
        $xmldata =& $namedParameters['xmlattribute']->DataText;
        $xml = new eZXML();
        $dom =& $xml->domTree( $xmldata );
        if ( is_object ($dom) )
        {
            $objects =& $dom->elementsByName( "embed" );
            foreach ($objects as $object)
            {
                $attributes=& $object->attributes();
                foreach ($attributes as $attribute)
                {
                    if ($attribute->Name == "object_id")
                        $operatorValue[] = $attribute->content;
                } 
            }
        }
    }

I haven't done a check for the eZ version, but this is working perfectly on my 3.6 installation.

Thanks again,

Ben Pirt

Xavier Dutoit

Wednesday 25 January 2006 12:05:59 am

Thanks for your contrib,

I've modified it so it's compatible both with 3.5 and 3.6.
That's on pubsvn and on the contrib area too;

Could you test with your config and tell me if it's ok ?

X+

http://www.sydesy.com

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