Skip to content

Commit d0a7309

Browse files
committed
Tabs, translations, todos, …
1 parent 163cbc5 commit d0a7309

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

code_samples/back_office/images/config/packages/views.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
ibexa.<site_access>.image_asset_view_defaults:
2+
ibexa.site_access.config.<scope>.image_asset_view_defaults:
33
full:
44
commons:
55
template: '@@ibexadesign/commons_asset_view.html.twig'

code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ public function fetchAsset(string $id): Asset
5252

5353
$jsonResponse = file_get_contents($metadataUrl);
5454
if ($jsonResponse === false) {
55-
throw new \RuntimeException('TODO: Couldn\'t retrieve asset metadata');
55+
throw new \RuntimeException('Couldn\'t retrieve asset metadata');
5656
}
5757

5858
$response = json_decode($jsonResponse, true);
5959
if (!isset($response['query']['pages'])) {
60-
throw new \RuntimeException('TODO');
60+
throw new \RuntimeException('Couldn\'t parse asset metadata');
6161
}
6262

6363
$pageData = array_values($response['query']['pages'])[0] ?? null;
6464
if (!isset($pageData['imageinfo'][0]['extmetadata'])) {
65-
throw new \RuntimeException('TODO');
65+
throw new \RuntimeException('Couldn\'t parse image asset metadata');
6666
}
6767

6868
$imageInfo = $pageData['imageinfo'][0]['extmetadata'];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ezimageasset.dam_asset.page_url: Image page
2+
ezimageasset.dam_asset.author: Image author
3+
ezimageasset.dam_asset.license: License
4+
ezimageasset.dam_asset.license_url: License page

docs/content_management/images/add_image_asset_from_dam.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ To extend the DAM support built into [[= product_name =]], you must create a cus
9494

9595
### Create DAM handler
9696

97-
This class handles searching through Wikimedia Commons for images and fetching assets.
97+
This class handles searching through Wikimedia Commons for images and fetching image assets.
9898

99-
In `src\Connector\Dam\Handler` folder, create the `WikimediaCommonsHandler.php` file that resembles the following example, which uses `search()` and `fetchAsset()` functions to query the server for images and return asset objects, respectively:
99+
In `src\Connector\Dam\Handler` folder, create the `WikimediaCommonsHandler.php` file that resembles the following example,
100+
which implements [`search()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Connector-Dam-Handler-Handler.html#method_search) and [`fetchAsset()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Connector-Dam-Handler-Handler.html#method_fetchAsset)
101+
functions to query the server for images and return asset objects, respectively:
100102

101103
```php
102104
[[= include_file('code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php') =]]
@@ -105,7 +107,7 @@ In `src\Connector\Dam\Handler` folder, create the `WikimediaCommonsHandler.php`
105107
Then, in `config\services.yaml`, register the handler as a service:
106108

107109
```yaml
108-
[[= include_file('code_samples/back_office/images/config/services.yaml', 9, 14) =]]
110+
[[= include_file('code_samples/back_office/images/config/services.yaml', 9, 12) =]]
109111
```
110112

111113
### Create transformation factory
@@ -114,15 +116,14 @@ The transformation factory maps [[= product_name =]]'s image variations to corre
114116

115117
In `src\Connector\Dam\Transformation` folder, create the `WikimediaCommonsTransformationFactory.php` file that resembles the following example:
116118

117-
118119
```php
119120
[[= include_file('code_samples/back_office/images/src/Connector/Dam/Transformation/WikimediaCommonsTransformationFactory.php') =]]
120121
```
121122

122123
Then register the transformation factory as a service:
123124

124125
```yaml
125-
[[= include_file('code_samples/back_office/images/config/services.yaml', 15, 20) =]]
126+
[[= include_file('code_samples/back_office/images/config/services.yaml', 13, 16) =]]
126127
```
127128

128129
### Register variations generator
@@ -141,25 +142,54 @@ When the user requests a specific variation of the image, for example, "large",
141142
For this to happen, register the variations generator as a service:
142143

143144
```yaml
144-
[[= include_file('code_samples/back_office/images/config/services.yaml', 21, 25) =]]
145+
[[= include_file('code_samples/back_office/images/config/services.yaml', 17, 21) =]]
146+
```
147+
148+
### Set tab for "Select from DAM" modal
149+
150+
To select an image from the DAM, a modal window pop in with tabs & panels for different search sub-interfaces.
151+
152+
In this example, the search only use the main text input.
153+
Its tab and its corresponding panel are a service created by combining existing components (as many [back office tabs](back_office_tabs.md)).
154+
155+
The tab service uses directly the dedicated base tab `GenericSearchTab`,
156+
passes it the dedicated base form `GenericSearchType`,
157+
links it to `commons` DAM source,
158+
is identified as `commons`,
159+
is tagged with `ibexa.admin_ui.tab` tag,
160+
and set in the `connector-dam-search` [tab group](back_office_tabs.md#tab-groups).
161+
162+
```yaml
163+
[[= include_file('code_samples/back_office/images/config/services.yaml', 22, 33) =]]
145164
```
146165

147-
### Create Twig template for Admin UI
166+
### Create Twig template
148167

149-
The template defines how images that come from Wikimedia Commons appear in the back office.
168+
The template defines how images that come from Wikimedia Commons appear.
150169

151-
In `templates/bundles/WikimediaCommonsConnector/`, add the `commons_asset_view.html.twig` file that resembles the following example:
170+
In `templates/themes/standard/`, add the `commons_asset_view.html.twig` file that resembles the following example:
152171

153172
```html+twig
154173
[[= include_file('code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig') =]]
155174
```
156175

157-
Then, register the template and a fallback template in configuration files:
176+
Then, register the template and a fallback template in configuration files
177+
(replace `<scope>` with [appropriate value](siteaccess_aware_configuration.md) like `default` so it's used everywhere including the back office):
158178

159179
```yaml
160180
[[= include_file('code_samples/back_office/images/config/packages/views.yaml') =]]
161181
```
162182

183+
### Provide back office translation
184+
185+
In the back office, an image asset field is displayed followed by a table of metadata.
186+
187+
As some new specific ones are used in this example, some new translation are needed.
188+
189+
```yaml
190+
[[= include_file('code_samples/back_office/images/translations/ibexa_fieldtypes_preview.en.yaml') =]]
191+
```
192+
163193
### Add Wikimedia Commons connection to DAM configuration
164194

165195
You can now configure a connection with Wikimedia Commons under the `ibexa.system.<scope>.content.dam` key:

0 commit comments

Comments
 (0)