-
Notifications
You must be signed in to change notification settings - Fork 27
implementing alternate languages for content documents #175
Conversation
{ | ||
foreach ($alternateLocales as $locale) { | ||
if ($url = $this->urlGenerator->generate($content, array('_locale' => $locale))) { | ||
$this->sonataPage->addLangAlternate($url, $locale); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
I came to the conclusion at night, to create a kind of a 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are right :-)
So ... That solution with asking the DocumentManager to serve the contents locale makes sense when Does anybody has some hints? Tried the follwoing:
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. |
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) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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.
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 |
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? |
You should stop using the shell file and start using the test listener stuff. |
ping .. we need to wrap up features soon as I want to decide what to include for CMF 1.2 |
@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. |
well the point is .. it would make sense if we have new features like this one :) |
@dbu got exact that question. I think the test are cheating me. you got examples? |
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 |
finally i found the issue, yeaaa. Should work now. |
this needs a rebase now |
93fb005
to
d326bc7
Compare
done |
so its no longer a WIP and can be merged? |
right, would like to squash when travis turns green. |
green it is :) |
d326bc7
to
ec65e44
Compare
typing 10xsquash takes some time |
* @param array|object[] $contents | ||
* @return AlternateLocaleCollection | ||
*/ | ||
public function createForManyContent(array $contents); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
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 |
no problem, everything sane you said. |
@lsmith77 i see a lot of green now, bu now you can't merge anymore. |
yeah .. just ping me when its ready |
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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)))
;
}
There was a problem hiding this comment.
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.
* | ||
* @param array|object[] $contents | ||
* | ||
* @return AlternateLocaleCollection |
There was a problem hiding this comment.
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.
yeah, coming good. |
i just squashed all commits and force pushed. i think its good now. waiting for a last travis green light, then lets merge! |
ah that was you, got that window open and thought: Wtw?!? Saw the move and the new commit with my avatar... :-) |
the powers of git :-P |
implementing alternate languages for content documents
I started to implement that feature. Thought we should take care for the existence of the
ManagerRegistry
and when it exists theSeoPresentation::setAlternateLocales()
method will figure out urls (byUrlGenerator
) and pass that information to sonatasPageService
. 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:
ContentListener
SeoPresentation
to compute and set the alternate lang values toPageService