Skip to content

Commit

Permalink
Fix issue with resolving context
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyCupic committed Oct 10, 2023
1 parent dea9113 commit 6c8b5d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Netgen\RemoteMedia\Core\Provider\Cloudinary\Converter\VisibilityType as VisibilityTypeConverter;
use Netgen\RemoteMedia\Exception\Factory\InvalidDataException;

use function array_key_exists;
use function array_merge;
use function cloudinary_url_internal;
use function in_array;
use function pathinfo;
Expand All @@ -24,8 +26,7 @@ public function __construct(
private ResourceTypeConverter $resourceTypeConverter,
private VisibilityTypeConverter $visibilityTypeConverter,
private FileHashFactoryInterface $fileHashFactory
) {
}
) {}

public function create($data): RemoteResourceValue
{
Expand Down Expand Up @@ -154,7 +155,12 @@ private function resolveMetaData(array $data): array
private function resolveContext(array $data): array
{
$context = $data['context'] ?? [];
$context = $context['custom'] ?? [];

if (array_key_exists('custom', $context)) {
$context = array_merge($context, $context['custom']);

unset($context['custom']);
}

unset($context['alt'], $context['caption']);

Expand Down
10 changes: 10 additions & 0 deletions tests/lib/Core/Provider/Cloudinary/Factory/RemoteResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ public static function createDataProvider(): array
'type' => 'test',
'secure_url' => 'https://res.cloudinary.com/myCloud/v1371995958/raw/media/raw/new/c87hg9xfxrd4itiim3t0',
'etag' => 'e522f43cf89aa0afd03387c38e2b6e29',
'context' => [
'test' => 'test',
'custom' => [
'test2' => 'test2',
],
],
],
new RemoteResource(
remoteId: 'test|raw|media/raw/new/c87hg9xfxrd4itiim3t0',
Expand All @@ -322,6 +328,10 @@ public static function createDataProvider(): array
'format' => 'zip',
'created_at' => '2011-06-23T13:59:18Z',
],
context: [
'test' => 'test',
'test2' => 'test2',
],
),
],
];
Expand Down

0 comments on commit 6c8b5d5

Please sign in to comment.