--- /dev/null
+<?php
+
+namespace Cubist\Backpack\Magic;
+
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Util\Str;
+
+class MagicObserver
+{
+ function creating(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'creating');
+ }
+
+ function created(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'created');
+ }
+
+ function updating(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'updating');
+ }
+
+ function updated(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'updated');
+ }
+
+ function saving(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'saving');
+ }
+
+ function saved(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'saved');
+ }
+
+ function deleting(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'deleting');
+ }
+
+ function deleted(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'deleted');
+ }
+
+ function restoring(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'restoring');
+ }
+
+ function restored(CubistMagicAbstractModel $model)
+ {
+ return $this->_trigger($model, 'restored');
+ }
+
+ protected function _trigger($model, $event)
+ {
+ $event = Str::camel('on_' . $event);
+ if (method_exists($model, $event)) {
+ return $model->$event();
+ }
+ }
+}
]);
}
- /**
- * @param \Cubist\Backpack\Magic\Controllers\CubistMagicController $controller
- * @throws \Exception
- */
- public function onBeforeCreate($controller)
- {
- $this->useTemplateIfNotSet(request('template'), $controller);
- parent::onBeforeCreate($controller);
- }
- public function onBeforeEdit($controller, $id)
+ public function onCreating()
{
- $template = request('template');
- // if the template in the GET parameter is missing, figure it out from the db
- if ($template == false) {
- $template = self::getTemplatesById()[$id];
- }
-
- $this->useTemplateIfNotSet($template);
- $controller->updateFieldsFromModel($this);
- parent::onBeforeEdit($controller, $id);
+ $this->useTemplateIfNotSet(request('template'));
+ return $this->onCreating();
}
- public function onBeforeStore($controller, $request)
+// public function onBeforeEdit($controller, $id)
+// {
+// $template = request('template');
+// // if the template in the GET parameter is missing, figure it out from the db
+// if ($template == false) {
+// $template = self::getTemplatesById()[$id];
+// }
+//
+// $this->useTemplateIfNotSet($template);
+// $controller->updateFieldsFromModel($this);
+// parent::onBeforeEdit($controller, $id);
+// }
+
+ public function onSaving()
{
- $this->useTemplateIfNotSet(\Request::input('template'));
- $controller->updateFieldsFromModel($this);
- parent::onBeforeStore($controller, $request);
+ $this->useTemplateIfNotSet(request('template'));
+ return $this->onSaving();
}
- public function onBeforeUpdate($controller, $request)
+ public function onUpdating()
{
- $this->useTemplateIfNotSet(\Request::input('template'));
- $controller->updateFieldsFromModel($this);
- parent::onBeforeUpdate($controller, $request);
+ $this->useTemplateIfNotSet(request('template'));
+ return $this->onUpdating();
}
+
/**
* @param $template TemplateAbstract|string|null
* @param $controller CubistMagicController
use Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
+use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use Cubist\Backpack\Http\Controllers\Operations\CloneEditOperation;
use Cubist\Backpack\Magic\Fields\Composed;
use Cubist\Backpack\Magic\Fields\Files;
use Cubist\Backpack\Magic\Fields\FilesOrURL;
use Cubist\Backpack\Magic\Fields\HiddenDatetime;
+use Cubist\Backpack\Magic\MagicObserver;
use Cubist\Backpack\Magic\Operations\CreateOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
-use Cubist\Backpack\Magic\Operations\UpdateOperation;
use Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation;
use Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
use Cubist\Backpack\Magic\Fields\UnstoredField;
use Cubist\Backpack\Magic\PageData;
use Cubist\Backpack\Magic\QueryBuilder;
-use Cubist\Backpack\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\Magic\Util;
use Cubist\Util\Json;
use Doctrine\DBAL\Schema\Schema;
static::addGlobalScope('ownerclause', function (Builder $builder) {
static::addOwnerClause($builder);
});
+
+ static::observe(new MagicObserver);
}
public function scopeOneinstance($query)
return $res;
}
- /**
- * @param $controller CubistMagicController
- */
- public function onBeforeCreate($controller)
- {
-
- }
-
- /**
- * @param $controller CubistMagicController
- * @param $id int
- */
- public function onBeforeEdit($controller, $id)
- {
- $this->_createOneInstance($id);
- }
protected function _createOneInstance($id = 1)
{
}
}
- public function onAfterSave()
- {
-
- }
-
- /**
- * @param $controller CubistMagicController
- * @param $request CubistMagicUpdateRequest
- */
-
- public function onBeforeUpdate($controller, $request)
- {
-
- }
-
- /**
- * @param $controller CubistMagicController
- * @param $request CubistMagicUpdateRequest
- */
- public function onBeforeStore($controller, $request)
- {
-
- }
-
/**
* @return EntityData
*/
}
return $nb;
}
+
+ public function onSaved()
+ {
+ return true;
+ }
+
+ public function onSaving()
+ {
+ return true;
+ }
+
+ public function onCreating()
+ {
+ return true;
+ }
+
+ public function onCreated()
+ {
+ return true;
+ }
+
+ public function onUpdating()
+ {
+ return true;
+ }
+
+ public function onUpdated()
+ {
+ return true;
+ }
+
+ public function onDeleting()
+ {
+ return true;
+ }
+
+ public function onDeleted()
+ {
+ return true;
+ }
+
+ public function onRestoring()
+ {
+ return true;
+ }
+
+ public function onRestored()
+ {
+ return true;
+ }
}
}
}
- /**
- * @param \Cubist\Backpack\Magic\Controllers\CubistMagicController $controller
- * @param \Cubist\Backpack\Magic\Requests\CubistMagicUpdateRequest $request
- */
- public function onBeforeUpdate($controller, $request)
+
+ public function onSaving()
{
$this->saveLanguageFile();
- parent::onBeforeUpdate($controller, $request);
+ return parent::onSaving();
}
- public function onAfterSave()
+ public function onSaved()
{
$this->saveLanguageFile();
- parent::onAfterSave();
+ return parent::onSaved();
}
trait CreateOperation
{
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation {
- store as _store;
create as _create;
- setupCreateDefaults as _setupCreateDefaults;
}
/**
return $this->_create();
}
- public function store()
- {
- $res = $this->_store();
- if ($this->crud->entry instanceof CubistMagicAbstractModel) {
- $this->crud->entry->onAfterSave();
- }
- return $res;
- }
-
- protected function setupCreateDefaults()
- {
- $this->_setupCreateDefaults();
- }
}
+++ /dev/null
-<?php
-
-namespace Cubist\Backpack\Magic\Operations;
-
-use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
-
-trait UpdateOperation
-{
- use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation {
- update as _update;
- }
-
- /**
- * Update the specified resource in the database.
- *
- * @return Response
- */
- public function update()
- {
- $res = $this->_update();
- if ($this->crud->entry instanceof CubistMagicAbstractModel) {
- $this->crud->entry->onAfterSave();
- }
- return $res;
- }
-
-}
.bunchmultiple .bunchmultiple__wrapper .item .legend > span .icon img,
.bunchmultiple .bunchmultiple__wrapper .item .legend > span .icon svg {
width: auto;
- height: 15px;
+ height: 25px;
}
.bunchmultiple .bunchmultiple__wrapper .item .legend a.action {
color: #333;
img, svg {
width: auto;
- height: 15px;
+ height: 25px;
}
}
}