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

Use contao.slug to generate tag alias #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

a-v-l
Copy link

@a-v-l a-v-l commented Sep 16, 2022

In order to use tag aliases as a slug or URL query it makes sense to use contaos slug generator (defaults on ausi/slug-generator) instead of the StringUtil::generateAlias method.

"valid alias characters" and/or "language" of the root page will be used to generate the alias/slug:
'ASCII numbers and lowercase letters' and 'de' would convert "Äpfel" to "aepfel"

instead of StringUtil::generateAlias
@qzminski
Copy link
Member

I don't think that's possible in form like that, because you can have multiple website roots with different configurations and the tags are not tied to website roots. This could be a setting in the tag manager configuration, though, maybe.

@a-v-l
Copy link
Author

a-v-l commented Sep 21, 2022

So, the tag manager would have two optional extra configuration items: locale (defaults to 'en') and validChars (defaults to '0-9a-z' in /src/DependencyInjection/Configuration.php)

The /src/Manager/DefaultManager.php (and /src/Manager/ManagerInterface.php) would get two new methods: getLocale() and getValidChars().

The method onAliasSaveCallback() in /src/EventListener/DataContainer/TagListener.php:303

$aliasOptions = \Contao\PageModel::findBytype('root')->id ?? [];

would change to

$manager = $this->registry->get($dc->activeRecord->source); // Selected source
$aliasOptions = [
    'locale' => $manager->getLocale(),
    'validChars' => $manager->getValidChars()
];

Pleas check out my last commit. I am not entirely sure, if this would be a breaking change – I don't think so…

@qzminski
Copy link
Member

Thank you, looks good. I will have a look at it soon.

'locale' => $manager->getLocale(),
'validChars' => $manager->getValidChars()
];
$value = System::getContainer()->get('contao.slug')->generate($dc->activeRecord->name, $aliasOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

System::getContainer() should not be used. Use Depdendency Injection instead.

'locale' => $this->locale,
'validChars' => $this->validChars
];
$alias = System::getContainer()->get('contao.slug')->generate($model->name, $aliasOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

System::getContainer() should not be used. Use Depdendency Injection instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants