Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bundle/Controller/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ private function resolveTranslations(): array
'preview_alternate_text_info' => $this->translator->trans('ngrm.edit.vue.preview.alternate_text_info', [], 'ngremotemedia'),
'preview_caption' => $this->translator->trans('ngrm.edit.vue.preview.caption', [], 'ngremotemedia'),
'preview_caption_info' => $this->translator->trans('ngrm.edit.vue.preview.caption_info', [], 'ngremotemedia'),
'preview_alternate_text_override' => $this->translator->trans('ngrm.edit.vue.preview.alternate_text_override', [], 'ngremotemedia'),
'preview_alternate_text_override_info' => $this->translator->trans('ngrm.edit.vue.preview.alternate_text_override_info', [], 'ngremotemedia'),
'preview_caption_override' => $this->translator->trans('ngrm.edit.vue.preview.caption_override', [], 'ngremotemedia'),
'preview_caption_override_info' => $this->translator->trans('ngrm.edit.vue.preview.caption_override_info', [], 'ngremotemedia'),
'preview_tags' => $this->translator->trans('ngrm.edit.vue.preview.tags', [], 'ngremotemedia'),
'preview_tags_info' => $this->translator->trans('ngrm.edit.vue.preview.tags_info', [], 'ngremotemedia'),
'preview_watermark_text' => $this->translator->trans('ngrm.edit.vue.preview.watermark_text', [], 'ngremotemedia'),
Expand Down
2 changes: 2 additions & 0 deletions bundle/Controller/Location/SelectedImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function __invoke(int $locationId): JsonResponse
'alternateText' => $remoteResource->getAltText(),
'caption' => $remoteResource->getCaption(),
'watermarkText' => $remoteResourceLocation->getWatermarkText(),
'altTextOverride' => $remoteResourceLocation->getAltTextOverride(),
'captionOverride' => $remoteResourceLocation->getCaptionOverride(),
'tags' => $remoteResource->getTags(),
'size' => $remoteResource->getSize(),
'variations' => $this->service->resolveCropSettingsJson($remoteResourceLocation),
Expand Down
8 changes: 8 additions & 0 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ private function addNamedObjectsConfiguration(ArrayNodeDefinition $rootNode): vo
->scalarNode('watermark_text')
->defaultValue(null)
->end()
->scalarNode('alt_text')
->info('Alt text override local to the location')
->defaultValue(null)
->end()
->scalarNode('caption')
->info('Caption override local to the location')
->defaultValue(null)
->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<field name="source" column="source" type="string" length="255" nullable="true" />
<field name="cropSettings" column="crop_settings" type="array" />
<field name="watermarkText" column="watermark_text" type="text" length="1000" nullable="true" />
<field name="altTextOverride" column="alt_text_override" type="text" length="1000" nullable="true" />
<field name="captionOverride" column="caption_override" type="text" length="1000" nullable="true" />
<field name="createdAt" column="created_at" type="datetime_immutable" />
<field name="updatedAt" column="updated_at" type="datetime_immutable" />

Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/public/css/remotemedia.css

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions bundle/Resources/public/js/ckeditor-plugin/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export const defaultValue = {
'preview_alternate_text_info': 'preview_alternate_text_info',
'preview_caption': 'preview_caption',
'preview_caption_info': 'preview_caption_info',
'preview_alternate_text_override': 'preview_alternate_text_override',
'preview_alternate_text_override_info': 'preview_alternate_text_override_info',
'preview_caption_override': 'preview_caption_override',
'preview_caption_override_info': 'preview_caption_override_info',
'preview_tags': 'preview_tags',
'preview_tags_info': 'preview_tags_info',
'preview_watermark_text': 'preview_watermark_text',
Expand All @@ -150,6 +154,8 @@ export const defaultValue = {
type: 'type',
altText: 'altText',
caption: 'caption',
altTextOverride: 'altTextOverride',
captionOverride: 'captionOverride',
tags: 'tags[]',
cropSettings: 'cropSettings',
source: 'source',
Expand Down Expand Up @@ -178,6 +184,8 @@ export const defaultValue = {
alternateText: '',
caption: '',
watermarkText: '',
altTextOverride: '',
captionOverride: '',
tags: [],
size: '',
variations: {},
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/public/js/remotemedia.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions bundle/Resources/translations/ngremotemedia.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ ngrm:
alternate_text_info: 'Alt text is stored directly in Cloudinary on a resource so updating it here will also update it on all other locations which are using that same resource.'
caption: 'Caption'
caption_info: 'Caption is stored directly in Cloudinary on a resource so updating it here will also update it on all other locations which are using that same resource.'
alternate_text_override: 'Alternate text override'
alternate_text_override_info: 'Alt text override is stored only on this location and takes precedence over the alt text stored in Cloudinary. Leave it empty to use the alt text from Cloudinary.'
caption_override: 'Caption override'
caption_override_info: 'Caption override is stored only on this location and takes precedence over the caption stored in Cloudinary. Leave it empty to use the caption from Cloudinary.'
tags: 'Tags'
tags_info: 'Tags are stored directly in Cloudinary on a resource so updating them here will also update them on all other locations which are using that same resource.'
watermark_text: 'Watermark text'
Expand Down
4 changes: 4 additions & 0 deletions bundle/Resources/translations/ngremotemedia.hr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ ngrm:
alternate_text_info: 'Alternativni tekst se sprema direktno na resurs u oblaku. Ukoliko se promjeni ovdje, promjenit će se i na svim ostalim lokacijama koje koriste taj resurs.'
caption: 'Naslov'
caption_info: 'Naslov se sprema direktno na resurs u oblaku. Ukoliko se promjeni ovdje, promjenit će se i na svim ostalim lokacijama koje koriste taj resurs.'
alternate_text_override: 'Zamjenski alternativni tekst'
alternate_text_override_info: 'Zamjenski alternativni tekst sprema se samo na ovu lokaciju i ima prednost pred alternativnim tekstom iz oblaka. Ostavite prazno kako bi se koristio alternativni tekst iz oblaka.'
caption_override: 'Zamjenski naslov'
caption_override_info: 'Zamjenski naslov sprema se samo na ovu lokaciju i ima prednost pred naslovom iz oblaka. Ostavite prazno kako bi se koristio naslov iz oblaka.'
tags: 'Tagovi'
tags_info: 'Tagovi se spremaju direktno na resurs u oblaku. Ukoliko se promjene ovdje, promjenit će se i na svim ostalim lokacijama koje koriste taj resurs.'
watermark_text: 'Tekst vodenog žiga'
Expand Down
4 changes: 4 additions & 0 deletions bundle/Resources/translations/ngremotemedia.no.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ ngrm:
alternate_text_info: 'Alt text is stored directly to the resource in the cloud. Changing it here will also change it on all other locations which are using that same resource.'
caption: 'Caption'
caption_info: 'Caption is stored directly to the resource in the cloud. Changing it here will also change it on all other locations which are using that same resource.'
alternate_text_override: 'Alt text override'
alternate_text_override_info: 'Alt text override is stored only on this location and takes precedence over the alt text stored in the cloud. Leave it empty to use the alt text from the cloud.'
caption_override: 'Caption override'
caption_override_info: 'Caption override is stored only on this location and takes precedence over the caption stored in the cloud. Leave it empty to use the caption from the cloud.'
tags: 'Tags'
tags_info: 'Tags are stored directly to the resource in the cloud. Changing them here will also change them on all other locations which are using that same resource.'
watermark_text: 'Watermark text'
Expand Down
6 changes: 6 additions & 0 deletions bundle/Resources/views/app/interactions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
'preview_alternate_text_info': 'ngrm.edit.vue.preview.alternate_text_info'|trans,
'preview_caption': 'ngrm.edit.vue.preview.caption'|trans,
'preview_caption_info': 'ngrm.edit.vue.preview.caption_info'|trans,
'preview_alternate_text_override': 'ngrm.edit.vue.preview.alternate_text_override'|trans,
'preview_alternate_text_override_info': 'ngrm.edit.vue.preview.alternate_text_override_info'|trans,
'preview_caption_override': 'ngrm.edit.vue.preview.caption_override'|trans,
'preview_caption_override_info': 'ngrm.edit.vue.preview.caption_override_info'|trans,
'preview_tags': 'ngrm.edit.vue.preview.tags'|trans,
'preview_tags_info': 'ngrm.edit.vue.preview.tags_info'|trans,
'preview_watermark_text': 'ngrm.edit.vue.preview.watermark_text'|trans,
Expand Down Expand Up @@ -167,6 +171,8 @@
'alternateText': location and location.remoteResource.altText ? location.remoteResource.altText : '',
'caption': location and location.remoteResource.caption ? location.remoteResource.caption : '',
'watermarkText': location and location.watermarkText ? location.watermarkText : '',
'altTextOverride': location and location.altTextOverride ? location.altTextOverride : '',
'captionOverride': location and location.captionOverride ? location.captionOverride : '',
'tags': location ? location.remoteResource.tags : [],
'size': location ? location.remoteResource.size : 0,
'variations': '%VARIATION_SETTINGS%',
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/views/app/view_resource.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% if variation_name %}
{{ ngrm_remote_resource_variation_html_tag(location, variation_group, variation_name)|raw }}
{% else %}
{{ ngrm_remote_resource_html_tag(location.remoteResource)|raw }}
{{ ngrm_remote_resource_location_html_tag(location)|raw }}
{% endif %}
</div>
{% else %}
Expand Down
4 changes: 4 additions & 0 deletions bundle/Templating/Twig/Extension/RemoteMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function getFunctions(): array
'ngrm_remote_resource_html_tag',
[RemoteMediaRuntime::class, 'getRemoteResourceHtmlTag'],
),
new TwigFunction(
'ngrm_remote_resource_location_html_tag',
[RemoteMediaRuntime::class, 'getRemoteResourceLocationHtmlTag'],
),
new TwigFunction(
'ngrm_remote_resource_variation_html_tag',
[RemoteMediaRuntime::class, 'getRemoteResourceVariationHtmlTag'],
Expand Down
34 changes: 34 additions & 0 deletions bundle/Templating/Twig/Runtime/RemoteMediaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
use Twig\Extension\AbstractExtension;

use function count;
use function get_debug_type;
use function in_array;
use function method_exists;
use function trigger_deprecation;

final class RemoteMediaRuntime extends AbstractExtension
{
Expand Down Expand Up @@ -107,6 +111,36 @@ public function getRemoteResourceHtmlTag(RemoteResource $resource, array $htmlAt
return $this->provider->generateHtmlTag($resource, $htmlAttributes, $forceVideo, $useThumbnail);
}

public function getRemoteResourceLocationHtmlTag(RemoteResourceLocation $location, array $htmlAttributes = [], bool $forceVideo = false, bool $useThumbnail = false): string
{
// The check and the fallback below will be removed in 4.0, when generateLocationHtmlTag() is added to ProviderInterface.
if (method_exists($this->provider, 'generateLocationHtmlTag')) {
return $this->provider->generateLocationHtmlTag($location, $htmlAttributes, $forceVideo, $useThumbnail);
}

trigger_deprecation(
'netgen/remote-media-bundle',
'3.1',
'Not implementing the "%s::generateLocationHtmlTag()" method in "%s" is deprecated, the method will be added to the interface in 4.0.',
ProviderInterface::class,
get_debug_type($this->provider),
);

$type = $location->getRemoteResource()->getType();
$isRenderedAsImage = $type === RemoteResource::TYPE_IMAGE
|| ($useThumbnail && in_array($type, [RemoteResource::TYPE_VIDEO, RemoteResource::TYPE_AUDIO], true));

if ($isRenderedAsImage && !($htmlAttributes['alt'] ?? null) && $location->getAltTextOverride() !== null) {
$htmlAttributes['alt'] = $location->getAltTextOverride();
}

if ($isRenderedAsImage && !($htmlAttributes['title'] ?? null) && $location->getCaptionOverride() !== null) {
$htmlAttributes['title'] = $location->getCaptionOverride();
}

return $this->provider->generateHtmlTag($location->getRemoteResource(), $htmlAttributes, $forceVideo, $useThumbnail);
}

public function getRemoteResourceVariationHtmlTag(
RemoteResourceLocation $location,
string $variationGroup,
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"symfony/form": "^5.4 || ^6.2",
"symfony/serializer": "^5.4 || ^6.2",
"symfony/translation": "^5.4 || ^6.2",
"symfony/deprecation-contracts": "^2.5 || ^3.0",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.10"
Expand Down
14 changes: 14 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Netgen Remote Media Bundle changelog

## 3.1.0

### Added

* alt text and caption overrides on `RemoteResourceLocation` (`alt_text_override` and `caption_override` columns), stored only on the location and never sent to the cloud, they take precedence over the values stored on the cloud
* the overrides are editable in the interface (form and CKEditor 5 plugin) next to the cloud values, and configurable for named locations (`alt_text` and `caption`), see [form documentation](FORM.md#alt-text-and-caption-overrides) and [named objects](NAMED_OBJECTS.md)
* `RemoteResourceLocation::getAltText()` and `RemoteResourceLocation::getCaption()` which return the override when it's set and the value from the cloud otherwise
* `ngrm_remote_resource_location_html_tag` TWIG function and `ProviderInterface::generateLocationHtmlTag()` which render the resource of a location with its overrides
* Doctrine migration `Version030100` which adds the two columns

### Deprecated

* not implementing `generateLocationHtmlTag()` in custom providers which don't extend `AbstractProvider` is deprecated, the method is declared with `@method` on `ProviderInterface` and will be added to the interface in 4.0, until then the TWIG runtime applies the overrides itself and calls `generateHtmlTag()` for such providers

## 3.0.3

### Added
Expand Down
17 changes: 17 additions & 0 deletions docs/FORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ The above example will make sure that, when you select a new resource in the for

The reason why we're using `OneToOne` relation here is because the idea is that every usage of a remote resource has it's own location. Things such as cropping settings or watermark text are stored in a location, and you want to have different cropping settings for the same eg. image used on different places.

## Alt text and caption overrides

Alt text and caption entered in the interface are stored on the resource in the cloud, so changing them updates every location which uses that resource. Each location can additionally have its own alt text and caption override (`altTextOverride` and `captionOverride` fields of the form), stored only on that location and never sent to the cloud. An empty override means that the value from the cloud is used.

`RemoteResourceLocation::getAltText()` and `RemoteResourceLocation::getCaption()` return the override when it's set and the value from the cloud otherwise, so use them (eg. `location.caption` in TWIG) instead of the ones on the resource when rendering a location:

```twig
{{ ngrm_remote_resource_variation_html_tag(location, 'default', 'wide') }}
{{ ngrm_remote_resource_location_html_tag(location) }}

{% if location.caption is not empty %}
<figcaption>{{ location.caption }}</figcaption>
{% endif %}
```

Both TWIG functions render the overrides as `alt` and `title` attributes of images and video thumbnails, unless those attributes are explicitly provided. `ngrm_remote_resource_html_tag` receives only the resource, so it always uses the values from the cloud.

## Add field to your form

Now when we have the entity configured properly, it's time to add the form field:
Expand Down
5 changes: 4 additions & 1 deletion docs/NAMED_OBJECTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ netgen_remote_media:

### Remote resource location

If you also need a location for that resource, it's possible by using configuration for locations. Configuration consists of key, value pairs, where key is the desired name (eg. `my_resource_location`) and value is another array which accepts three keys:
If you also need a location for that resource, it's possible by using configuration for locations. Configuration consists of key, value pairs, where key is the desired name (eg. `my_resource_location`) and value is another array which accepts the following keys:

- `resource_remote_id` - remote ID of the resource on the cloud
- `source` (optional) - text that will be used for the location source (eg. `named_my_resource_location`)
- `watermark_text` (optional) - watermark text which can be used if a watermaked variation gets built from that location
- `alt_text` (optional) - alt text override for the location, used instead of the alt text stored on the cloud
- `caption` (optional) - caption override for the location, used instead of the caption stored on the cloud

Example:

Expand All @@ -35,6 +37,7 @@ netgen_remote_media:
resource_remote_id: 'upload|image|folder/my_resource'
source: 'named_my_resource_location'
watermark_text: 'Netgen.io'
alt_text: 'Netgen logo'
```

## Usage
Expand Down
Loading
Loading