Skip to content

Commit

Permalink
Merge pull request #526 from paulandrieux/bugfix/#428-i18n-seo-parame…
Browse files Browse the repository at this point in the history
…ters

Bugfix/#428 i18n seo parameters
  • Loading branch information
paulandrieux committed Jul 20, 2016
2 parents 6e39d04 + 4a7c0ee commit b8063bf
Show file tree
Hide file tree
Showing 10 changed files with 1,429 additions and 402 deletions.
5 changes: 3 additions & 2 deletions Bundle/CoreBundle/Entity/View.php
Expand Up @@ -19,10 +19,11 @@
* A victoire view is a visual representation with a widget map.
*
* @Gedmo\Tree(type="nested")
* @Gedmo\TranslationEntity(class="Victoire\Bundle\I18nBundle\Entity\ViewTranslation")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\Entity(repositoryClass="Victoire\Bundle\CoreBundle\Repository\ViewRepository")
* @ORM\Entity(
* repositoryClass="Victoire\Bundle\CoreBundle\Repository\ViewRepository"
* )
* @ORM\Table("vic_view")
* @ORM\HasLifecycleCallbacks
*/
Expand Down
2 changes: 2 additions & 0 deletions Bundle/FormBundle/Form/Type/LinkType.php
Expand Up @@ -54,6 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'choices_as_values' => true,
'attr' => [
'data-refreshOnChange' => 'true',
'data-target' => $options['refresh-target'],
],
])
->add('target', ChoiceType::class, [
Expand Down Expand Up @@ -175,6 +176,7 @@ public function configureOptions(OptionsResolver $resolver)
'translation_domain' => 'victoire',
'horizontal' => false,
'linkTypeChoices' => $this->getDefaultLinkTypeChoices(),
'refresh-target' => null,
]);
}

Expand Down
17 changes: 13 additions & 4 deletions Bundle/PageBundle/Helper/PageHelper.php
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ORM\ORMInvalidArgumentException;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand All @@ -19,6 +20,7 @@
use Victoire\Bundle\BusinessPageBundle\Entity\BusinessTemplate;
use Victoire\Bundle\BusinessPageBundle\Helper\BusinessPageHelper;
use Victoire\Bundle\CoreBundle\Entity\EntityProxy;
use Victoire\Bundle\CoreBundle\Entity\Link;
use Victoire\Bundle\CoreBundle\Entity\View;
use Victoire\Bundle\CoreBundle\Event\PageRenderEvent;
use Victoire\Bundle\CoreBundle\Helper\CurrentViewHelper;
Expand Down Expand Up @@ -158,16 +160,19 @@ public function renderPageByUrl($url, $locale, $isAjax = false)
$page = null;
if ($viewReference = $this->viewReferenceRepository->getReferenceByUrl($url, $locale)) {
$page = $this->findPageByReference($viewReference, $entity = $this->findEntityByReference($viewReference));
$this->checkPageValidity($page, $entity, ['url' => $url, 'locale' => $locale]);
$page->setReference($viewReference);

if ($page instanceof BasePage
&& $page->getSeo()
&& $page->getSeo()->getRedirectTo()
&& $page->getSeo()->getRedirectTo()->getLinkType() != Link::TYPE_NONE
&& !$this->session->get('victoire.edit_mode', false)) {
$page = $page->getSeo()->getRedirectTo();
$link = $page->getSeo()->getRedirectTo();

return new RedirectResponse($this->container->get('victoire_widget.twig.link_extension')->victoireLinkUrl($link->getParameters()));
}

$this->checkPageValidity($page, $entity, ['url' => $url, 'locale' => $locale]);
$page->setReference($viewReference);

return $this->renderPage($page, $isAjax);
} else {
Expand Down Expand Up @@ -281,7 +286,11 @@ public function findPageByReference($viewReference, $entity = null)
if ($entity) {
if ($page instanceof BusinessTemplate) {
$page = $this->updatePageWithEntity($page, $entity);
} elseif ($page instanceof BusinessPage) {
}
if ($page instanceof BusinessPage) {
if ($page->getSeo()) {
$page->getSeo()->setCurrentLocale($viewReference->getLocale());
}
$this->pageSeoHelper->updateSeoByEntity($page, $entity);
}
}
Expand Down
9 changes: 7 additions & 2 deletions Bundle/SeoBundle/Controller/PageSeoController.php
Expand Up @@ -65,8 +65,13 @@ public function settingsAction(View $page)
);

$form->handleRequest($this->get('request'));
$novalidate = $this->get('request')->query->get('novalidate', false);

if ($form->isValid()) {
$template = 'VictoireSeoBundle:PageSeo:form.html.twig';
if ($novalidate === false) {
$template = 'VictoireSeoBundle:PageSeo:settings.html.twig';
}
if (false === $novalidate && $form->isValid()) {
$em->persist($pageSeo);
$page->setSeo($pageSeo);
$em->persist($page);
Expand Down Expand Up @@ -95,7 +100,7 @@ public function settingsAction(View $page)
return new JsonResponse([
'success' => !$form->isSubmitted(),
'html' => $this->container->get('templating')->render(
'VictoireSeoBundle:PageSeo:settings.html.twig',
$template,
[
'page' => $page,
'form' => $form->createView(),
Expand Down

0 comments on commit b8063bf

Please sign in to comment.