Download the PHP package heimrichhannot/contao-syndication-type-bundle without Composer
On this page you can find all versions of the php package heimrichhannot/contao-syndication-type-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download heimrichhannot/contao-syndication-type-bundle
More information about heimrichhannot/contao-syndication-type-bundle
Files in heimrichhannot/contao-syndication-type-bundle
Package contao-syndication-type-bundle
Short Description This bundle brings an extendable syndication framework to contao.
License LGPL-3.0-or-later
Informations about the package contao-syndication-type-bundle
Contao Syndication Type Bundle
This bundle brings an extendable syndication framework to contao. Syndication can be easily added to your own bundle/module/element. There are already some bundles/entites supported out-of-the-box (see features section).
Features
- out-of-the-box syndication support for
- article
- content element
- Reader Bundle
- bundled syndication types:
- sharing: facebook, email, email feedback, twitter, whatsapp, xing, linkedin
- export: ical, print
- expandable and customizable syndication framework
- add pdf export through PDF Creator Bundle
- generated links and link lists implementing PSR-13
LinkInterface
andLinkProviderInterface
Usage
Requirements
- php ^7.2
- contao ^4.4
- for iCal (.ics) export:
eluceo/ical (^0.16)
- for PDF export:
heimrichhannot/contao-pdf-creator-bundle
Install
-
Install with composer or contao manager
composer require heimrichhannot/contao-syndication-type-bundle
- Update database
Article syndication
You can replace the contao article syndication with the syndication of this bundle.
- Set
huh_syndication_type.enable_article_syndication
to true (in your project config.yml) - Clear your cache and update the database
- You'll find the new syndication config in your article configuration
Content element syndication
You can add syndication as a content Element to every article.
- Set
huh_syndication_type.enable_content_syndication
to true (in your project config.yml) - Clear your cache and update the database
- You'll find the new syndication type in content element type selection
Reader Bundle
- Create a new reader config element of type syndication
- Select syndications
- output the template variable in your template (with raw filter)
Print content
To print your content, you have two options: print the whole page (a simple window.print() link) or use a custom template to print. Print template are written in twig and the file name must start with syndication_type_print_
, for example syndication_type_print_default.html.twig
. You can extend our default template or create a complete custom template.
While creating you print template, you may want to see a preview without the print popup. To get one, just append synPrintDebug
parameter to the print url.
Developers
Customize link rendering
If you need more control over the output of the link rendering, you have different options:
Override or change default templates
You can override following templates (just use the contao template inheritance with twig templates thanks to Twig Support Bundle):
syndication_provider_default.html.twig
syndication_link_default.html.twig
It is also possible to create custom versions like syndication_provider_acme.html.twig
. To use a custom link template, you can use the BeforeRenderSyndicationLinks
event, pass the option on SyndicationLinkRenderer methods call or decorate the SyndicationLinkRenderer
service. Change the provider template can be archived by pass the option on SyndicationLinkRenderer methods call or decorate the SyndicationLinkRenderer
service.
Use the BeforeRenderSyndicationLinks event
You can customize the options and the links that are rendered through the BeforeRenderSyndicationLinks.
Example (Contao 4.9+):
Decorate the SyndicationLinkRenderer
service
You can customize all options by decorating the SyndicationLinkRenderer
service. If you're not familiar with that, it sounds complicated, but symfony make it easy and here is a working example (just change namespaces and class names):
Add syndications to your bundle
Syndication bundle is build to be reused. You can easily add it to your code.
-
Add all needed fields to your dca
- We recommend creating a listener to the loadDataContainer Hook
- Add fields and configuration with
SyndicationTypeDcaProvider::prepareDca($table)
- Generate the palette with
SyndicationTypeDcaProvider::getPalette()
and place it where it should be. You can pass a boolean parameter to get the palette seperated by legends or not.
-
Generate syndication links in your controller/module/listener/...
- create an instance of
SyndicationContext
- generate syndication links with
SyndicationLinkProviderGenerator::generateFromContext()
(will return aSyndicationLinkProvider
instance, which is a collection ofSyndicationLink
instances) - render the syndication links with
SyndicationLinkRenderer::renderProvider()
(will return the rendered links as string. You could also use/create a custom link renderer)
For easy of implementation you can access all of these services through
SyndicationManager
. - create an instance of
- Add export support.
- this should be done, where your content to export is completely configured and fully rendered (or can be fully rendered). In the most cases, this can be done where you generate the syndication links, but maybe it must be done on a later point.
- create a
SyndicationContext
instance - run
ExportSyndicationHandler::exportByContext()
Add custom syndication type
- Create a SyndicationType class
- the class must implement
SyndicationTypeInterface
(orExportSyndicationTypeInterface
) - you can (and we recommend) extend
AbstractSyndicationType
orAbstractExportSyndicationType
(for syndication types which do some export like pdf, print or ical), which already implement their corresponding interfaces
- the class must implement
- Implement the abstract methods
getType()
- return an alias for the syndication typegenerate()
- generate the syndication link. ASyndicationContext
instance is passed, aSyndicationLink
instance must be returned. We recommend to useSyndicationLinkFactory
to create theSyndicationLink
instance.
- Optional: If your SyndicationType extends one of the abstract classes, your can override following methods:
getCategory()
- customize the syndication category. There are two categories predefined as constants inAbstractSyndicationType
:share
andexport
, but it is possible to use a custom categorygetPalette()
- if your syndication type depends on additions configuration, you can set the syndication type palette here
- Optional: If your SyndicationType extends one of the abstract classes, your can use the following helper methods:
getValueByFieldOption()
- return a configuration value from the context (shorthand so you don't have to do all the array validation)appendGetParameterToUrl()
- utils to append a get parameter to an url. Useful for creating export links
- Register service type class as service with
huh.syndication_type.type
service tag - Create an Event Subscriber for
AddSyndicationTypeFieldsEvent
,AddSyndicationTypePaletteSelectorsEvent
andAddSyndicationTypeSubpalettesEvent
to add custom dca fields and subpalettes
Configuration reference
All versions of contao-syndication-type-bundle with dependencies
contao/core-bundle Version ^4.9
heimrichhannot/contao-twig-support-bundle Version ^0.2.16 || ^1.0
psr/container Version ^1.0 || ^2.0
psr/link Version ^1.0 || ^2.0
symfony/config Version ^4.4 || ^5.0 || ^6.0
symfony/event-dispatcher Version ^4.4 || ^5.0 || ^6.0
symfony/event-dispatcher-contracts Version ^1.0 || ^2.0 || ^3.0
symfony/http-foundation Version ^4.4 || ^5.0 || ^6.0
symfony/service-contracts Version ^1.0 || ^2.0 || ^3.0
symfony/string Version ^5.0 || ^6.0
symfony/translation-contracts Version ^1.0 || ^2.0 || ^3.0