Forums / Setup & design / Object name pattern for class

Object name pattern for class

Author Message

Marc Boon

Thursday 02 March 2006 8:33:18 am

I want to specify an attribute of an atribute of the class in the object name pattern.

For example, I have a class of type 'Country Folder', which contains as a required attribute the country, of datatype ymccountry, and some optional other attributes like map and flag images.

I would like to use the country name from the country attribute to appear as the object name. Otherwise, I have to add another text line attribute containing the country name, and including all translations for my multi-language site, which seems redundant, since these names are already contained in the ymccountry datatype.

I tried object name pattern like <country.name>, <country.data_map.name>, <country.title> etc, but they all didn't work, giving a blank name.

Any suggestions?

Sergiy Pushchin

Thursday 02 March 2006 9:08:00 am

Hi as far as I understand this is your own datatype, right?
If so you need to define function "title" in your datatype, this function should return a string, which than will be used in object name.

   /*!
     Returns the content of the string for use as a title
    */
    function title( &$contentObjectAttribute )
    {
       $countryObject = $contentObjectAttribute->attribute('content');
        return $countryObject->attribute( 'name' );
    }

I do not know your datatype (how is it written and what is returned as datatype content) so the code above mostprobably will not work for it. ;)

Marc Boon

Thursday 02 March 2006 9:42:53 am

It's actually a datatype from Contributions:
http://ez.no/community/contribs/datatypes/ymc_country

It does contain a function title():

function title( &$contentObjectAttribute )
{
    $data =& $this->countryInformation( $contentObjectAttribute );
    return $data['name'];
}

But using <country.title> or just <country> doesn't give me the title in the content tree.
How should I specify the object name pattern?

Sergiy Pushchin

Thursday 02 March 2006 2:04:52 pm

I'll check this contribution, maybe I can help you.
It is not possible to use attributes of attributes, so if the identifier of your attribute is in the class is country, then you can only use name pattern <country> and make sure that function title of the datatype returns string you need. I'll look to this datatype probably tomorrow.

Regards,
SP

Sergiy Pushchin

Thursday 02 March 2006 2:14:50 pm

Ok, I have not tested it, but from the code of the datatype it looks like to use name of the chosen country in the object name pattern you should just write identifier of your class attribute:

<country>

please let me know if it does not work.. make sure that you used correct identifier of your class attribute..

Marc Boon

Friday 03 March 2006 12:42:08 am

I had already tried <country> and it didn't work, but for a different reason.
After changing the object name pattern of a class, the names of existing objects are not updated, even after clearing all caches. You have to re-publish each existing object individually in order for the object name to be updated.

Ɓukasz Serwatka

Friday 03 March 2006 12:45:38 am

Hi Marc,

eZ publish has PHP script which you can use and update object names.

From eZ publish root directory run

php -s site_access update/common/scripts/updatecontentobjectname.php

Remember do make backup before run the script.

For full list of available options run:

php update/common/scripts/updatecontentobjectname.php -h

Useful might be also script, updateniceurls.php which updates nice urls
update/common/scripts/updateniceurls.php

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog