{
public function getAttribute($key, $default = null)
{
- if (isset($this->_attributes[$key])) {
+ if ($this->hasAttribute($key)) {
return $this->_attributes[$key];
}
return $default;
}
+
+ public function hasAttribute($key)
+ {
+ return isset($this->_attributes[$key]);
+ }
+
+ public function setAttribute($key, $value)
+ {
+ $this->_attributes[$key] = $value;
+ }
}
public function __construct($attributes)
{
$this->_attributes = array_merge($this->getDefaultAttributes(), $attributes);
+ $this->_postSetAttributes();
$this->init();
}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+use Illuminate\Support\Str;
+
+class Model extends Field
+{
+ public function __construct($attributes)
+ {
+ parent::__construct($attributes);
+ }
+
+ public function getDefaultAttributes()
+ {
+ return array_merge(parent::getDefaultAttributes(), ['attribute' => 'name', 'allow_null' => false, 'allow_multiples' => $this->_multiple]);
+ }
+
+ protected function _postSetAttributes()
+ {
+ if (!$this->hasAttribute('entity')) {
+ $this->setAttribute('entity', $this->getAttribute('name'));
+ }
+ }
+}
--- /dev/null
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+class SelectFromModel extends Model
+{
+ protected $_adminType = 'select2';
+ protected $_databaseType = 'string';
+ protected $_multiple = false;
+
+
+}
*/
protected $translatable = [];
+
+ /**
+ * @var array
+ */
+ protected $_relationships = [];
+
public function __construct(array $attributes = [])
{
$this->setFields();
*/
public function addField($attributes)
{
+
+
/** @var Field $field */
$field = Field::getInstance($attributes);
+ if (isset($attributes['relationship'])) {
+ $this->_addRelationship($field, $attributes['relationship']);
+ }
+
$name = $field->getAttribute('name');
$this->_fields[$name] = $field;
-
if ($field->getAttribute('fillable')) {
$this->fillable[] = $name;
}
}
}
+ protected function _addRelationship($field, $relationship)
+ {
+ $this->_relationships[] = ['field' => $field, 'relationship' => $relationship];
+ }
+
public function generateCode()
{
$this->_generateControllerCode();
$this->replicateSluggable($except);
}
+ public function __call($method, $parameters)
+ {
+ if (stristr())
+
+ return parent::__call($method, $parameters);
+ }
+
public static function toDoctrineType($type)
{
if (isset(self::$_doctrineTypesMapping[$type])) {
}
return $type;
}
-
-
}
/**
* @return string
*/
- protected function _getBaseController(){
+ protected function _getBaseController()
+ {
return 'CubistMagicNestedController';
}
-
}