]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 21 Jun 2019 15:36:21 +0000 (17:36 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 21 Jun 2019 15:36:21 +0000 (17:36 +0200)
src/app/CubistCrudPanel.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Text.php
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/views/fields/text.blade.php [new file with mode: 0644]

index 05efc8ce02cc4c3f5e51c5a54d114e62a08660d6..0ebcc2e66f01fd2481c5b4d04b1872823aeec9c7 100644 (file)
@@ -3,9 +3,19 @@
 namespace Cubist\Backpack;
 
 use Backpack\CRUD\CrudPanel;
+use Cubist\Backpack\app\Magic\Models\CubistMagicModel;
 
+/**
+ * @property CubistMagicModel $model
+ */
+
+/**
+ * @property CubistMagicModel $entry
+ */
 class CubistCrudPanel extends CrudPanel
 {
+
+
     public function hasField($name)
     {
         $lists = ['getCreateFields', 'getUpdateFields'];
@@ -19,4 +29,15 @@ class CubistCrudPanel extends CrudPanel
         }
         return false;
     }
+
+    public function setModel($model_namespace)
+    {
+        parent::setModel($model_namespace);
+    }
+
+    public function updateEntry()
+    {
+        $this->entry = null;
+        return $this->getEntry($this->getCurrentEntryId());
+    }
 }
index 40196c39e25ccdc9647314b6501696b91d6770b0..847859265fcd5bac142de78cae8ea6b5a654e0f4 100644 (file)
@@ -65,7 +65,7 @@ trait CubistMagicControllerTrait
     public function updateFieldsFromModel($model = null)
     {
         if (null === $model) {
-            $model=$this->getModelInstance();
+            $model = $this->getModelInstance();
         }
         foreach ($model->getFields() as $field) {
             if ($this->crud->hasField($field->getAttribute('name'))) {
@@ -73,6 +73,8 @@ trait CubistMagicControllerTrait
             }
             $this->addField($field);
         }
+
+        $this->crud->updateEntry();
     }
 
 
index abc5917b3f568ba80eab5a41df80118a6a7f9539..dde0ce4fea2e3223202e9fa344aba14dd1134280 100644 (file)
@@ -194,7 +194,11 @@ class Field implements \ArrayAccess
     {
         if ($this->getAttribute('fake')) {
             $this->setAttributeIfNotSet('store_in', 'extras');
+            if ($this->getAttribute('translatable', false) === true) {
+                $this->setAttribute('store_in', $this->getAttribute('store_in') . "_translatable");
+            }
         }
+
         if ($this->hasAttribute('when')) {
             $wrapperAttributes = $this->getAttribute('wrapperAttributes', []);
             $wrapperAttributes['data-when'] = json_encode($this->getAttribute('when'));
index 3cc2e351abe59d0212a0e54e4c9398bc1041f629..22eb7fe46c39379112d1dfd9c90f140dc65f430d 100644 (file)
@@ -2,8 +2,12 @@
 
 namespace Cubist\Backpack\app\Magic\Fields;
 
+use Cubist\Backpack\CubistBackpackServiceProvider;
+
 class Text extends Field
 {
     protected $_databaseType = 'string';
     protected $_translatable = true;
+    protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
+    
 }
index 1276e8e364aebbb4bca49eda2e0a3d5ec710e461..9407547f4d42de93587bfac49cd9a028c7f186b8 100644 (file)
@@ -111,9 +111,11 @@ class CMSPage extends CubistMagicModel
         $template = request('template');
         // if the template in the GET parameter is missing, figure it out from the db
         if ($template == false) {
-            $entry = self::findOrFail($id);
-            $template = $entry->template;
+            /** @var self $entry */
+            $controller->data['entry'] = self::findOrFail($id);
+            $template = $controller->data['entry']->template;
         }
+
         $this->useTemplate($template, $controller);
         parent::onBeforeEdit($controller, $id);
     }
@@ -150,10 +152,8 @@ class CMSPage extends CubistMagicModel
         }
         foreach ($fields as $field) {
             $attr = array_merge($this->defaultFieldAttributes, $field);
-
             $this->addFakeField($attr);
         }
-
         $controller->updateFieldsFromModel();
     }
 
index 31073eaefd758390e13670a4cdd7afdf365d47ee..912cb047509005fd72a385ea308acb7109c32473 100644 (file)
@@ -9,9 +9,9 @@ use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
 use Cubist\Backpack\app\Magic\Fields\Field;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
 use Cubist\Backpack\app\Magic\Util;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
 use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
 use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
 use Doctrine\DBAL\Schema\Schema;
 use Doctrine\DBAL\Schema\Table;
 use Illuminate\Database\Eloquent\Model;
@@ -23,12 +23,11 @@ use Venturecraft\Revisionable\RevisionableTrait;
 
 class CubistMagicAbstractModel extends Model implements HasMedia
 {
-    use SluggableScopeHelpers;
     use CrudTrait;
     use Sluggable {
         replicate as protected replicateSluggable;
     }
-    use Sluggable, SluggableScopeHelpers;
+    use SluggableScopeHelpers;
     use HasTranslations;
     use RevisionableTrait;
     use HasMediaTrait;
@@ -36,7 +35,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         addField as protected bunchAddField;
     }
 
-
     protected static $_doctrineTypesMapping = ['int' => 'integer'];
 
     protected $primaryKey = 'id';
@@ -194,7 +192,9 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     }
 
     /**
-     * @param $attributes
+     * @param $attributes array
+     * @return Field
+     * @throws \Exception
      */
     public function addField($attributes)
     {
@@ -211,15 +211,12 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             if (!in_array($store_in, $this->fillable)) {
                 $this->fillable[] = $store_in;
             }
-
             $this->casts[$store_in] = 'array';
-
             if ($field->getAttribute('translatable')) {
-                $this->fillable[] = $store_in;
                 $this->translatable[] = $store_in;
             }
-
             $this->fakeColumns[] = $store_in;
+            $field->setAttribute('translatable', false);
         } else {
             if ($field->getAttribute('fillable')) {
                 $this->fillable[] = $name;
@@ -243,6 +240,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         }
 
 
+        return $field;
     }
 
     /**
@@ -347,7 +345,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             $field->defineDbColumn($table);
         }
 
-        foreach ($this->fakeColumns as $fakeColumn => $true) {
+        $this->fakeColumns=array_unique($this->fakeColumns);
+        foreach ($this->fakeColumns as $fakeColumn) {
             $table->addColumn($fakeColumn, 'text');
         }
 
diff --git a/src/resources/views/fields/text.blade.php b/src/resources/views/fields/text.blade.php
new file mode 100644 (file)
index 0000000..8ecfab3
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+print_r($field);
+?>
+<!-- text input -->
+<div @include('crud::inc.field_wrapper_attributes') >
+    <label>{!! $field['label'] !!}</label>
+    @include('crud::inc.field_translatable_icon')
+
+    @if(isset($field['prefix']) || isset($field['suffix'])) <div class="input-group"> @endif
+        @if(isset($field['prefix'])) <div class="input-group-addon">{!! $field['prefix'] !!}</div> @endif
+        <input
+            type="text"
+            name="{{ $field['name'] }}"
+            value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
+            @include('crud::inc.field_attributes')
+        >
+        @if(isset($field['suffix'])) <div class="input-group-addon">{!! $field['suffix'] !!}</div> @endif
+        @if(isset($field['prefix']) || isset($field['suffix'])) </div> @endif
+
+    {{-- HINT --}}
+    @if (isset($field['hint']))
+        <p class="help-block">{!! $field['hint'] !!}</p>
+    @endif
+</div>
+
+
+{{-- FIELD EXTRA CSS  --}}
+{{-- push things in the after_styles section --}}
+
+{{-- @push('crud_fields_styles')
+    <!-- no styles -->
+@endpush --}}
+
+
+{{-- FIELD EXTRA JS --}}
+{{-- push things in the after_scripts section --}}
+
+{{-- @push('crud_fields_scripts')
+    <!-- no scripts -->
+@endpush --}}
+
+
+{{-- Note: you can use @if ($crud->checkIfFieldIsFirstOfItsType($field, $fields)) to only load some CSS/JS once, even though there are multiple instances of it --}}