chameleon-system/meta-data-bundle
Handle page meta data
Requires
- php: ^7.4|^8.0
- chameleon-system/chameleon-shop: ~7.1.0
README
The bundle handles metadata for a page. There are two ways to change the meta data.
Change Meta Data via Provider
You can change the metadata by implementing \ChameleonSystem\MetaData\Interfaces\MetaDataModifierInterface and tagging the
service with chameleon_system_meta_data.modifier. Since there may be many metadata services, you can control which service will
be used by setting the following attribute:
- priority: services with a higher priority will be called AFTER services with lower priority, thereby allowing the higher priority services to overwrite tags set by the lower priority services.
Change Meta Data via Service
Sometimes you may want to change metadata directly from a module. You can do so by using the metadata service
chameleon_system_meta_data.meta_data_bucket (\ChameleonSystem\MetaData\Interfaces\MetaDataBucketInterface). The service can be used to change
the metadata object collected via the metadata providers.
Add Further Tags Via Property Table
If you want to add the support for a number of meta tags in different places - for example the same tags for pages,
products and articles you can make use of the new table cms_meta_data:
- Add some (tag) fields to
cms_meta_data, e. g. a "robots" field - Add a "belongs to" field of type "Parent key" for any place where it should be used; the existing tab "Belongs to" should be used for grouping -- It needs to have the following field properties: bOnlyOneRecord=true, bOpenOnLoad=true, fieldNameInConnectedTable=<content table name_id (e.g. shop_article_id)
- Add a "Tags" field of type "Property" to any content table with the value "cms_meta_data"
With this you will automatically get a new settings block for any data set in the content tables. There is already support for a "title" and "description" field in these settings blocks.
When accessing this data you can use the class\ChameleonSystem\MetaDataBundle\Bridge\Chameleon\DataAccess\MetaDataDataAccess.
You have to define it yourself as a service because for every content table it needs an "owning field name" (e. g. shop_article_id)
as service parameter.
The service returns an instance of \ChameleonSystem\MetaData\DataModel\CmsMetaDataDataModel which especially has a
generic access method getField() which can be used to query every field that is available in cms_meta_data.
The data returned is already translated to the current langauge if applicable for that field.
Caching
To avoid regenerating metadata on every page call, the metadata will be cached. If you modify the meta data bucket directly
via the service chameleon_system_meta_data.meta_data_bucket you must make sure to also modify the cache bucket via
chameleon_system_meta_data.meta_data_cache_bucket.
Provided Default Modifier
The following basic modifiers already exist in Bridge\Chameleon\Modifier. They are activated by default.
CmsTplPageMetaDataModifier: maps the meta data fields of a pagePortalMetaDataModifier: maps the meta data fields of the portal, with a lower priority than the page modifierPortalNameTitleModifier: adds the portal name as suffix to any page title
Configuration
chameleon_system_meta_data:
pageMetaDataModifier:
enable: true
addGeneratorTag: true
portalNameTitleModifier:
enable: true
Integration Into An Existing Project
// TODO more; this is only a detail
The meta-data-bundle changes the handling of some of the normal meta data (title, description, ...). The rendering of those must be removed from their current place in the project. And the character encoding of a page should be added separately again.