-
Notifications
You must be signed in to change notification settings - Fork 81
IBX-9594: Describe creating a custom DAM connector #2642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4836c64
IBX-9594: Describe creating a custom DAM connector
dabrt 36db157
Move code from md to code sample files
dabrt 6e0c245
PHP & JS CS Fixes
dabrt d43bc7c
Fix formatting, template location and simplify the template
dabrt 320fdc1
Implement reviewer comments
dabrt a503470
Modify template declaration
dabrt 5e16efc
Modify Twig template declaration again
dabrt 9c4d7eb
Fix variable
dabrt 57c2af9
Add missing eof lines, remove obsolete script
dabrt af1c0ae
Merge branch 'master' into IBX-9594
dabrt 363a917
Apply suggestions from code review
dabrt 75a3bba
Add missing dependency to composer.json
dabrt 377e1f0
Merge branch 'IBX-9594' of https://github.com/ibexa/documentation-dev…
dabrt 9382168
Update namespace in php libraries
dabrt 24faff1
Implement reviewer comments
dabrt d4f1423
PHP & JS CS Fixes
dabrt c4b841e
Merge branch 'master' into IBX-9594
adriendupuis ce26c9b
IBX-9594: Review of "Describe creating a custom DAM connector" (#2689)
adriendupuis 0ccda82
Implement review comments
dabrt f869fd8
Apply suggestions from code review
dabrt 2c1ad54
Apply suggestions from code review
dabrt 3c963a0
Implement reviewer comments
dabrt eb2e201
One more slash fix
dabrt 4bc5ab6
Fix a broken link
dabrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
code_samples/back_office/images/config/packages/views.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| parameters: | ||
| ibexa.<site_access>.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: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Connector\Dam\Handler; | ||
|
|
||
| use Ibexa\Platform\Contracts\Connector\Dam\Asset; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\AssetCollection; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\AssetIdentifier; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\AssetMetadata; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\AssetSource; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\AssetUri; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\Handler\Handler as HandlerInterface; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\Search\AssetSearchResult; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\Search\Query; | ||
|
|
||
| class WikimediaCommonsHandler implements HandlerInterface | ||
| { | ||
| public function search(Query $query, int $offset = 0, int $limit = 20): AssetSearchResult | ||
| { | ||
| $searchUrl = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srnamespace=6' | ||
| . '&srsearch=' . urlencode($query->getPhrase()) | ||
| . '&sroffset=' . $offset | ||
| . '&srlimit=' . $limit | ||
| ; | ||
| $response = json_decode(file_get_contents($searchUrl), true); | ||
|
|
||
| $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'], new AssetCollection($assets)); | ||
| } | ||
|
|
||
| public function fetchAsset(string $id): Asset | ||
| { | ||
| $metadataUrl = 'https://commons.wikipedia.org/w/api.php?action=query&prop=imageinfo&iiprop=extmetadata&format=json' | ||
| . '&titles=File%3a' . urlencode($id) | ||
| ; | ||
| $response = json_decode(file_get_contents($metadataUrl), true); | ||
| $imageInfo = array_values($response['query']['pages'])[0]['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' => array_key_exists('Artist', $imageInfo) ? $imageInfo['Artist']['value'] : null, | ||
| 'license' => array_key_exists('LicenseShortName', $imageInfo) ? $imageInfo['LicenseShortName']['value'] : null, | ||
| 'license_url' => array_key_exists('LicenseUrl', $imageInfo) ? $imageInfo['LicenseUrl']['value'] : null, | ||
| ]) | ||
| ); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
..._office/images/src/Connector/Dam/Transformation/WikimediaCommonsTransformationFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Connector\Dam\Transformation; | ||
|
|
||
| use Ibexa\Platform\Contracts\Connector\Dam\Variation\Transformation; | ||
| use Ibexa\Platform\Contracts\Connector\Dam\Variation\TransformationFactory as TransformationFactoryInterface; | ||
|
|
||
| class WikimediaCommonsTransformationFactory implements TransformationFactoryInterface | ||
| { | ||
| public function build(?string $transformationName = null, array $transformationParameters = []): Transformation | ||
| { | ||
| return $this->buildAll()[$transformationName]; | ||
| } | ||
|
|
||
| public function buildAll(): iterable | ||
| { | ||
| 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]), | ||
| ]; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| {% extends '@ibexadesign/ui/field_type/image_asset_view.html.twig' %} | ||
|
|
||
| {% block asset_preview %} | ||
| {{ parent() }} | ||
| <div> | ||
| <a href="{{ asset.assetMetadata.page_url }}">Image</a> by {{ asset.assetMetadata.author }} under | ||
| <a href="{{ asset.assetMetadata.license_url }}">{{ asset.assetMetadata.license }}</a>. </div> | ||
| {% endblock %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.