0
votes

Currently I'm trying to create nice looking URL's for my custom extension.

I am using a plugin on page "Products" (uid: 3) to list all categories.

For example there are the following categories:

  • Men
    • Shirts
    • Sweatshirts
  • Women
    • Shoes
    • Dresses

I'd like to have these corresponding URL's:

www.mydomain.com/products/men.html

www.mydomain.com/products/men/shirts.html

This is, what I get:

www.mydomain.com/products//men.html

www.mydomain.com/products/men/shirts.html

The category "Men" on the first Level does not have a parent category, so this segment remains empty. As soon as there is a parent category, everything is fine.

TYPO3 Version: 7.6.15

realurl Version: 2.1.6

This is my current configuration for fixedPostVars:

'fixedPostVars' => array ( 
// EXT: productsDb start           
'productsDbConfiguration' => array(
    array(
        'GETvar' => 'tx_productsdb_categories[action]',
        'valueMap' => array(
        ),
        'noMatch' => 'bypass'
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[controller]',
        'valueMap' => array(
        ),
        'noMatch' => 'bypass'
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[parent]',
        'lookUpTable' => array(
            'table' => 'tx_productsdb_domain_model_category',
            'id_field' => 'uid',
            'alias_field' => 'title',
            'addWhereClause' => ' AND NOT deleted',
            'useUniqueCache' => 1,
            'useUniqueCache_conf' => array(
                'strtolower' => 1,
                'spaceCharacter' => '-'
            ),
            'languageGetVar' => 'L',
            'languageExceptionUids' => '',
            'languageField' => 'sys_language_uid',
            'transOrigPointerField' => 'l10n_parent',
            //'autoUpdate' => 1,
            //'expireDays' => 180,
        ),
       // 'valueDefault' => '',
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[category]',
        'lookUpTable' => array(
            'table' => 'tx_productsdb_domain_model_category',
            'id_field' => 'uid',
            'alias_field' => 'title',
            'addWhereClause' => ' AND NOT deleted',
            'useUniqueCache' => 1,
            'useUniqueCache_conf' => array(
                'strtolower' => 1,
                'spaceCharacter' => '-'
            ),
            'languageGetVar' => 'L',
            'languageExceptionUids' => '',
            'languageField' => 'sys_language_uid',
            'transOrigPointerField' => 'l10n_parent',
            //'autoUpdate' => 1,
            //'expireDays' => 180,
        )
    ),
),
'3' => 'productsDbConfiguration',
// EXT: productsdb end

),

So, here is my question: Is there a way and what do I need to do, to skip an optional path segment, if it is empty?

Thanks in advance for having a look at it.

1
As there seems to be no other solution, I decided for now to use the encodeSpURL_postProc hook of realurl, to modify the encoded URL to my needs, though it feels kind of dirty to do it this way.IhsakoOti

1 Answers

0
votes

here's the code I used for the realurl encodeSpURL_postProc hook:

public function encodeUrl(&$params) {
    $originalParameters = $params['pObj']->getOriginalUrlParameters();

    if(array_key_exists('tx_productsdb_categories[category]', $originalParameters)===TRUE) {
        if (strpos($params['URL'], '//')) {
            $encodedSegments = explode('/', $params['URL']);
            $modifiedSegments = array_filter($encodedSegments, 'strlen');
            $params['URL'] = implode('/', $modifiedSegments);
        }
    }
}

let me know, if you got any other ideas for improvement.