Skip to content
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

Merged
merged 9 commits into from
Oct 31, 2017

Conversation

ausi
Copy link
Member

@ausi ausi commented Aug 10, 2017

As discussed in #954

@contao/developers Is an event class the right thing for this use case?

ToDo:

Copy link
Member

@Toflar Toflar left a 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 👍

@leofeyer leofeyer added this to the 4.5.0 milestone Aug 11, 2017
@agoat
Copy link
Contributor

agoat commented Aug 11, 2017

Have only looked quickly over it. Great.

Just as a note: Your package require php: ^7.1. If this will be merged, contao should also raise the minimum php version to 7.1.

@Toflar
Copy link
Member

Toflar commented Aug 11, 2017 via email

@ausi
Copy link
Member Author

ausi commented Aug 11, 2017

Yes, the PHP requirement is the same as in Contao 4.5. But it also requires ext-intl, ext-mbstring and ext-pcre, maybe we should discuss if it is OK to require these extensions?

@leofeyer
Copy link
Member

I guess so. Is there an alternative?

@Toflar
Copy link
Member

Toflar commented Aug 11, 2017 via email

@ausi
Copy link
Member Author

ausi commented Aug 14, 2017

ext-pcre is already required by Contao and patchwork/utf8.

ext-intl and ext-mbstring are already required by league/uri which itself is required since Contao 4.1.

Therefore I think I can keep the requirements of the slug library as they are now.

@ausi ausi changed the title [WIP] Use ausi/slug-generator for the creation of aliases [RFC] Use ausi/slug-generator for the creation of aliases Sep 12, 2017
@leofeyer leofeyer force-pushed the develop branch 5 times, most recently from ed0a7e5 to 3dadd44 Compare September 28, 2017 10:39
@ausi ausi changed the title [RFC] Use ausi/slug-generator for the creation of aliases [RTM] Use ausi/slug-generator for the creation of aliases Oct 30, 2017
@ausi
Copy link
Member Author

ausi commented Oct 30, 2017

The de-ASCII rules are included in the latest CLDR version 32-beta3, so I released ausi/slug-generator version 1.0 and updated this PR.

It should be RTM now 🎉

/**
* @var string[]
*/
private $defaultOptions = [
Copy link
Member

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?

Copy link
Member Author

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.


$translator
->expects($this->at(1))
Copy link
Member Author

@ausi ausi Oct 31, 2017

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. 😄

Copy link
Member

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.

Copy link
Member Author

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.

@@ -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.
Copy link
Member Author

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”

Copy link
Member

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?

Copy link
Member Author

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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also plural “characters”

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

@leofeyer leofeyer merged commit a075de1 into contao:develop Oct 31, 2017
leofeyer pushed a commit to contao/calendar-bundle that referenced this pull request Oct 31, 2017
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
leofeyer pushed a commit to contao/news-bundle that referenced this pull request Oct 31, 2017
Description
-----------

See contao/core-bundle#1016

Commits
-------

2e286b0 Use the slug generator service for the news alias
fb5b802 Also handle the $objNewsArchive === null case
leofeyer added a commit to contao/faq-bundle that referenced this pull request Oct 31, 2017
leofeyer added a commit to contao/newsletter-bundle that referenced this pull request Oct 31, 2017
@leofeyer
Copy link
Member

Very good job @ausi. Thanks a bunch.

@backbone87
Copy link
Contributor

So 4.4 LTS does not and will not support this?

@ausi
Copy link
Member Author

ausi commented Jan 21, 2018

@backbone87 No, but there is an extension which backports the new behaviour to 4.4: ausi/contao-slug-backport

@backbone87
Copy link
Contributor

@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

@ausi
Copy link
Member Author

ausi commented Jan 22, 2018

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;
}

@backbone87
Copy link
Contributor

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

@ausi
Copy link
Member Author

ausi commented Jan 22, 2018

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.

@ausi
Copy link
Member Author

ausi commented Jan 22, 2018

Related: #1334

leofeyer added a commit that referenced this pull request Dec 3, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants