Realurl: generate the url using userFunc

I wanted to see if I was able to create my own urls using UserFunc because realUrl was not doing what it’s supposed to do. Thats why I added the field “url” to my entry model, which realurl should use if it is set. If not, I want it to use the title field, cleaned up by realurl.

To turn “This is a Test” into “this-is-a-test”, the UrlEncoder offers the function cleanUpAlias

This is how the realurl_conf.php part looks like:

'fixedPostVars' => array(
    141 => array(
        array('GETvar' => 'tx_ophipage_entrydetail[controller]', 'noMatch' => 'bypass'),
        array('GETvar' => 'tx_ophipage_entrydetail[action]', 'noMatch' => 'bypass'),
            'GETvar' => 'tx_ophipage_entrydetail[entry]',
            'userFunc' => 'Ophi\OphiPage\UserFunctions\RealUrl->getUrl',
            'lookUpTable' => array(
                'table' => 'tx_ophipage_domain_model_entry',
                'id_field' => 'uid',
                'alias_field' => 'coalesce(NULLIF(url, ""), title)',
                'addWhereClause' => ' AND deleted != 1',
                'useUniqueCache' => 1,
                'useUniqueCache_conf' => array(
                    'strtolower' => 1,
                    'spaceCharacter' => '-',
                'languageGetVar' => 'L',
                'languageField' => 'sys_language_uid',
                'transOrigPointerField' => 'l10n_parent',
                'enable404forInvalidAlias' => 1,

And the php file looks like this:

namespace Ophi\OphiPage\UserFunctions;

class RealUrl {

    public function getUrl(&$params, $ref){
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('url, title', 'tx_ophipage_domain_model_entry', 'uid='.$params['value']);
        return $res['url'] ? $res['url'] : $ref->cleanUpAlias($ref->getOriginalUrlParameters(), $res['title']);

Works good so far.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.