]> _ Git - cubist_cms-back.git/commitdiff
wip #3010 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Sep 2019 13:32:27 +0000 (15:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Sep 2019 13:32:27 +0000 (15:32 +0200)
src/app/Magic/EntityData.php
src/resources/views/fields/select2_from_array.blade.php

index 1e623e05bedbbc020d6b142893756d23245c3b1f..09565111f27721acf7330e6eb05574309602770b 100644 (file)
@@ -126,7 +126,7 @@ class EntityData implements \ArrayAccess
                 $res = $res[App::getLocale()];
             }
 
-            if (!$res) {
+            if (null === $res) {
                 return $default;
             }
             return $res;
index 351faef0d46ea3204f52eba7a9101d52ece0f494..54223bf846c6315e7ec89a3029878b91c09909ec 100644 (file)
@@ -1,5 +1,21 @@
 @php
-    $is_null=null===old(square_brackets_to_dots($field['name'])) && (isset($field['value']) && null===$field['value']);
+    $o=$field['value'] ?? old(square_brackets_to_dots($field['name']));
+
+    $is_null=null===$o;
+    if(!function_exists('select2_from_array_selected')){
+        function select2_from_array_selected($key,$o){
+            if(null===$o){
+                return false;
+            }
+            if(!is_array($o)){
+                return $o==$key;
+            }
+            if(is_array($o)){
+                return in_array($key,$o);
+            }
+            return false;
+        }
+    }
 @endphp
 
 <!-- select2 from array -->
 
         @if (count($field['options']))
             @foreach ($field['options'] as $key => $value)
-                @if(
-                !$is_null && (
-                (old(square_brackets_to_dots($field['name'])) && (
-                        $key == old(square_brackets_to_dots($field['name'])) ||
-                        (is_array(old(square_brackets_to_dots($field['name']))) &&
-                        in_array($key, old(square_brackets_to_dots($field['name'])))))) ||
-                        (null === old(square_brackets_to_dots($field['name'])) &&
-                            ((isset($field['value']) && (
-                                        ($key == $field['value'] && null !== $field['value'] )|| (
-                                                is_array($field['value']) &&
-                                                in_array($key, $field['value'])
-                                                )
-                                        )) ||
-                                (isset($field['default']) &&
-                                ($key == $field['default'] || (
-                                                is_array($field['default']) &&
-                                                in_array($key, $field['default'])
-                                            )
-                                        )
-                                ))
-                        )))
+                @php
+                    $selected=select2_from_array_selected($key,$o);
+                @endphp
+                @if($selected)
                     <option value="{{ $key }}" selected>{{ $value }}</option>
                 @else
                     <option value="{{ $key }}">{{ $value }}</option>