-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RTM] Use ausi/slug-generator for the creation of aliases #1016
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, an event is perfectly correct. Excellent stuff 👍
Have only looked quickly over it. Great. Just as a note: Your package require |
It already is ;) See the develop branch :)
|
Yes, the PHP requirement is the same as in Contao 4.5. But it also requires |
I guess so. Is there an alternative? |
Of course! All of them are required for a decent multilingual (and thus multibyte/utf-8) setup.
|
Therefore I think I can keep the requirements of the slug library as they are now. |
ed0a7e5
to
3dadd44
Compare
b22e057
to
868e9e6
Compare
The It should be RTM now 🎉 |
868e9e6
to
a04c20f
Compare
src/Slug/ValidCharacters.php
Outdated
/** | ||
* @var string[] | ||
*/ | ||
private $defaultOptions = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be a constant or static property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a private constant should be fine.
tests/Slug/ValidCharactersTest.php
Outdated
|
||
$translator | ||
->expects($this->at(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to test how the translator is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the test assures that the class iterates over all four default options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the order should not be relevant. I think we should remove the translator tests here.
src/Event/ContaoCoreEvents.php
Outdated
@@ -60,7 +60,7 @@ | |||
public const BACKEND_MENU_BUILD = 'contao.backend_menu_build'; | |||
|
|||
/** | |||
* The contao.slug_valid_characters event is triggered when the options for the valid characters setting for aliases are generated. | |||
* The contao.slug_valid_characters event is triggered when the valid slug characters option is generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be plural “options are generated”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there several valid slug characters options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, by default there are four options: unicode lowercase, unicode, ASCII lowercase and ASCII.
</trans-unit> | ||
<trans-unit id="tl_page.validAliasCharacters.1"> | ||
<source>When aliases get created automatically, this character set gets used for the conversion.</source> | ||
<source>Please choose the character for auto-generating page aliases.</source> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also plural “characters”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
401d88e
to
fe8286a
Compare
Description ----------- See contao/core-bundle#1016 Commits ------- ac1a2f9 Use the slug generator service for the event alias d9b5537 Handle the $objCalendar === null case 30bf980 Fix a wrong nesting
Description ----------- See contao/core-bundle#1016 Commits ------- 2e286b0 Use the slug generator service for the news alias fb5b802 Also handle the $objNewsArchive === null case
Very good job @ausi. Thanks a bunch. |
So 4.4 LTS does not and will not support this? |
@backbone87 No, but there is an extension which backports the new behaviour to 4.4: ausi/contao-slug-backport |
@ausi is it worth to add a contao specific impl of Ausi\SlugGenerator\SlugGenerator that provides a method with a PageModel argument, that automatically extracts the slug configuration and builds it? that would remove the duplicated code that gathers this configuration in various listeners and eases the integration for 3rd party bundles |
I’m not sure if this is necessary. It’s not that much code that transforms the page model to the options array: $slugOptions['locale'] = $objPage->language;
if ($objPage->validAliasCharacters) {
$slugOptions['validChars'] = $objPage->validAliasCharacters;
} |
well, you also must make sure, that $page->loadDetails() is executed and possibly strip insert tags. further StringUtil::generateAlias should be deprecated and changed to use the slug generator |
sounds reasonable, I think you should open a new ticket for that. |
Related: #1334 |
Description ----------- Fixes #798 I am not sure about the performance implications here as the `file_exists()` check is done inside the `while` loop. We could also do ```php if (!include $strParent) { throw new \Exception('…'); } ``` @contao/developers WDYT? Commits ------- 91e1c928 Check if a template exists when inheriting templates (see #798) 10c057e8 Only log the missing file instead of throwing an exception
As discussed in #954
@contao/developers Is an event class the right thing for this use case?
ToDo: