class CubistCrudPanel extends CrudPanel
{
+ public function hasField($name)
+ {
+ $lists = ['getCreateFields', 'getUpdateFields'];
+ foreach ($lists as $list) {
+ foreach ($this->$list(1) as $field) {
+ if ($field['name'] == $name) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
$this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
+ $this->updateFieldsFromModel();
+
+ }
+
+ public function updateFieldsFromModel()
+ {
+ $model = $this->getModelInstance();
foreach ($model->getFields() as $field) {
+ if ($this->crud->hasField($field->getAttribute('name'))) {
+ continue;
+ }
$this->addField($field);
}
-
}
namespace Cubist\Backpack\app\Magic\Models;
+use Cubist\Backpack\app\Template\TemplateAbstract;
+
class CMSPage extends CubistMagicModel
{
protected static $_templates = [];
]);
}
- public function onBeforeEdit($controller, $id)
+ public function onBeforeCreate($controller)
{
-
+ parent::onBeforeCreate($controller);
}
- public function onBeforeUpdate($controller, $request)
+ public function onBeforeEdit($controller, $id)
{
-
+ parent::onBeforeEdit($controller, $id);
}
public function onBeforeStore($controller, $request)
{
+ parent::onBeforeStore($controller, $request);
+ }
+ public function onBeforeUpdate($controller, $request)
+ {
+ parent::onBeforeUpdate($controller, $request);
}
+ /**
+ * @param $template
+ * @throws \Exception
+ */
+ protected function useTemplate($template)
+ {
+ if (is_string($template)) {
+ $template = new $template();
+ }
+
+ $fields = $template->getFields();
+ if (!count($fields)) {
+ return;
+ }
+ foreach ($fields as $field) {
+ $this->addFakeField($field);
+ }
+ }
}
return $this->{$this->getPrimaryKey()};
}
- protected function useTemplate($template)
- {
-
- }
/**
* @param $controller CubistMagicController
namespace Cubist\Backpack\app\Template;
-use Cubist\Backpack\app\Magic\BunchOfFields;
use Illuminate\Support\Str;
class TemplateAbstract
{
- use BunchOfFields;
/**
* @var TemplateAbstract[]
*/
protected static $_templates = null;
- protected function _seo()
- {
- $this->addField([
- 'name' => 'meta_title',
- 'label' => trans('backpack::pagemanager.meta_title'),
- 'type' => 'Text',
- 'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
- 'tab' => 'Meta // SEO',
- ]);
- $this->addField([
- 'name' => 'meta_description',
- 'label' => trans('backpack::pagemanager.meta_description'),
- 'type' => 'Textarea',
- 'hint' => __('Recommended length: 160 chars'),
- 'tab' => 'Meta // SEO',
- ]);
- $this->addField([
- 'name' => 'robots',
- 'label' => __('Allow page index by search engines'),
- 'type' => 'Checkbox',
- 'default' => true,
- 'tab' => 'Meta // SEO',
- ]);
- }
+ protected $defaultFieldAttributes = ['translate' => true];
+
+ protected $_fields = [];
public function init()
{
- $this->_common();
+
}
- protected function _common()
+ /**
+ * @param $attributes array
+ */
+ public function addField($attributes)
{
- $this->addField([
- 'name' => 'status',
- 'type' => 'SelectFromArray',
- 'default' => '0',
- 'label' => __('Status'),
- 'options' => ['0' => __('Offline'), '1' => __('Published')],
- 'tab' => 'Général',
- ]);
- $this->_seo();
+ $attributes = array_merge($this->defaultFieldAttributes, $attributes);
+ $this->_fields[$attributes['name']] = $attributes;
}
+ /**
+ * @return array
+ */
+ public function getFields()
+ {
+ return $this->_fields;
+ }
public function showInDropDown()
{