]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6947 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jun 2024 15:56:47 +0000 (17:56 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jun 2024 15:56:47 +0000 (17:56 +0200)
app/Models/ToolWebflow.php
app/Services/Webflow.php
resources/views/fields/webflow/images.blade.php

index 2ba0af9d2d24fa0fda05042cf50beb373829bff8..e29e42530aacdf3fb89809abd972f7aa0f1c24c7 100644 (file)
@@ -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) {
 
index 905ad28dcb784d20eab19593dcbaea54482410dd..a9775ab6f587b083a07dbc71c8a39284494bc527 100644 (file)
@@ -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']];
                     }
                 }
             }
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..04d65ea8aa2b25fc1d2d8b830c08c30511378957 100644 (file)
@@ -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')
+<label>{!! $field['label'] !!}</label>
+@include('crud::fields.inc.translatable_icon')
+
+<table style="width: 100%">
+    <tr>
+        <th>Aperçu de l'image</th>
+        <th>Texte alternatif</th>
+    </tr>
+    @foreach($images as $id=>$image)
+        @php
+            $e=explode('/',$image['url']);
+            $ee=array_pop($e);
+            $e=explode('_',$ee,2);
+            $short=$e[1];
+        @endphp
+        <tr>
+            <td style="padding: 5px;width: 60%;">
+                <div
+                    style="padding:5px;background-color:#efefef;width: 100%;height: 600px;background-image:url({!! $image['url'] !!});background-size: cover;background-position: 50% 50%"></div>
+            </td>
+            <td style="vertical-align: top;padding: 5px;width: 40%">
+                # {{$id}}<br>
+                <a href="{!! $image['url'] !!}" style="word-break: break-all">{!! $short !!}</a>
+                <textarea style="width: 100%" rows="3"
+                          name="{{ $field['name'] }}[{{$image['id']}}]" @include('crud::fields.inc.attributes')>{{$translations[$image['id']]}}</textarea>
+            </td>
+        </tr>
+    @endforeach
+</table>
+{{-- HINT --}}
+
+@include('crud::fields.inc.wrapper_end')