Skip to content

Commit

Permalink
Merge pull request #1757 from open-orchestra/1-2_multi_languages_meta
Browse files Browse the repository at this point in the history
1 2 multi languages meta
  • Loading branch information
ngilain committed Jun 14, 2016
2 parents 5370cff + 986b390 commit d1bdc91
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions ApiBundle/Facade/SiteFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class SiteFacade extends AbstractFacade
public $name;

/**
* @Serializer\Type("string")
* @Serializer\Type("array<string>")
*/
public $metaKeywords;

/**
* @Serializer\Type("string")
* @Serializer\Type("array<string>")
*/
public $metaDescription;
public $metaDescriptions;

/**
* @Serializer\Type("boolean")
Expand Down
2 changes: 1 addition & 1 deletion ApiBundle/Transformer/SiteTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function transform($site)
$facade->siteId = $site->getSiteId();
$facade->name = $site->getName();
$facade->metaKeywords = $site->getMetaKeywords();
$facade->metaDescription = $site->getMetaDescription();
$facade->metaDescriptions = $site->getMetaDescriptions();
$facade->metaIndex = $site->getMetaIndex();
$facade->metaFollow = $site->getMetaFollow();
$facade->theme = $this->getTransformer('theme')->transform($site->getTheme());
Expand Down
17 changes: 13 additions & 4 deletions Backoffice/Form/Type/SiteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@ class SiteType extends AbstractType
protected $siteClass;
protected $translator;
protected $templateRepository;
protected $frontLanguages;

/**
* @param string $siteClass
* @param TranslatorInterface $translator
* @param TemplateRepositoryInterface $templateRepository
* @param array $frontLanguages
*/
public function __construct($siteClass, TranslatorInterface $translator, TemplateRepositoryInterface $templateRepository)
{
public function __construct(
$siteClass,
TranslatorInterface $translator,
TemplateRepositoryInterface $templateRepository,
array $frontLanguages
){
$this->siteClass = $siteClass;
$this->translator = $translator;
$this->templateRepository = $templateRepository;
$this->frontLanguages = \array_keys($frontLanguages);
}

/**
Expand Down Expand Up @@ -77,13 +84,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'precision' => 2,
'attr' => array('help_text' => 'open_orchestra_backoffice.form.node.priority.helper'),
))
->add('metaKeywords', 'text', array(
->add('metaKeywords', 'oo_multi_languages_text', array(
'label' => 'open_orchestra_backoffice.form.website.meta_keywords',
'required' => false,
'languages' => $this->frontLanguages
))
->add('metaDescription', 'text', array(
->add('metaDescriptions', 'oo_multi_languages_text', array(
'label' => 'open_orchestra_backoffice.form.website.meta_description',
'required' => false,
'languages' => $this->frontLanguages
))
->add('metaIndex', 'checkbox', array(
'label' => 'open_orchestra_backoffice.form.website.meta_index',
Expand Down
13 changes: 10 additions & 3 deletions Backoffice/Manager/NodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,16 @@ public function createNewLanguageNode(NodeInterface $node, $language)
$newNode = clone $node;
$newNode->setVersion(1);
$newNode->setStatus($this->getEditableStatus($node));
$newNode->setLanguage($language);
$newNode = $this->duplicateBlockAndArea($node, $newNode);

$siteId = $this->contextManager->getCurrentSiteId();
$site = $this->siteRepository->findOneBySiteId($siteId);
$newNode->setLanguage($language);
if ($site) {
$newNode->setMetaKeywords($site->getMetaKeywordsInLanguage($language));
$newNode->setMetaDescription($site->getMetaDescriptionInLanguage($language));
}

$this->eventDispatcher->dispatch(NodeEvents::NODE_ADD_LANGUAGE, new NodeEvent($node));

return $newNode;
Expand Down Expand Up @@ -341,8 +348,8 @@ public function initializeNode($parentId, $language, $siteId)

$site = $this->siteRepository->findOneBySiteId($siteId);
if ($site) {
$node->setMetaKeywords($site->getMetaKeywords());
$node->setMetaDescription($site->getMetaDescription());
$node->setMetaKeywords($site->getMetaKeywordsInLanguage($language));
$node->setMetaDescription($site->getMetaDescriptionInLanguage($language));
$node->setMetaIndex($site->getMetaIndex());
$node->setMetaFollow($site->getMetaFollow());
}
Expand Down
3 changes: 2 additions & 1 deletion Backoffice/Tests/Form/Type/SiteTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SiteTypeTest extends AbstractBaseTestCase

protected $siteClass = 'oo_site';
protected $translator;
protected $languages = array('en', 'fr');

/**
* Set up the test
Expand All @@ -28,7 +29,7 @@ public function setUp()
$repositoryTemplate = Phake::mock('OpenOrchestra\ModelInterface\Repository\TemplateRepositoryInterface');
Phake::when($this->translator)->trans(Phake::anyParameters())->thenReturn('foo');

$this->form = new SiteType($this->siteClass, $this->translator, $repositoryTemplate);
$this->form = new SiteType($this->siteClass, $this->translator, $repositoryTemplate, $this->languages);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions Backoffice/Tests/Manager/NodeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class NodeManagerTest extends AbstractBaseTestCase
protected $siteRepository;
protected $eventDispatcher;
protected $statusRepository;
protected $metaKeywords = 'fake keyword';
protected $metaDescription = 'fake description';

/**
* Set up the test
Expand All @@ -49,8 +51,8 @@ public function setUp()
Phake::when($theme)->getName()->thenReturn('fakeNameTheme');
$site = Phake::mock('OpenOrchestra\ModelInterface\Model\SiteInterface');
Phake::when($site)->getTheme()->thenReturn($theme);
Phake::when($site)->getMetaKeywords()->thenReturn('fake keyword');
Phake::when($site)->getMetaDescription()->thenReturn('fake description');
Phake::when($site)->getMetaKeywordsInLanguage(Phake::anyParameters())->thenReturn($this->metaKeywords);
Phake::when($site)->getMetaDescriptionInLanguage(Phake::anyParameters())->thenReturn($this->metaDescription);
Phake::when($site)->getMetaIndex()->thenReturn(true);
Phake::when($site)->getMetaFollow()->thenReturn(true);

Expand Down Expand Up @@ -132,6 +134,8 @@ public function testCreateNewLanguageNode(NodeInterface $node, $language)
Phake::verify($alteredNode)->setVersion(1);
Phake::verify($alteredNode)->setStatus(null);
Phake::verify($alteredNode)->setLanguage($language);
Phake::verify($alteredNode)->setMetaKeywords($this->metaKeywords);
Phake::verify($alteredNode)->setMetaDescription($this->metaDescription);
Phake::verify($this->eventDispatcher)->dispatch(Phake::anyParameters());
}

Expand Down Expand Up @@ -299,8 +303,8 @@ public function testInitializeNode($language, $siteId, NodeInterface $parentNode
$this->assertEquals($language, $node->getLanguage());
$this->assertEquals(NodeInterface::THEME_DEFAULT, $node->getTheme());
$this->assertTrue($node->hasDefaultSiteTheme());
$this->assertEquals('fake keyword', $node->getMetaKeywords());
$this->assertEquals('fake description', $node->getMetaDescription());
$this->assertEquals($this->metaKeywords, $node->getMetaKeywords());
$this->assertEquals($this->metaDescription, $node->getMetaDescription());
$this->assertEquals(0, $node->getOrder());
$this->assertEquals($status, $node->getStatus());
$this->assertEquals(true, $node->getMetaIndex());
Expand Down
1 change: 1 addition & 0 deletions BackofficeBundle/Resources/config/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ services:
- %open_orchestra_model.document.site.class%
- @translator
- @open_orchestra_model.repository.template
- %open_orchestra_backoffice.orchestra_choice.front_language%
tags:
- { name: form.type, alias: oo_site }
open_orchestra_backoffice.type.site_alias:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ input.focusable {
border: 0px;
height: 0px;
}

div.tab-pane>div.form-group>input[type="text"], div.tab-pane>div.form-group>textarea {
border-top: 0px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
}
.form-group {
.tab-content > .tab-pane {
display: block;
margin-bottom: -32px;
position: relative;
visibility: visible;
z-index: 1;
}

.tab-content > .active ~ .tab-pane {
top: -32px;
}

.tab-content > .active {
margin-bottom: 0;
top: 0;
z-index: 2;
}

.tab-content .form-group {
margin-bottom: 0;
}
Expand Down

0 comments on commit d1bdc91

Please sign in to comment.