From: Vincent Vanwaelscappel Date: Fri, 21 Jun 2019 15:36:21 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3061b196baab2b4c99d521c1257efa252a855f2f;p=cubist_cms-back.git #2843 --- diff --git a/src/app/CubistCrudPanel.php b/src/app/CubistCrudPanel.php index 05efc8c..0ebcc2e 100644 --- a/src/app/CubistCrudPanel.php +++ b/src/app/CubistCrudPanel.php @@ -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()); + } } diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index 40196c3..8478592 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -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(); } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index abc5917..dde0ce4 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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')); diff --git a/src/app/Magic/Fields/Text.php b/src/app/Magic/Fields/Text.php index 3cc2e35..22eb7fe 100644 --- a/src/app/Magic/Fields/Text.php +++ b/src/app/Magic/Fields/Text.php @@ -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'; + } diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 1276e8e..9407547 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -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(); } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 31073ea..912cb04 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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 index 0000000..8ecfab3 --- /dev/null +++ b/src/resources/views/fields/text.blade.php @@ -0,0 +1,43 @@ + + +
+ + @include('crud::inc.field_translatable_icon') + + @if(isset($field['prefix']) || isset($field['suffix']))
@endif + @if(isset($field['prefix']))
{!! $field['prefix'] !!}
@endif + + @if(isset($field['suffix']))
{!! $field['suffix'] !!}
@endif + @if(isset($field['prefix']) || isset($field['suffix']))
@endif + + {{-- HINT --}} + @if (isset($field['hint'])) +

{!! $field['hint'] !!}

+ @endif +
+ + +{{-- FIELD EXTRA CSS --}} +{{-- push things in the after_styles section --}} + +{{-- @push('crud_fields_styles') + +@endpush --}} + + +{{-- FIELD EXTRA JS --}} +{{-- push things in the after_scripts section --}} + +{{-- @push('crud_fields_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 --}}