From 2b9ec17f9d310df79cae4b7b0891a2e35f4a6a25 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 6 Jun 2024 17:56:47 +0200 Subject: [PATCH] wip #6947 @4 --- app/Models/ToolWebflow.php | 27 +++++++++++++ app/Services/Webflow.php | 8 +++- .../views/fields/webflow/images.blade.php | 39 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/app/Models/ToolWebflow.php b/app/Models/ToolWebflow.php index 2ba0af9d2..e29e42530 100644 --- a/app/Models/ToolWebflow.php +++ b/app/Models/ToolWebflow.php @@ -119,6 +119,7 @@ class ToolWebflow extends ToolboxTranslatableModel $api = json_decode($this->api, true); } $seo = $this->getTranslations('seo'); + $images = $this->getTranslations('images'); $hasChanged = false; @@ -138,6 +139,13 @@ class ToolWebflow extends ToolboxTranslatableModel } } + foreach ($images[$mainLocale] as $id => $alt) { + if ($api['images'][$id] !== $alt) { + $api['images'][$id] = $alt; + Webflow::saveImageAlt($id, $alt); + } + } + if ($hasChanged) { $this->api = json_encode($api); $this->saveQuietly(); @@ -231,6 +239,25 @@ class ToolWebflow extends ToolboxTranslatableModel } $this->setTranslations('texts', $translations); + $data = Json::decode($this->images, Json::TYPE_ARRAY); + foreach ($this->api['images'] as $image) { + $data[$mainLocale][$image['id']] = str_starts_with($image['alt'], '__wf_') ? '' : $image['alt']; + } + foreach ($locales as $locale) { + if ($locale === $mainLocale) { + continue; + } + if (!isset($data[$locale])) { + $data[$locale] = []; + } + foreach ($data[$mainLocale] as $id => $alt) { + if (!isset($data[$locale][$id]) || !$data[$locale][$id]) { + $data[$locale][$id] = $alt ? $translateAPI->translate($alt, $locale, $mainLocale) : ''; + } + } + } + $this->setTranslations('images', $data); + $this->saveQuietly(); } catch (LockTimeoutException $e) { diff --git a/app/Services/Webflow.php b/app/Services/Webflow.php index 905ad28dc..a9775ab6f 100644 --- a/app/Services/Webflow.php +++ b/app/Services/Webflow.php @@ -238,6 +238,11 @@ class Webflow return self::paginatedRequest('sites/' . self::getSiteId($shortname) . '/assets', 'assets'); } + public static function saveImageAlt($id, $alt) + { + + } + public static function getEditableData($shortname) { $key = self::getToken() . '_' . $shortname; @@ -293,6 +298,7 @@ class Webflow } $res['texts'][$node['text']['text']]['occurences']++; } else if ($node['type'] === 'image') { + if (!isset($node['image']['assetId'])) { continue; } @@ -300,7 +306,7 @@ class Webflow if (isset($res['images'][$assetId])) { continue; } - $res['images'][$assetId] = ['id' => $assetId, 'alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']]; + $res['images'][$pageID . '_' . $assetId] = ['page' => $pageID, 'id' => $assetId, 'alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']]; } } } diff --git a/resources/views/fields/webflow/images.blade.php b/resources/views/fields/webflow/images.blade.php index e69de29bb..04d65ea8a 100644 --- a/resources/views/fields/webflow/images.blade.php +++ b/resources/views/fields/webflow/images.blade.php @@ -0,0 +1,39 @@ +@php + $value=old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '[]'; + $translations=\Cubist\Util\Json::decode($value,\Cubist\Util\Json::TYPE_ARRAY)??[]; + $images=\Cubist\Util\Json::decode($crud->entry->api,\Cubist\Util\Json::TYPE_ARRAY)['images']; +@endphp + +@include('crud::fields.inc.wrapper_start') + +@include('crud::fields.inc.translatable_icon') + + + + + + + @foreach($images as $id=>$image) + @php + $e=explode('/',$image['url']); + $ee=array_pop($e); + $e=explode('_',$ee,2); + $short=$e[1]; + @endphp + + + + + @endforeach +
Aperçu de l'imageTexte alternatif
+
+
+ # {{$id}}
+ {!! $short !!} + +
+{{-- HINT --}} + +@include('crud::fields.inc.wrapper_end') -- 2.39.5