Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

implementing alternate languages for content documents #175

Merged
merged 1 commit into from
Aug 21, 2014

Conversation

ElectricMaxxx
Copy link
Member

Q A
Bug fix? [no]
New feature? [yes]
BC breaks? [no]
Deprecations? [no]
Tests pass? [no]
Fixed tickets [#166]
License MIT
Doc PR not yet

I started to implement that feature. Thought we should take care for the existence of the ManagerRegistry and when it exists the SeoPresentation::setAlternateLocales() method will figure out urls (by UrlGenerator) and pass that information to sonatas PageService. By doing it that way the user just needs to add the right TwigHelper {{ sonata_seo_lang_alternates() }} to see the result. Same procedure as all other metadata comes into the template.

Todo:

  • implement logic in ContentListener
  • add registry by compiler pass
  • add method in SeoPresentation to compute and set the alternate lang values to PageService
  • tests for unit and frontend
  • take care on current route
  • fix strange url problem

{
foreach ($alternateLocales as $locale) {
if ($url = $this->urlGenerator->generate($content, array('_locale' => $locale))) {
$this->sonataPage->addLangAlternate($url, $locale);
Copy link
Member Author

Choose a reason for hiding this comment

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

need to add the current host/domain here

Copy link
Member

Choose a reason for hiding this comment

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

then you simply need to pass true in one of the arguments to generate to make the url absolute.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 thank's a lot never know :-)

@ElectricMaxxx ElectricMaxxx mentioned this pull request Jul 12, 2014
@ElectricMaxxx
Copy link
Member Author

I came to the conclusion at night, to create a kind of a RouteProviderInterface to get RouteCollections Independent from the environment. Otherwise i would end up in endless if-clauses for every env. That Provider should have a ability to configure/set. And i would put the current code into a PhpcrBasedAlternateLocaleRouteProvider.

Edit: started to work on that, hope to push it before soccer match this evening.

$documentManager = $this->getDocumentManagerForClass(get_class($content));
if ($documentManager
&& $content instanceof TranslatableInterface
&& $content instanceof RouteReferrersInterface
Copy link
Member

Choose a reason for hiding this comment

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

you should check for RouteReferrersReadInterface i think.

Copy link
Member Author

Choose a reason for hiding this comment

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

does the RouteReffersReadInterface? inherit from this on? Our UrlGenerator checks for that interface.

Copy link
Member

Choose a reason for hiding this comment

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

the generator checks for RouteReferrersReadInterface: https://github.com/symfony-cmf/Routing/blob/master/ContentAwareGenerator.php#L126

if the SeoBundle checks for the not-readonly-interface in a pure reading context, this is a mistake and should be relaxed to the ReadInterface.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh you are right :-)

@ElectricMaxxx
Copy link
Member Author

So ...
i am almost done with that, but i got one problem:

That solution with asking the DocumentManager to serve the contents locale makes sense when doctrine_phpcr exists or the DoctrinePHPCRBundle is there. So i try to load the service, when the doctrine_phpcr is available, but i got trouble. Maybe the tests are cheating me, cause test application got my service when i want it (when the doctrine_phpcr is available), but i did not find the right way of a service definition that depends on an other service/bundle.

Does anybody has some hints?

Tried the follwoing:

  • compile pass with $container->hasDefenition('doctrine_phpcr)` -> create my service as a separate definition
    • same in bundle extension
    • loading a phpcr.xml config file when cmf_seo.persistence.phpcr = true with service defintion

maybe i need to show my current state this evening, but maybe there are best practices, including tests that works, cause i think i have got a problem in the configuration test with that bundle loading stuff.

@dbu
Copy link
Member

dbu commented Jul 21, 2014

i think in such cases we either say you need to enable the service (alternate languages with phpcr-odm in this case) and if you enable without doctrine_phpcr being availalbe, it will simply fail.

the other way we did a couple of places is configuration with true|false|auto, and with auto you would check class_exists(FQN\DoctrinePHPCRBundle) in the DI class and enable if the class exists, disable otherwise.

$this->seoPresentation->updateAlternateLocales(
$this->alternateLocaleProvider->createForContent($content)
);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Btw: @wouterj before polluting the SeoPresentation with lots of more logic i would suggest that for your #133 work. Just injecting the typed data (SeoMetadata in your case) into it instead of letting it extract or compute it.
Maybe you can extract the SeoPresentation::getSeoMetadata() into an extra service, which extract and/or reads metadata (or one for each). Cause in my head a PresentationModel should not do that hard work - just preparing data for the view.

@ElectricMaxxx
Copy link
Member Author

I think i am running in a circle in here. It is just an issue with implementing that optional service. But i can't really see if the issue is just a test configuration issue. When i call php app/console container:debug i see doctrine_phpcr whilst my tests fails cause it is missing.

@dbu
Copy link
Member

dbu commented Jul 24, 2014

kind of the obvious question: is phpcr-odm enabled in your test setup? and did you look at other tests in other bundles that are using the manager registry?

@wouterj
Copy link
Member

wouterj commented Jul 24, 2014

You should stop using the shell file and start using the test listener stuff.

@lsmith77
Copy link
Member

ping .. we need to wrap up features soon as I want to decide what to include for CMF 1.2

@wouterj
Copy link
Member

wouterj commented Jul 25, 2014

@lsmith77 SeoBundle doesn't have any new features yet (except from psr-4 autoloading). So it makes no sense to release a new minor version for this bundle.

@lsmith77
Copy link
Member

well the point is .. it would make sense if we have new features like this one :)

@ElectricMaxxx
Copy link
Member Author

@dbu got exact that question. I think the test are cheating me. you got examples?

@ElectricMaxxx
Copy link
Member Author

I am almost done with that. The functions i wanted to add with that PR are working fine. Just one test suite is failing: ORM. For some reason the environment = 'orm' setting does not work anymore. The complete orm setting is ignored for that test, so the manager_name/backend_type_orm isn't set right -> Exception in the MappingPass. @wouterj do you have a minute for that? Did i disable one of the configs?

@ElectricMaxxx
Copy link
Member Author

finally i found the issue, yeaaa. Should work now.

@lsmith77
Copy link
Member

this needs a rebase now

@ElectricMaxxx
Copy link
Member Author

done

@lsmith77
Copy link
Member

so its no longer a WIP and can be merged?

@ElectricMaxxx ElectricMaxxx changed the title [WIP] implementing alternate languages for content documents implementing alternate languages for content documents Aug 21, 2014
@ElectricMaxxx
Copy link
Member Author

right, would like to squash when travis turns green.

@lsmith77
Copy link
Member

green it is :)

@ElectricMaxxx
Copy link
Member Author

typing 10xsquash takes some time

* @param array|object[] $contents
* @return AlternateLocaleCollection
*/
public function createForManyContent(array $contents);
Copy link
Member

Choose a reason for hiding this comment

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

kind of last moment, but why not createForContents? its just an s versus no s - but we use this naming scheme in many places and i found it convenient.

Copy link
Member Author

Choose a reason for hiding this comment

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

you are waking up very late to day :-) what time is it in the states now?

Copy link
Member

Choose a reason for hiding this comment

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

i only leave this saturday :-)

@@ -11,7 +11,10 @@

namespace Symfony\Cmf\Bundle\SeoBundle\EventListener;

use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
Copy link
Member

Choose a reason for hiding this comment

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

unused

@dbu
Copy link
Member

dbu commented Aug 21, 2014

okay, i am through with my review. srry for only looking at it now. i think its coming good, just a few details, mostly code cleanup

@ElectricMaxxx
Copy link
Member Author

no problem, everything sane you said.

@ElectricMaxxx
Copy link
Member Author

@lsmith77 i see a lot of green now, bu now you can't merge anymore.

@lsmith77
Copy link
Member

yeah .. just ping me when its ready

@ElectricMaxxx
Copy link
Member Author

Except the issue i don't understand i would call it ready.

if (null !== $alternateLocaleProviderDefinition) {
$definition = $container->getDefinition('cmf_seo.event_listener.seo_content');
$definition
->addMethodCall('setAlternateLocaleProvider', array($alternateLocaleProviderDefinition));
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 i got it as you both (@dbu, @lsmith77 ) wanted it.
Either an user sets its own provider under the served parameter with an service id (won't check that, he needs to feel the pain of an error), or, if defined, we use the custom one with the PHPCR behavior.

Copy link
Member

Choose a reason for hiding this comment

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

almost. if you create this defaultAlternateLocaleProvider you can do

$alternateLocaleProvider = empty($config['alternate_locale']['provider_id']) ? $this->defaultAlternateLocaleProvider : $config['alternate_locale.provider_id'];
if ($alternateLocaleProvider) {
    $definition = $container->getDefinition('cmf_seo.event_listener.seo_content');
    $definition
        ->addMethodCall('setAlternateLocaleProvider', array($this->getDefinition($alternateLocaleProvider)))
    ;
}

Copy link
Member

Choose a reason for hiding this comment

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

no need to again check if the container knows the service. we do want an error if $config['alternate_locale']['provider_id'] does not exist so we know.

@ElectricMaxxx
Copy link
Member Author

@lsmith77 that should be fine now. Right @dbu?

*
* @param array|object[] $contents
*
* @return AlternateLocaleCollection
Copy link
Member

Choose a reason for hiding this comment

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

this returns an AlternateLocaleCollection[], right? a list of alternate locale collections.

@dbu
Copy link
Member

dbu commented Aug 21, 2014

yeah, coming good.

@dbu
Copy link
Member

dbu commented Aug 21, 2014

i just squashed all commits and force pushed. i think its good now. waiting for a last travis green light, then lets merge!

@ElectricMaxxx
Copy link
Member Author

ah that was you, got that window open and thought: Wtw?!? Saw the move and the new commit with my avatar... :-)

@dbu
Copy link
Member

dbu commented Aug 21, 2014

the powers of git :-P

lsmith77 added a commit that referenced this pull request Aug 21, 2014
implementing alternate languages for content documents
@lsmith77 lsmith77 merged commit 77ea44b into master Aug 21, 2014
@lsmith77 lsmith77 deleted the lang-alternate branch August 21, 2014 13:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants