protected $hidden = [];
+ protected $revisionEnabled = false;
+
public function _postSetModel()
{
}
}
- if (!$model->isRevisionEnabled()) {
- $this->revisionEnabled = false;
+ if ($model->isRevisionEnabled()) {
+ $this->revisionEnabled = true;
}
$this->crud->setRoute(backpack_url($this->_routeURL));
}
}
- public function addFakes($columns = ['extras'])
- {
- try {
- return parent::addFakes($columns);
- } catch (\Exception $e) {
-
- }
-
- foreach ($columns as $key => $column) {
- if (!isset($this->attributes[$column])) {
- continue;
- }
-
- $column_contents = $this->{$column};
-
- if ($this->shouldDecodeFake($column) && is_string($column_contents)) {
- $column_contents = json_decode($column_contents);
- }
-
- if ((is_array($column_contents) || is_object($column_contents) || $column_contents instanceof Traversable)) {
- foreach ($column_contents as $fake_field_name => $fake_field_value) {
- $this->setAttribute($fake_field_name, $fake_field_value);
- }
- }
- }
- }
-
public function getFields()
{
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\Sluggable;
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\SluggableScopeHelpers;
use Cubist\Util\Json;
+use Cubist\Util\PHP;
class CubistMagicTranslatableModel extends CubistMagicAbstractModel
{
*/
protected $_availableLocales = 'backpack';
+ protected $_castCache = null;
+
+ protected $_fakesAdded = false;
+
public function postSetFields()
{
+ PHP::neverStop();
+
parent::postSetFields();
$this->translatable = array_unique($this->translatable);
}
if (!in_array($field->getAttribute('store_in'), $this->translatable)) {
$this->translatable[] = $field->getAttribute('store_in');
}
+ $this->translatable[] = $field->getAttribute('name');
}
} else {
if ($field->getAttribute('translatable')) {
if (isset($this->_translations[$key])) {
return $this->_translations[$key];
}
- $measure_label = 'Get translation of ' . get_class($this) . '::' . $key;
- throw new \Error(':(');
- start_measure($measure_label);
+// $measure_label = 'Get translation in ' . get_class($this);
+// start_measure($measure_label);
$this->guardAgainstNonTranslatableAttribute($key);
$attrs = $this->getAttributes();
if (!isset($attrs[$key])) {
});
}
$this->_translations[$key] = $res;
- stop_measure($measure_label);
+// stop_measure($measure_label);
return $res;
}
return $res;
}
+
public function copyAllTranslations($from, $to, $overwrite = false)
{
$i = 0;
$this->save();
}
+ public function addFakes($columns = ['extras'])
+ {
+ if ($this->_fakesAdded) {
+ return;
+ }
+ $this->_fakesAdded = true;
+ start_measure('add fakes ' . get_class($this));
+ $res = parent::addFakes($columns);
+ stop_measure('add fakes ' . get_class($this));
+ return $res;
+ }
+
public function getAttribute($key)
{
+// $label = 'getAttribute in ' . get_class($this);
+// start_measure($label);
$f = $this->getField($key);
$value = parent::getAttribute($key);
if (!$value && null !== $f && $f->isMigrateTranslation()) {
}
if (null === $f) {
- return $value;
+ $res = $value;
+ } else {
+ $res = $f->filterValue($value);
}
- return $f->filterValue($value);
+ //stop_measure($label);
+ return $res;
}
protected function _migrateTranslation($key)
public function getAvailableLocales()
{
+ start_measure('getAvailableLocales()');
if ($this->_availableLocales === 'backpack') {
$res = $this->getAvailableLocalesTranslations();
} else if (is_array($this->_availableLocales)) {
}
uksort($res, [$this, '_sortLocales']);
+ stop_measure('getAvailableLocales()');
return $res;
}
{
return strcmp($a, $b);
}
-
}
+@php
+
+ start_measure('Render edit form');
+@endphp
+
@extends(backpack_view('blank'))
@include('cubist_back::form.additional_edit_views')
// When clicking on a locale link in the dropdown menu, it doesn't preserve
// the current tab because this is stored in the hash and managed by JS.
// To overcome this, we catch the locale links and append the hash to them...
- $(document).on('click', '.dropdown-menu a[href*="?locale="]', function (event) {
+ $(document).on('click', '.dropdown-menu a[href*="?_locale="]', function (event) {
event.preventDefault();
window.location.href = $(this).attr('href') + document.location.hash;
});
<small>{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.</small>
@if ($crud->hasAccess('list'))
- <small><a href="{{ url($crud->route) }}" class="hidden-print font-sm"><i
+ <small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i
class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }}
<span>{{ $crud->entity_name_plural }}</span></a></small>
@endif
@section('content')
<div class="row">
<div class="{{ $crud->getEditContentClass() }}">
- <!-- Default box -->
+ {{-- Default box --}}
@include('crud::inc.grouped_errors')
<form method="post"
action="{{ url($crud->route.'/'.$entry->getKey()) }}"
@if ($crud->hasUploadFields('update', $entry->getKey()))
- enctype="multipart/form-data"
+ enctype="multipart/form-data"
@endif
>
{!! csrf_field() !!}
@if ($crud->model->translationEnabled())
<div class="mb-2 text-right">
- <!-- Single button -->
+ {{-- Single button --}}
<div class="btn-group">
<button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{{trans('backpack::crud.language')}}
- : {{ $crud->model->getAvailableLocales()[request()->input('locale')?request()->input('locale'):App::getLocale()] }}
+ : {{ $crud->model->getAvailableLocales()[request()->input('_locale')?request()->input('_locale'):App::getLocale()] }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
@foreach ($crud->model->getAvailableLocales() as $key => $locale)
<a class="dropdown-item"
- href="{{ url($crud->route.'/'.$entry->getKey().'/edit') }}?locale={{ $key }}">{{ $locale }}</a>
+ href="{{ url($crud->route.'/'.$entry->getKey().'/edit') }}?_locale={{ $key }}">{{ $locale }}</a>
@endforeach
</ul>
</div>
</div>
@endif
- <!-- load the view from the application if it exists, otherwise load the one in the package -->
+ {{-- load the view from the application if it exists, otherwise load the one in the package --}}
@if(view()->exists('vendor.backpack.crud.form_content'))
@include('vendor.backpack.crud.form_content', ['fields' => $crud->fields(), 'action' => 'edit'])
@else
@include('crud::form_content', ['fields' => $crud->fields(), 'action' => 'edit'])
@endif
-
+ {{-- This makes sure that all field assets are loaded. --}}
+ <div class="d-none" id="parentLoadedAssets">{{ json_encode(Assets::loaded()) }}</div>
@include('crud::inc.form_save_buttons')
</form>
</div>
@stack('after_form')
@endsection
+@php
+
+ stop_measure('Render edit form');
+@endphp