Add Image Asset from Digital Asset Management¶
With the Digital Asset Management (DAM) system connector you can use assets such as images directly from the DAM in your content.
DAM configuration¶
You can configure a connection with a Digital Asset Management (DAM) system under the ibexa.system.<scope>.content.dam
configuration key.
1 2 3 4 5 |
|
The configuration for each connector depends on the requirements of the specific DAM system.
You can use the provided example DAM connector for Unsplash, or extend DAM support by creating a connector of your choice.
To add the Unsplash connector to your system, add the ibexa/connector-unsplash
bundle to your installation.
Add Image Asset in Page Builder ¶
To add Image Assets directly in the Page Builder, you can do it by using the Embed block. The example below shows how to add images from Unsplash.
First, in templates/themes/standard/embed/
, create a custom template dam.html.twig
:
1 2 3 4 5 6 7 |
|
The 770px
parameter in the template above is used to render the DAM image. It's the unsplash
specific image variation and must be defined separately.
Next, in config/packages/ibexa.yaml
, set the dam.html.twig
template for the embed
view type that is matched for the content type, which you created for DAM images.
For more information about displaying content, see Content rendering.
1 2 3 4 5 6 7 8 9 |
|
In your configuration file add the following configuration:
1 2 3 4 5 6 7 8 9 |
|
You can customize the parameters according to your needs.
For more information about supported parameters, see the Unsplash documentation.
In the back office, go to Admin > Content types. In the Content group, create a content type for DAM images, which includes the ImageAsset field.
Now, when you use the Embed block in the Page Builder, you should see a DAM Image.
For more information about block customization (defined templates, variations), see Create custom block.
Extend DAM support by adding custom connector¶
To extend the DAM support built into Ibexa DXP, you must create a custom handler and transformation factory.
Wikimedia Commons licensing
Before you use Wikimedia Commons assets in a production environment, ensure that you comply with their license requirements.
Create DAM handler¶
This class handles searching through Wikimedia Commons for images and fetching image assets.
In src/Connector/Dam/Handler
folder, create the WikimediaCommonsHandler.php
file that resembles the following example,
which implements search()
to query the server
and fetchAsset()
to return asset objects:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
Then, in config/services.yaml
, register the handler as a service:
1 2 3 |
|
The source
parameter passed in the tag is an identifier of this new DAM connector and is used in other places to glue elements together.
Create transformation factory¶
The transformation factory maps Ibexa DXP's image variations to corresponding variations from Wikimedia Commons.
In src/Connector/Dam/Transformation
folder, create the WikimediaCommonsTransformationFactory.php
file that resembles the following example,
which implements the TransformationFactory
interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Then register the transformation factory as a service:
1 2 3 |
|
Register variations generator¶
The variation generator applies map parameters coming from the transformation factory to build a fetch request to the DAM.
The solution uses the built-in URLBasedVariationGenerator
class, which adds all the map elements as query parameters to the request.
For example, for an asset with the ID Ibexa_Logo.svg
, the handler generates the Asset with AssetUri's URL
equal to:
https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Ibexa_Logo.svg
When the user requests a specific variation of the image, for example, "large", the variation generator modifies the URL and returns it in the following form:
https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/Ibexa_Logo.svg&width=300
For this to happen, register the variations generator as a service available for the custom commons
connector:
1 2 3 4 |
|
Configure tab for "Select from DAM" modal¶
To enable selecting an image from the DAM system, a modal window pops up with tabs and panels that contain different search interfaces.
In this example, the search only uses the main text input. The tab and its corresponding panel are a service created by combining existing components, like in the case of other back office tabs.
The commons_search_tab
service uses the GenericSearchTab
class as a base, and the GenericSearchType
form for search input.
It is linked to the commons
DAM source and uses the identifier commons
.
The DAM search tab is registered in the connector-dam-search
tab group using the ibexa.admin_ui.tab
tag.
1 2 3 4 5 6 7 8 9 10 11 |
|
Create Twig template¶
The template defines how images that come from Wikimedia Commons are displayed.
In templates/themes/standard/
, add the commons_asset_view.html.twig
file that resembles the following example:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Then, register the template and a fallback template in configuration files.
Replace <scope>
with an appropriate value that designates the SiteAccess or SiteAccess group, for example, default
to use the template everywhere, including the back office:
1 2 3 4 5 6 7 8 9 10 |
|
Provide back office translation¶
When the image asset field is displayed in the back office, a table of metadata follows.
This example uses new fields, so you need to provide translations for their labels, for example, in translations/ibexa_fieldtypes_preview.en.yaml
:
1 2 3 4 |
|
Add Wikimedia Commons connection to DAM configuration¶
You can now configure a connection with Wikimedia Commons under the ibexa.system.<scope>.content.dam
key using the source identifier commons
:
1 2 3 4 5 |
|
Once you clear the cache, you can search for images to see whether images from the newly configured DAM are displayed correctly, including their variations.