ibexa

Path

ez publish / technical manual / 4.4 / features / multi-language support for... / custom transformation commands


Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

Custom transformation commands

In order to transform the URLs according to specific needs, it is possible to create and use so-called custom commands. The commands can be created as extensions and added to the system using an override of the "transform.ini" configuration file. The following text explains how to create a custom transformation command for URLs.

Let's say that for some reason, we would like all URLs to be reversed. This can be achieved by creating a custom transformation command.

1. Creating a new extension

A new file must be create and placed inside the directory of an extension. The file must contain a class that has a static method called "executeCommand" with three parameters: "$text", "$command" and "$charsetName".

  • $text - The input text to transform
  • $command - The name of the command to execute, this can be used to keep multiple commands in one function
  • $charsetName - The name of the charset in use for $text, usually not needed

In this example, we will create a "myreverse.php" file under the "extension/myextension/transformation" directory and put the following lines of code into it:

<?php
   class MyReverse
   {
       function executeCommand( $text, $command, $charsetName )
       {
           $text = strrev( $text );
           return $text;
       }
   }
?>

As the code shows, the function will return a reversed version of the inputted text.

2. Registering a new transformation command in the "transform.ini" file

The command must be registered in the "transform.ini" configuration file. To do that, you need to add a new line into the "Commands[]" array located under the "[Extensions]" section. The line must contain the path to the PHP file, a colon (used for separation) and the class name that should be used. The following example demonstrates how this can be done.

[Extensions]
Commands[]
Commands[my_reverse]=extension/myextension/transformation/myreverse.php:MyReverse

3. Adding a new command to the corresponding transformation group

The newly created command must be added in the "transform.ini" file to one of the groups that will be used for URL text transformation. In the example below, the custom command "my_reverse" is added to the "urlalias_iri" transformation group.

[urlalias_iri]
 
Commands[]
Commands[]=url_cleanup_iri
Commands[]=my_reverse

From now on, newly generated URLs will be reversed because they will be processed by the custom "my_reverse" command that we added to the list of commands to be performed when the "urlalias_iri" transformation method is used.

Julia Shymova (14/09/2010 12:21 pm)

Geir Arne Waaler (28/09/2010 6:47 pm)

Julia Shymova, Balazs Halasy, Geir Arne Waaler


Comments

  • Could you confirm it handles the collisions ?

    Hi,

    What happends if my transformation generates an already used url ? is the _1, _2 suffix added later in the chain ?

    X+
  • order and inheritance

    thanks. may I suggest to address the following in the above documentation:

    - in the example, in which order would the commands be executed ?

    - could you present the example using transform.ini.append.php instead of transform.ini (do you still need to add "url_cleanup_iri" to the commands - wouldnt that be inherited from the global "transform.ini" ?)

    $2c,
    *-pike