I need to join two tables for configuration of fixedPostVars in realurl. All solutions I found are for older version < 2 of realurl.
Following SQL statement returns wanted result
SELECT
CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city)
FROM
tx_myext_domain_model_eventannouncement
INNER JOIN
tx_myext_domain_model_event
ON
tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid
WHERE
tx_myext_domain_model_eventannouncement.uid = 2
;
Is there a way to integrate this SQL in the realurl configuration? I tried this but URLs result in https://example.com/.../detail/2/
'GETvar' => 'tx_myext_eventannouncement[eventannouncement]',
'lookUpTable' => [
'table' => 'tx_myext_domain_model_eventannouncement',
'id_field' => 'tx_myext_domain_model_eventannouncement.uid',
'alias_field' => 'INNER JOIN tx_myext_domain_model_event ON tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \' % d -%m -%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city)',
'addWhereClause' => ' AND tx_myext_domain_model_eventannouncement.deleted=0 AND tx_myext_domain_model_eventannouncement.hidden=0',
'useUniqueCache' => true,
'useUniqueCache_conf' => [
'strtolower' => true,
'spaceCharacter' => '-',
],
'enable404forInvalidAlias' => true,
],
You have two options to allow RealURL to access your field through this join.
First to use a subquery intead of joins.
(SELECT DISTINCT
CONCAT(
DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),
"-",
tx_myext_domain_model_event.title,
"-",
tx_myext_domain_model_event.city)
FROM tx_myext_domain_model_event
INNER JOIN
tx_myext_domain_model_event
ON
tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid)
as alias_field
(Please note, this code snippet is an idea only, I had not the opportunity to test it for you.)
The second is to create a view:
CREATE VIEW tx_myext_event_view AS
SELECT tx_myext_domain_model_eventannouncement.*,
CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city) as alias_field
FROM
tx_myext_domain_model_eventannouncement
INNER JOIN
tx_myext_domain_model_event
ON
tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid
Now you can set the RealURL config like:
'GETvar' => 'tx_myext_eventannouncement[eventannouncement]',
'lookUpTable' => [
'table' => 'tx_myext_event_view',
'id_field' => 'tx_myext_event_view.uid',
'alias_field' => 'tx_myext_event_view.alias_field',
'useUniqueCache' => true,
'useUniqueCache_conf' => [
'strtolower' => true,
'spaceCharacter' => '-',
],
'enable404forInvalidAlias' => true,
],
I would try with the subquery because to maintain a view in an extension is tricky. However it could be a better solution for an even more complex logic or if you have multiple definitions getting information from the same base with different conditions.
Related
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?
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.
I have two different configurations for two different extensions.
With news I use postvarsets:
'postVarSets' =>
array (
'_DEFAULT' =>
array (
'news' =>
array (
0 =>
array (
'GETvar' => 'tx_news_pi1[news]',
'lookUpTable' =>
array (
'table' => 'tx_news_domain_model_news',
'id_field' => 'uid',
'alias_field' => 'title',
'useUniqueCache' => 1,
'useUniqueCache_conf' =>
array (
'strtolower' => 1,
'spaceCharacter' => '-',
),
),
),
),
),
)
For an own extension to display categories I use fixedpostvars:
'fixedPostVars' =>
array (
'category' =>
array (
0 =>
array (
'GETvar' => 'tx_myextension_plugin[mainCategory]',
'lookUpTable' =>
array (
'table' => 'sys_category',
'id_field' => 'uid',
'alias_field' => 'title',
'languageGetVar' => 'L',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'useUniqueCache' => 1,
'useUniqueCache_conf' =>
array (
'strtolower' => 1,
'spaceCharacter' => '-',
),
),
),
),
),
If I now use some invalid URL in news, I get a 404 (which is completely right).
If I now use some invalid category in my URL, I get a 500 error with the error message:
Exception while property mapping at property path "": The identity property "ergeriguehrgoiekweukw" is no UID.
Why is there a difference between the two configurations and how can I get a 404 as well for the fixedpostvars?
i am not sure but i think this is useful for you. add 'enable404forInvalidAlias' => 1, for getting 404 error. in fixedPostVars realURL configuration.
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.
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.