Download the PHP package umanit/seo-bundle without Composer
On this page you can find all versions of the php package umanit/seo-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download umanit/seo-bundle
More information about umanit/seo-bundle
Files in umanit/seo-bundle
Package seo-bundle
Short Description Provides SEO features on Doctrine entities.
License MIT
Homepage https://github.com/umanit/seo-bundle
Informations about the package seo-bundle
Umanit Seo Bundle
This bundle adds SEO capabilities for any model entities.
Features
- [x] 301 Redirects when accessing an old URL
- [x] SEO Metadata (title and description)
- [x] Canonical URL
- [x] Schema.org
- [x] Breadcrumb
- [ ] Sitemap
Installation
$ composer require umanit/seo-bundle
Configuration
The template needs to be declared in your Twig configuration, before other templates. You must choose one between:
You can configure your bundle further by creating a umanit_seo.yaml
configuration file. Here is the default
configuration provided by the bundle:
Usage
- Basic Usage
- Seo Metadata
- Schema.org
- Breadcrumb
- Enabling 301 redirects
- Twig functions reference
- Protips
Basic usage
In order to function properly, SeoBundle must be able to generate a URL for a given entity. To do so, the
umanit_seo.routable
service uses handlers to process the entity.
A handler is a service which implements Umanit\SeoBundle\Handler\Routable\RoutableHandlerInterface
. A supports
method indicated if the service can handle the given entity and a process
method do the job by returning a
Umanit\SeoBundle\Model\Route
object.
The Umanit\SeoBundle\Model\Route
object has a name
attribute, which is the name of the route used to access the
entity and a parameters
attribute used to build the route.
You must implement the interface Umanit\SeoBundle\Model\RoutableModelInterface
on your entity and create a handler
to process it.
SeoBundle will now be able to generate a URL from the entity. If you ever change the slug of a page, the old URL will be redirected to the new one.
If you wanted to generate the URL by yourself you would have done something like the following example:
You can now do like so:
Note: You can use the canonical()
function without passing it an entity, SeoBundle will automatically resolve the
entity associated to the current accessed route and generate the url from it.
Usually, you'll want to use the canonical()
function directly within your main layout.
Seo Metadata
Use the seo_metadata(your_entity)
twig function in your templates.
SeoBundle will automatically find the most pertinent fields in your entity to deduct title and description.
Again, seo_metadata()
can be used without passing it any entity.
Administrating metadata
In order to administrate Seo Metadata, you'll need again to tune-up your entity.
Make your entity implement the HasSeoMetadataInterface
and use the SeoMetadataTrait
If the configuration umanit_seo.metadata.form_type.add_seo_metadata_type
is not disabled, all form which handles your
entity as data
will automatically have a new SeoMetadataType
form type.
This will add a subform with two fields, title
and description
.
_Note: The form type class can be customized with umanit_seo.metadata.form_type.class_fqcn
._
Schema.org implementation
To generate valid schema.org json microdata, SeoBundle must be able to process the given entity.
To do so, the umanit_seo.schemable
service uses handlers to process the entity.
A handler is a service which implements Umanit\SeoBundle\Handler\Schemable\SchemableHandlerInterface
. A supports
method indicated if the service can handle the given entity and a process
method do the job by returning a
Spatie\SchemaOrg\BaseType
object.
The Spatie\SchemaOrg\BaseType
object is provided by the library
spatie/schema-org.
You must implement the interface Umanit\SeoBundle\Model\SchemableModelInterface
on your entity and create a handler
to process it.
Next, add the twig function seo_schema_org()
at the bottom of your layout.
The function will format and display the json schema of the current entity as you defined it.
Breadcrumb
You can easily generate your breadcrumb in 3 different formats; Microdata
, RDFa
or JSON-LD
as described by
the specification. To do so, the umanit_seo.breadcrumbable
service uses handlers
to process the entity.
A handler is a service which implements Umanit\SeoBundle\Handler\Breadcrumbable\BreadcrumbableHandlerInterface
. A
supports
method indicated if the service can handle the given entity and a process
method do the job by returning a
Umanit\SeoBundle\Model\Breadcrumb
object.
The Umanit\SeoBundle\Model\Breadcrumb
obect has a format
attribute, which is one of the previously mentionned and a
items
attributes which is an array of Umanit\SeoBundle\Model\BreadcrumbItem
. Each BreadcrumbItem
has a label
attribute and an optionnal url
attribute.
You must implement the interface Umanit\SeoBundle\Model\BreadcrumbableModelInterface
on your entity and create a
handler to process it.
_Note: If the processed entity implements the RoutableModelInterface
, you can omit the url
attribute to let the
service umanit_seo.routable
generate it for you._
You can now use the twig function seo_breadcrumb()
like the following examples:
Enabling 301 redirects
In order to enable URL history and 301 redirects on an entity, ensure the configuration
umanit_seo.url_historization.enabled
is active (yes by default) then implement the interface
Umanit\SeoBundle\Model\HistorizableUrlModelInterface
and use the trait
Umanit\SeoBundle\Doctrine\Model\HistorizableUrlTrait
.
Twig functions reference
Protips
- The
HistorizableUrlModelInterface
extends theRoutableModelInterface
, so you don't need to implement both, - you can use a custom HTTP code when redirecting by overriding
umanit_seo.url_historization.redirect_code
, - you can use a custom cache service for
Umanit\SeoBundle\Doctrine\EventSubscriber\UrlHistoryWriter
by overridingumanit_seo.url_historization.cache_service
, - if one of your service needs the
@router
, you can implementUmanit\SeoBundle\Service\RouterAwareInterface
and use the traitUmanit\SeoBundle\Service\RouterAwareTrait
(usefull for breadcrumb handlers!).
All versions of seo-bundle with dependencies
ext-json Version *
spatie/schema-org Version ^3.2
ramsey/uuid Version ^4.1
symfony/twig-bundle Version ^6.4|^7.0
twig/extra-bundle Version ^3.0
twig/twig Version ^3.0
doctrine/doctrine-bundle Version ^2.0
doctrine/doctrine-migrations-bundle Version ^3.0
doctrine/orm Version ^2.7
symfony/form Version ^6.4|^7.0