TYPO3 Realurl Configuration Category Page - typo3

I have TYPO3 7.6.10.
I have tx_news.
I want to configure my page with news by category.
Now i have:
'newsCategoryConfiguration' => array(
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][categories]',
'lookUpTable' => array(
'table' => 'sys_category',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-'
)
)
)
),
It works and the result is:
/domain/page-With-List-Of-News-By-Category/Category
If have a sub category the result is:
/domain/-page-With-List-Of-News-By-Category/Category
Ho can i get:
/domain/page-With-List-Of-News-By-Category/Parent-Category/Sub-Category

Maybe there's a faster or better way. But if you won't find, try this and build it yourself using userfunc in that way:
'useUniqueCache_conf' => [
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'My\Ext\Hooks\News\RealUrlCategories->buildCategoryPath'
];
and the class something like:
class RealUrlCategories {
function buildCategoryPath($parameters) {
$categoriesPath = '';
// find category rootline
// you can find the uid somewhere in $parameters, then iterate for parent categories and read db for the titles to build final string
...
// return generated string like "Parent-Category/Sub-Category"
return $categoriesPath;
}
}

The problem is, that realURL parses the result of the userFunc with rawurlencode. So Parent-Category/Sub-Category would be transformed to Parent-Category%252FSub-Category.
You could return Parent-Category-Sub-Category. This would also be stored in the cache.
Also your UserFunc could return Parent-Category~~~Sub-Category and you replace the ~~~ with a / in a $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['encodeSpURL_postProc'] hook, but the ~~~ will be stored in the cache.
You could also add another parameter like parent_category, but this optional parameter doesn't work in the fixesPostVars section because here the parameter is required and so if it is empty, you have an double slash //category in your URL.
Could you find any other solution beside to use the format parent-category-sub-category?

Related

Realurl create paths with several parts like detail/land-1/name-1

I have an extension for items, each has several fields. One field is name and one field is country.
In realurl_conf.php i can create a url like:
detail/name-1
with:
name' => array(
array(
'GETvar' => 'tx_myext_myplugin[model]',
'lookUpTable' => array(
'table' => 'tx_myext_domain_model_model',
'id_field' => 'uid',
'alias_field' => 'name',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
),
),
),
But what if i also want to have the country in the url, like:
detail/country-xy/name-1
How can i achieve this?
Realurl can only map arguments which are available. Therefore you must also provide the country to the typolink generation.

TYPO3 - realurl is ignoring created/own extension

I have a running TYPO3 installation (7.6) with with the latest realurl and news extension. All working fine. I now created a simple extension tx_ffscarexample and struggling to manipulate the paths for it. In tx_ffscarexample I have 'list, show, new, create, edit, update, delete' actions. Now, when first calling the page /car-example/ with the List View ... my path looks like:
List View
/car-example/
... I get all records showing in a table.
But already when I hover over the links I get like
/car-example/?tx_ffscarexample_carlist[car]=3&tx_ffscarexample_carlist[action]=show&tx_ffscarexample_carlist[controller]=Car&cHash=0b3f5b986dsdf95f33465e3d324e1e83a
When I then go into a detail view ... I get e.g.
Show View
/car-example/?tx_ffscarexample_carlist[car]=3&tx_ffscarexample_carlist[action]=show&tx_ffscarexample_carlist[controller]=Car&cHash=0b3f5b236dd5295f5f6234d324e1e83a
New View
/car-example/?tx_ffscarexample_carlist[action]=new&tx_ffscarexample_carlist[controller]=Car&cHash=4df2347378f318530423761f7627394a6
Edit View
/car-example/?tx_ffscarexample_carlist%5Bcar%5D=15&tx_ffscarexample_carlist%5Baction%5D=edit&tx_ffscarexample_carlist%5Bcontroller%5D=Car&cHash=72344542eaf1c64c12347dd3c7714
List View
/car-example/?tx_ffscarexample_carlist[action]=list&tx_ffscarexample_carlist[controller]=Car&cHash=23d56247c27805c2c234c8c23353c7e
In realurl_conf.php I've added for the extension:
...
'postVarSets' => array(
'_DEFAULT' => array(
'car' => array(
array(
'GETvar' => 'tx_ffscarexample_carlist[action]',
'valueMap' => array(
'list' => 'list',
'show' => 'show',
'new' => 'new',
'edit' => 'edit',
'create' => 'create',
'delete' => 'delete',
'update' => 'udpate'
),
'noMatch' => 'bypass'
),
array(
'GETvar' => 'tx_ffscarexample_carlist[controller]',
'valueMap' => array(
'car' => 'car',
),
'noMatch' => 'bypass'
),
array(
'GETvar' => 'tx_ffscarexample_carlist[car]',
'lookUpTable' => array(
'table' => 'tx_ffscarexample_domain_model_car',
'id_field' => 'uid',
'alias_field' => 'name',
'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,
)
)
),
),
)
...
What am I missing?
What I would like to have is sth like ...
/car-example/car/
/car-example/car/new
/car-example/car/audi/
/car-example/car/audi/edit/
/car-example/car/audi/delete/
/car-example/car/bmw/
/car-example/car/bmw/edit/
/car-example/car/bmw/delete/
Seems like here are similar issues:
typo3 7, bootstrap_package, RealUrl and own extension
Fixed it. What I did was:
I deactivated and removed the extension.
Deleted typo3temp and all realurl tables.
Cleared caches in InstallTool
Installed the extension again.
-> Now everything works as expected
*Please make copies of records and tables before removing them just in case.
It might be due to the installation order:
"The order you will install the extensions matters! Make sure the RealURL extension is installed first, then the bootstrap package and afterwards the rest of the extensions which contain RealURL rules including your new one." (Source: https://aimeos.org/tips/tag/realurl/ )

Multiple Values in RealUrl

When I got multiple values in my URL of the same name
e.g …&tx_myext_pi1[crit][]=1&tx_myext_pi1[crit][]=2…
and I want to have it multiple times in my RealUrl-ified URL
like …/crit/title-of-crit-1/crit/title-of-crit-2…
it's not working.
I only get …/crit/title-of-crit-1… and …/crit/title-of-crit-2… is missing
…&tx_myext_pi1[crit][]=1…
translates to …/crit/title-of-crit-1/… and
…&tx_myext_pi1[crit][]=2…
translates to …/crit/title-of-crit-2/…
so that part is working. But not multiple values.
Is this impossible to do with RealUrl?
Should I make a userFunc? How?
My RealUrl Conf
// …
'postVarSets' => array(
'_DEFAULT' => array(
'crit' => array(
array(
'GETvar' => 'tx_myext_pi1[crit][]',
'lookUpTable' => array(
'table' => 'tx_myext_domain_model_crit',
'id_field' => 'uid',
'alias_field' => 'title',
'languageGetVar' => 'L',
'languageExceptionUids' => '',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'autoUpdate' => 1,
),
),
),
),
// …
Is this impossible to do with RealUrl?
Yes, is impossible to achieve this using RealUrl.
The problem is that you are using array in the query string.
You can merge your values in one string
Like this:
/crit/title-of-crit-1,title-of-crit-1
Or
/crit/title-of-crit-1+title-of-crit-1
And split it when you need. by , Or + or another special character.
For example Drupal uses this rule for multiple values in views moudle.

Typo3 RealURL news links with news id

I want my news article URLs to be of the following form: http://domain.com/news/news-title-for-seo-and-usability-324/
And I want only the news id to be used in decoding, and title to be added only for SEO purposes.
How can I acomplish it with either RealURL, CoolURI or anything else?
edit: so far I managed to do what I wanted with the following two userfuncs:
array(
'GETvar' => 'tx_news_pi1[news]',
'userFunc' => 'EXT:speciality/Classes/Hooks/RealUrlUserFunc.php:&Tx_Speciality_Hooks_RealUrlUserFunc->main',
'lookUpTable_fake' => array(
'table' => 'tx_news_domain_model_news',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND NOT deleted AND NOT hidden',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'EXT:speciality/Classes/Hooks/RealUrlUserFunc.php:&Tx_Speciality_Hooks_RealUrlUserFunc->user_newsid',
),
),
),
And the userfuncs:
class Tx_Speciality_Hooks_RealUrlUserFunc {
public function main(array $params, $parent) {
$this->pObj = $parent;
if($params['decodeAlias']) {
return $this->alias2id($params);
} else {
return $this->id2alias($params);
}
}
function alias2id($params){
return array_pop(explode('-', $params['value']));
}
function id2alias($params){
return $this->pObj->lookUpTranslation($params['setup']['lookUpTable_fake'], $params['value'], FALSE);
}
function user_newsid($params) {
if($params['pObj']->orig_paramKeyValues['tx_news_pi1[news]'])
return $params['processedTitle'] ."-". $params['pObj']->orig_paramKeyValues['tx_news_pi1[news]'];
else
return $params['processedTitle'];
}
}
The only problem so far is that lookUpTranslation is a protected function, so I had to temporary hack Realurl to make that fucntion public.
So how do I encode a title from my userfunc the right way?
Perhaps there is a easier way to do this but it's definitly possible with RealUrl by using a hook. Keyword is "encodeTitle_userProc", see here:
http://docs.typo3.org/typo3cms/extensions/realurl/1.12.7/Realurl/ClasstxRealurlAdvancedphp/Configuration/Index.html?highlight=encodetitle_userproc
Here's a simple example to remove the registered sign from a URL:
RealUrlConfig:
'product' => array(
array(
'GETvar' => 'tx_myextension[product]',
'lookUpTable' => array(
....
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
'encodeTitle_userProc' => 'EXT:tx_myextension/Classes/Hooks/RealUrlUserFunc.php:&Tx_Myextension_Hooks_RealUrlUserFunc->user_productsTitle',
),
...
),
),
),
And the hook class:
class Tx_Myextension_Hooks_RealUrlUserFunc {
function user_productsTitle($params) {
return preg_replace('/[R]{1}/', '', $params['processedTitle']);
}
}

TYPO3 RealURL postVarSets hide keyword

I have an URL which looks like this:
http://domain.com/leistungen/industrial-design/?tx_fsproject_fsprojectfp%5Bproject%5D=2&tx_fsproject_fsprojectfp%5Baction%5D=show&tx_fsproject_fsprojectfp%5Bcontroller%5D=Project&cHash=7c405bcde49853af9a7e78bdf465002c
Using RealURL with the following configuration (and some hook functions as explained here):
'postVarSets' => array(
'_DEFAULT' => array(
// projects
'industrial-design' => array(
array(
'GETvar' => 'tx_fsproject_fsprojectfp[controller]',
),
array(
'GETvar' => 'tx_fsproject_fsprojectfp[action]',
),
array(
'GETvar' => 'tx_fsproject_fsprojectfp[project]',
'lookUpTable' => array(
'table' => 'tx_fsproject_domain_model_project',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND deleted !=1 AND hidden !=1',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
)
)
),
),
),
),
I get an URL looking like this:
http://domain.com/leistungen/industrial-design/industrial-design/projekt/project-b/
This is not bad. However, why does the industrial-design/ part show up twice?
The first industrial-design is the page that is being displayed. The second one is the keyword inserted by RealURL to identify the set of variables. To avoid that you can:
Change the structure of pages so that you don't have industrial-design page at all.
Rename the postVarSets that you set up in the RealURL configuration.
Use fixedPostVars instead as that doesn't use a keyword to identify the set of variables but a page UID.