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'];
}
return false;
}
+
+ public function setModel($model_namespace)
+ {
+ parent::setModel($model_namespace);
+ }
+
+ public function updateEntry()
+ {
+ $this->entry = null;
+ return $this->getEntry($this->getCurrentEntryId());
+ }
}
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'))) {
}
$this->addField($field);
}
+
+ $this->crud->updateEntry();
}
{
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'));
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';
+
}
$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);
}
}
foreach ($fields as $field) {
$attr = array_merge($this->defaultFieldAttributes, $field);
-
$this->addFakeField($attr);
}
-
$controller->updateFieldsFromModel();
}
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;
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;
addField as protected bunchAddField;
}
-
protected static $_doctrineTypesMapping = ['int' => 'integer'];
protected $primaryKey = 'id';
}
/**
- * @param $attributes
+ * @param $attributes array
+ * @return Field
+ * @throws \Exception
*/
public function addField($attributes)
{
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;
}
+ return $field;
}
/**
$field->defineDbColumn($table);
}
- foreach ($this->fakeColumns as $fakeColumn => $true) {
+ $this->fakeColumns=array_unique($this->fakeColumns);
+ foreach ($this->fakeColumns as $fakeColumn) {
$table->addColumn($fakeColumn, 'text');
}
--- /dev/null
+<?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 --}}