$doc = $modx->newObject('modDocument'); $data = array( 'pagetitle' => $title, // $title="Joé, the slow one !" 'alias' => $title // how to create the alias ? "joe-the-slow-one" );
There is an API call for it, but it is on the list of things to be addressed/improved before RC1 release, including adding the event for custom TransAlias plugins to work with, as well as adding error handling for duplicate aliases or other potential conflicts. Some of these features were added to Evolution after Revolution was branched off and needs to be synced back up. This should be addressed in the next couple of days.
If I’m understanding you, there’s no API call for that. You’d have to create a plugin attached to the OnBeforeDocFormSave event and do it there.
Your users would leave the alias blank and the alias would be generated as they saved the document.
$title = 'Title of the document'; makeAlias($title); function makeAlias($url){ $url = no_accent($url); $url = ereg_replace("[^a-z A-Z0-9-]*","",$url); $url = ereg_replace("-{2,}","-",$url); $url = ereg_replace(' ','-',$url); $url = trim(strtolower($url)); $url = ltrim($url,'-'); $url = rtrim($url,'-'); return $url; } function no_accent($filename) { $str = strtr(utf8_decode($filename),utf8_decode("ÀÁÂÃÄÅÇÑñÇçÈÉÊËÌÍÎÏÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöøùúûüýÿ' "), "AAAAAACNnCcEEEEIIIIOOOOOOUUUUYaaaaaaceeeeiiiiooooooouuuuyy--" ); return $str; }
modX::makeUrl() is for getting the URL of existing Resources, not of ones that are being created. The code in the processor is what checks to make sure unique URLs are being generated when you attempt to save the Resource with a particular alias. The alias is cleansed (using modResource::cleanAlias()) and then the URL is constructed (from the parents if friendly_alias_path is enabled) and checked against the existing URLs in the system. This entire process will be moved into a single function before RC1, and will include an invocation of the event OnStripAlias to which you can attach plugins to alter the process.
i just saw that modX::makeUrl can generate a URL representing a specified resource.