Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created SeoAwareTrait #274

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/reference/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ However, it is possible to alter these values at runtime:
->addMeta('property', 'og:description', $post->getAbstract())
;

.. note::

If you need a shortcut to inject the seo page into any class, you could use the
``Sonata\SeoBundle\Seo\SeoAwareTrait``.

These values can be used inside a twig template.

Expand Down
27 changes: 27 additions & 0 deletions src/Seo/SeoAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\SeoBundle\Seo;

trait SeoAwareTrait
{
/**
* @var SeoPageInterface|null
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding @required it will try to autowire it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't find any examples in the other traits.
Should you use autowiring when there is a setter method?

Copy link
Contributor

Choose a reason for hiding this comment

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

why not? You can still set it yourself or let it be autowired. A better question is, should we autowire it at all, I think it is not a best practice for 3rd party bundles.

Copy link
Member Author

@core23 core23 Jun 16, 2018

Choose a reason for hiding this comment

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

Fixed it

*
* @required
*/
protected $seoPage;

public function setSeoPage(SeoPageInterface $seoPage = null)
{
$this->seoPage = $seoPage;
}
}