Skip to content

Commit

Permalink
Add override for url_generator and fix the save json response
Browse files Browse the repository at this point in the history
  • Loading branch information
SvanteRichter committed Jul 27, 2016
1 parent 0ba3411 commit 0eebecc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
12 changes: 9 additions & 3 deletions config/config.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ locales:
label: Deutsch
slug: de

# Enable/disable automatic routing.
# Enable/disable automatic routing override.
# Enabling this will prefix all routes with {_locale} which leads to links like
# /en/pages/yourpageslug It is reccomended that you leave this on unless you
# want to build your own routing.
routing_override: true

# Enable/disable the menubuilder.
# Enable/disable the menubuilder override.
# Enabling this will make the menu output links in the format of the automatic
# routing. It is reccomended that you leave this on unless you want to build
# your own localized menus.
menu_override: true

# Enable/disable the url_generator override.
# Enabling this will override the url generator to make sure that we don't
# generate links without a locale. This is highlig reccomended to keep unless
# you also build your own override since it can cause WSOD on 404's otherwise.
url_generator_override: true

# Enable/disable translated slugs.
# Enabling this will use translated slugs instead of using the same slug for
# all languages. Only set to false if you also don't set your slugs to `is_translateable`.
translate_slugs: true
translate_slugs: true
16 changes: 16 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,20 @@ public function setTranslateSlugs($translateSlugs)
{
$this->set('translate_slugs', $translateSlugs);
}

/**
* @return boolean
*/
public function isUrlGeneratorOverride()
{
return $this->get('url_generator_override', true);
}

/**
* @param boolean $urlGeneratorOverride
*/
public function setUrlGeneratorOverride($urlGeneratorOverride)
{
$this->set('url_generator_override', $urlGeneratorOverride);
}
}
2 changes: 1 addition & 1 deletion src/EventListener/StorageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function postSave(StorageEvent $event)
if (!$subject instanceof Content) {
return;
}
if (isset($subject[$localeSlug . '_data'])) {
if (!isset($subject[$localeSlug . '_data'])) {
return;
}

Expand Down
37 changes: 18 additions & 19 deletions src/TranslateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,26 @@ function ($app) {
}
);

<<<<<<< ad5143b99bd4b77fa332bd6150e0392ca6c466c1
$app['url_generator'] = $app->extend(
'url_generator',
function ($urlGenerator) use ($app) {
$requestContext = $urlGenerator->getContext();

if (is_null($requestContext->getParameter('_locale'))) {
$config = $app['translate.config'];
/** @var Config\Locale $locale */
$locale = reset($config->getLocales());
$defaultSlug = $locale->getSlug();

$requestContext->setParameter('_locale', $defaultSlug);
}
if ($app['translate.config']->isUrlGeneratorOverride()) {
$app['url_generator'] = $app->extend(
'url_generator',
function ($urlGenerator) use ($app) {
$requestContext = $urlGenerator->getContext();

if (is_null($requestContext->getParameter('_locale'))) {
$config = $app['translate.config'];
/** @var Config\Locale $locale */
$locale = reset($config->getLocales());
$defaultSlug = $locale->getSlug();

$requestContext->setParameter('_locale', $defaultSlug);
}

return $urlGenerator;
}
);
return $urlGenerator;
}
);
}

=======
>>>>>>> fix typos, PSR2 warning, locale param in querystring
if ($app['translate.config']->isMenuOverride()) {
$app['menu'] = $app->share(
function ($app) {
Expand Down

0 comments on commit 0eebecc

Please sign in to comment.