]> _ Git - cubist_cms-back.git/commitdiff
wip #5041 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jan 2022 17:04:00 +0000 (18:04 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jan 2022 17:04:00 +0000 (18:04 +0100)
src/app/Magic/Models/CubistMagicAbstractModel.php

index c996869ab450d5c4a0c21bd61653eae6816cf92f..b5c5ce92be79878b3ca10b8cfcd7f5688824eceb 100644 (file)
@@ -72,6 +72,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
 
     protected $_baseController = CubistMagicController::class;
 
+    protected static array $_reservedNames = ['media'];
+
     /**
      * @var array
      */
@@ -328,6 +330,13 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $attributes;
     }
 
+    protected function checkForReservedNames($name)
+    {
+        if (in_array($name, static::$_reservedNames)) {
+            throw new \Exception(sprintf('The attribute name %s is reserved', $name));
+        }
+    }
+
     /**
      * @param string|array $name
      * @param string $type
@@ -340,6 +349,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     {
         $attributes = self::normalizeAttributes($name, $type, $label, $attributes);
 
+        $this->checkForReservedNames($name);
+
         $field = $this->bunchAddField($attributes);
         $field->setModelInstance($this);
         $name = $field->getAttribute('name');