diff --git a/code_samples/back_office/images/config/packages/views.yaml b/code_samples/back_office/images/config/packages/views.yaml new file mode 100644 index 0000000000..6d97f044e2 --- /dev/null +++ b/code_samples/back_office/images/config/packages/views.yaml @@ -0,0 +1,10 @@ +parameters: + ibexa.site_access.config..image_asset_view_defaults: + full: + commons: + template: '@@ibexadesign/commons_asset_view.html.twig' + match: + SourceBasedViewMatcher: commons + default: + template: '@@ibexadesign/ui/field_type/image_asset_view.html.twig' + match: [] diff --git a/code_samples/back_office/images/config/services.yaml b/code_samples/back_office/images/config/services.yaml index a6cebc0938..63357d14b3 100644 --- a/code_samples/back_office/images/config/services.yaml +++ b/code_samples/back_office/images/config/services.yaml @@ -6,3 +6,28 @@ services: - '@ibexa.api.service.content' - '@ibexa.field_type.ezbinaryfile.io_service' - '@Ibexa\Core\Helper\TranslationHelper' + + App\Connector\Dam\Handler\WikimediaCommonsHandler: + tags: + - { name: 'ibexa.platform.connector.dam.handler', source: 'commons' } + + App\Connector\Dam\Transformation\WikimediaCommonsTransformationFactory: + tags: + - { name: 'ibexa.platform.connector.dam.transformation_factory', source: 'commons' } + + commons_asset_variation_generator: + class: Ibexa\Connector\Dam\Variation\URLBasedVariationGenerator + tags: + - { name: 'ibexa.platform.connector.dam.variation_generator', source: 'commons' } + + commons_search_tab: + class: Ibexa\Connector\Dam\View\Search\Tab\GenericSearchTab + public: false + arguments: + $identifier: 'commons' + $source: 'commons' + $name: 'Wikimedia Commons' + $searchFormType: 'Ibexa\Connector\Dam\Form\Search\GenericSearchType' + $formFactory: '@form.factory' + tags: + - { name: 'ibexa.admin_ui.tab', group: 'connector-dam-search' } diff --git a/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php new file mode 100644 index 0000000000..32398396d8 --- /dev/null +++ b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php @@ -0,0 +1,82 @@ +getPhrase()) + . '&sroffset=' . $offset + . '&srlimit=' . $limit + ; + + $jsonResponse = file_get_contents($searchUrl); + if ($jsonResponse === false) { + return new AssetSearchResult(0, new AssetCollection([])); + } + + $response = json_decode($jsonResponse, true); + if (!isset($response['query']['search'])) { + return new AssetSearchResult(0, new AssetCollection([])); + } + + $assets = []; + foreach ($response['query']['search'] as $result) { + $identifier = str_replace('File:', '', $result['title']); + $assets[] = $this->fetchAsset($identifier); + } + + return new AssetSearchResult( + (int) ($response['query']['searchinfo']['totalhits'] ?? 0), + new AssetCollection($assets) + ); + } + + public function fetchAsset(string $id): Asset + { + $metadataUrl = 'https://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=extmetadata&format=json' + . '&titles=File%3a' . urlencode($id) + ; + + $jsonResponse = file_get_contents($metadataUrl); + if ($jsonResponse === false) { + throw new \RuntimeException('Couldn\'t retrieve asset metadata'); + } + + $response = json_decode($jsonResponse, true); + if (!isset($response['query']['pages'])) { + throw new \RuntimeException('Couldn\'t parse asset metadata'); + } + + $pageData = array_values($response['query']['pages'])[0] ?? null; + if (!isset($pageData['imageinfo'][0]['extmetadata'])) { + throw new \RuntimeException('Couldn\'t parse image asset metadata'); + } + + $imageInfo = $pageData['imageinfo'][0]['extmetadata']; + + return new Asset( + new AssetIdentifier($id), + new AssetSource('commons'), + new AssetUri('https://commons.wikimedia.org/w/index.php?title=Special:Redirect/file/' . urlencode($id)), + new AssetMetadata([ + 'page_url' => "https://commons.wikimedia.org/wiki/File:$id", + 'author' => $imageInfo['Artist']['value'] ?? null, + 'license' => $imageInfo['LicenseShortName']['value'] ?? null, + 'license_url' => $imageInfo['LicenseUrl']['value'] ?? null, + ]) + ); + } +} diff --git a/code_samples/back_office/images/src/Connector/Dam/Transformation/WikimediaCommonsTransformationFactory.php b/code_samples/back_office/images/src/Connector/Dam/Transformation/WikimediaCommonsTransformationFactory.php new file mode 100644 index 0000000000..7b46a12079 --- /dev/null +++ b/code_samples/back_office/images/src/Connector/Dam/Transformation/WikimediaCommonsTransformationFactory.php @@ -0,0 +1,36 @@ + $transformationParameters */ + public function build(?string $transformationName = null, array $transformationParameters = []): Transformation + { + if (null === $transformationName) { + return new Transformation(null, array_map('strval', $transformationParameters)); + } + + $transformations = $this->buildAll(); + + if (array_key_exists($transformationName, $transformations)) { + return $transformations[$transformationName]; + } + + throw new \InvalidArgumentException(sprintf('Unknown transformation "%s".', $transformationName)); + } + + public function buildAll(): array + { + return [ + 'reference' => new Transformation('reference', []), + 'tiny' => new Transformation('tiny', ['width' => '30']), + 'small' => new Transformation('small', ['width' => '100']), + 'medium' => new Transformation('medium', ['width' => '200']), + 'large' => new Transformation('large', ['width' => '300']), + ]; + } +} diff --git a/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig b/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig new file mode 100644 index 0000000000..00a5bac1cd --- /dev/null +++ b/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig @@ -0,0 +1,12 @@ +{% extends '@ibexadesign/ui/field_type/image_asset_view.html.twig' %} + +{% block asset_preview %} + {{ parent() }} +
+ Image + {% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author }}{% endif %} + {% if asset.assetMetadata.license and asset.assetMetadata.license_url %} + under {{ asset.assetMetadata.license }} + {% endif %}. +
+{% endblock %} diff --git a/code_samples/back_office/images/translations/ibexa_fieldtypes_preview.en.yaml b/code_samples/back_office/images/translations/ibexa_fieldtypes_preview.en.yaml new file mode 100644 index 0000000000..c1cdfa4d4e --- /dev/null +++ b/code_samples/back_office/images/translations/ibexa_fieldtypes_preview.en.yaml @@ -0,0 +1,4 @@ +ezimageasset.dam_asset.page_url: Image page +ezimageasset.dam_asset.author: Image author +ezimageasset.dam_asset.license: License +ezimageasset.dam_asset.license_url: License page diff --git a/composer.json b/composer.json index 3161aafe6b..edad1fd446 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,8 @@ "ibexa/solr": "5.0.x-dev", "ibexa/version-comparison": "5.0.x-dev", "league/oauth2-google": "^4.0", - "ibexa/core-search": "~5.0.x-dev" + "ibexa/core-search": "~5.0.x-dev", + "ibexa/connector-dam": "~5.0.x-dev" }, "scripts": { "fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots", diff --git a/docs/administration/back_office/add_user_setting.md b/docs/administration/back_office/add_user_setting.md index c994960139..61c1a07f49 100644 --- a/docs/administration/back_office/add_user_setting.md +++ b/docs/administration/back_office/add_user_setting.md @@ -27,7 +27,7 @@ You can order the settings in the **User** menu by setting their `priority`. `group` indicates the group that the setting is placed in. It can be one of the built-in groups, or a custom one. -To create a custom setting group, create an `App\Setting\Group\MyGroup.php` file: +To create a custom setting group, create an `App/Setting/Group/MyGroup.php` file: ``` php [[= include_file('code_samples/back_office/settings/src/Setting/Group/MyGroup.php') =]] diff --git a/docs/administration/back_office/back_office_elements/formatting_date_and_time.md b/docs/administration/back_office/back_office_elements/formatting_date_and_time.md index 2faff86b23..1e02c76ea5 100644 --- a/docs/administration/back_office/back_office_elements/formatting_date_and_time.md +++ b/docs/administration/back_office/back_office_elements/formatting_date_and_time.md @@ -17,7 +17,7 @@ You can format date and time by using the following services: - `@ibexa.user.settings.full_date_format.formatter` - `@ibexa.user.settings.full_time_format.formatter` -To use them, create an `src\Service\MyService.php` file containing: +To use them, create an `src/Service/MyService.php` file containing: ``` php ` with an [appropriate value](siteaccess_aware_configuration.md) that designates the SiteAccess or SiteAccess group, for example, `default` to use the template everywhere, including the back office: + +```yaml +[[= include_file('code_samples/back_office/images/config/packages/views.yaml') =]] +``` + +### 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`: + +```yaml +[[= include_file('code_samples/back_office/images/translations/ibexa_fieldtypes_preview.en.yaml') =]] +``` + +### Add Wikimedia Commons connection to DAM configuration + +You can now configure a connection with Wikimedia Commons under the `ibexa.system..content.dam` key using the source identifier `commons`: + +```yaml +ibexa: + system: + default: + content: + dam: [ commons ] +``` + +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. diff --git a/docs/content_management/images/images.md b/docs/content_management/images/images.md index 988dde21c4..2fbda0b7e5 100644 --- a/docs/content_management/images/images.md +++ b/docs/content_management/images/images.md @@ -215,7 +215,7 @@ It points to a custom controller that handles the downloading of the SVG file. The controller's definition (that you place in the `config/services.yaml` file under `services` key) and implementation are as follows: ```yaml -[[= include_file('code_samples/back_office/images/config/services.yaml') =]] +[[= include_file('code_samples/back_office/images/config/services.yaml', 0, 8) =]] ``` ```php diff --git a/docs/update_and_migration/from_3.3/update_from_3.3.md b/docs/update_and_migration/from_3.3/update_from_3.3.md index 15c75314a1..993f528b29 100644 --- a/docs/update_and_migration/from_3.3/update_from_3.3.md +++ b/docs/update_and_migration/from_3.3/update_from_3.3.md @@ -148,7 +148,7 @@ CREATE INDEX idx_workflow_name ON ezeditorialworkflow_workflows(workflow_name); #### Enable Commerce features Commerce features in Experience and Content editions are disabled by default. -If you use these features, after the update enable Commerce features by going to `config\packages\ecommerce.yaml` +If you use these features, after the update enable Commerce features by going to `config/packages/ecommerce.yaml` and setting the following: ``` yaml