"league/commonmark-ext-autolink": "^1.0",
"cviebrock/laravel-elasticsearch": "^3.6",
"spatie/laravel-honeypot": "^1.3",
- "chrisjean/php-ico": "^1.0"
-
+ "chrisjean/php-ico": "^1.0",
+ "ext-json": "*"
},
"require-dev": {
"filp/whoops": "^2.3",
return '[]';
}
- $string=is_string($value);
+ $string = is_string($value);
if ($string) {
$decoded = json_decode($value, 1);
} else {
$decoded = json_decode(json_encode($value), 1);
}
+ if (null === $decoded) {
+ $decoded = [];
+ }
$res = [];
foreach ($decoded as $i => $item) {
+ if (is_string($item)) {
+ continue;
+ }
if (!isset($item['id']) || $item['id'] == '') {
$item['id'] = $i;
}
return $item;
}
/** @var $item PageItem */
- if (stristr($item->getTemplate(), 'redirection')) {
+ if (stripos($item->getTemplate(), 'redirection') !== false) {
continue;
}
return $item;
use Cubist\Backpack\app\Magic\PageData;
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\app\Magic\Util;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
use Cubist\Util\Json;
+use Cviebrock\EloquentSluggable\Sluggable;
+use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Illuminate\Database\Eloquent\Model;
use Sluggable;
use SluggableScopeHelpers;
use HasMediaTrait;
- use HasTranslations {
- update as protected updateTranslations;
- create as protected createTranslations;
- }
use RevisionableTrait;
use BunchOfFields {
addField as protected bunchAddField;
*/
protected $_slugFields = ['slug', 'title', 'name'];
- /**
- * @var array
- */
- protected $translatable = [];
-
/**
* @var array
*/
}
$this->fakeColumns = array_unique($this->fakeColumns);
- $this->translatable = array_unique($this->translatable);
}
}
// do not enable it again !!
// $this->casts[$store_in] = 'array';
- if ($field->getAttribute('translatable')) {
- if (!in_array($store_in, $this->translatable)) {
- $this->translatable[] = $store_in;
- }
- }
-
if (!in_array($store_in, $this->fakeColumns)) {
$this->fakeColumns[] = $store_in;
}
if ($field->getAttribute('cast', false) !== false) {
$this->casts[$field->getAttribute('name')] = $field->getAttribute('cast');
}
- if ($field->getAttribute('translatable')) {
- $this->translatable[] = $name;
- }
}
return $field;
try {
$table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]);
} catch (\Exception $e) {
- return $e->getMessage();
+
}
$table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
foreach ($this->_relationships as $relationship) {
- if ($relationship->getRelationship() == 'belongsToMany') {
+ if ($relationship->getRelationship() === 'belongsToMany') {
$model = self::_toModel($relationship->getAttribute('model'));
}
foreach ($this->_fields as $field) {
- if ($field->getRelationship() == 'belongsToMany') {
+ if ($field->getRelationship() === 'belongsToMany') {
continue;
}
if ($field->getAttribute('fake', false) !== false) {
{
$res = [];
foreach ($attributes as $k => $attribute) {
- if (stristr($k, '___')) {
+ if (strpos($k, '___') !== false) {
continue;
}
- if (stristr($k, 'bunchmultiple_')) {
+ if (stripos($k, 'bunchmultiple_') !== false) {
continue;
}
$res[$k] = $attribute;
return $res;
}
- public function update(array $attributes = [], array $options = [])
- {
- return $this->updateTranslations($this->_prepareData($attributes), $options);
- }
-
- public function create(array $attributes = [])
- {
- return $this->createTranslations($this->_prepareData($attributes));
- }
-
- public function getSlugAttribute($value)
- {
- if (!$value) {
- return Str::slug($this->title);
- }
- return $value;
- }
-
/**
* @param $controller CubistMagicController
*/
+++ /dev/null
-<?php
-
-namespace Cubist\Backpack\app\Magic\Models;
-
-class CubistMagicModel extends CubistMagicAbstractModel
-{
-
-}
namespace Cubist\Backpack\app\Magic\Models;
-class CubistMagicPageModel extends CubistMagicModel
+class CubistMagicPageModel extends CubistMagicTranslatableModel
{
public function setFields()
{
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Models;
+
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
+
+class CubistMagicTranslatableModel extends CubistMagicAbstractModel
+{
+ use Sluggable;
+ use SluggableScopeHelpers;
+ use HasTranslations {
+ update as protected updateTranslations;
+ create as protected createTranslations;
+ }
+
+ /**
+ * @var array
+ */
+ protected $translatable = [];
+
+ public function postSetFields()
+ {
+ parent::postSetFields();
+ $this->translatable = array_unique($this->translatable);
+ }
+
+ public function addField($attributes)
+ {
+ $field = parent::addField($attributes);
+ if ($field->getAttribute('fake', false) === true) {
+ if ($field->getAttribute('translatable')) {
+ if (!in_array($field->getAttribute('store_in'), $this->translatable)) {
+ $this->translatable[] = $field->getAttribute('store_in');
+ }
+ }
+ } else {
+ if ($field->getAttribute('translatable')) {
+ $this->translatable[] = $field->getAttribute('name');
+ }
+ }
+
+ return $field;
+ }
+
+ public function update(array $attributes = [], array $options = [])
+ {
+ return $this->updateTranslations($this->_prepareData($attributes), $options);
+ }
+
+ public function create(array $attributes = [])
+ {
+ return $this->createTranslations($this->_prepareData($attributes));
+ }
+
+}
namespace Cubist\Backpack\app\Magic\Models;
-class Locale extends CubistMagicModel
+class Locale extends CubistMagicAbstractModel
{
protected $table = 'cubist_locales';
'type' => 'Checkbox',
'label' => 'Par défaut',
'column' => true]);
+
+ $this->addField(['name' => 'domains',
+ 'type' => 'Table',
+ 'label' => 'Domaines',
+ 'columns' => ['env' => 'Environnement', 'domain' => 'Domaine'],
+ 'translatable' => false,
+ ]);
}
}
namespace Cubist\Backpack\app\Magic\Models;
-
-class News extends CubistMagicPageModel
+class News extends CubistMagicTranslatableModel
{
protected $table = 'cubist_news';
use Cubist\Backpack\app\Magic\PageData;
use Spatie\MediaLibrary\Models\Media;
-class Settings extends CubistMagicModel
+class Settings extends CubistMagicTranslatableModel
{
/** @var PageData|null */
protected static $_data = null;
namespace Cubist\Backpack\app\Magic\Models;
-
-class Translate extends CubistMagicModel
+class Translate extends CubistMagicTranslatableModel
{
protected $table = 'cubist_translate';