Exemplo n.º 1
0
 public function testRemove()
 {
     $objDc = $this->objProperty->getDataContainer();
     $this->objProperty->remove();
     $this->assertFalse($objDc->hasProperty('test'));
     $this->assertFalse(isset($GLOBALS['TL_DCA']['tl_test']['fields']['test']));
 }
Exemplo n.º 2
0
 /**
  * Get activated
  *
  * @param Property $objProperty
  * @param ModelInterface $objModel
  *
  * @return Definition\SubPalette|null
  */
 public static function getActivePropertySubPalette(Property $objProperty, ModelInterface $objModel)
 {
     $objProperty->getDataContainer();
     $varValue = $objModel->getProperty($objProperty->getName());
     if ($objProperty->hasSubPalette($varValue)) {
         return $objProperty->getSubPalette($varValue);
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * @param Property|string $property
  * @param bool $blnFromDataContainer
  * @return $this
  */
 public function removeProperty($property, $blnFromDataContainer = true)
 {
     list($strName, $objProperty) = Property::argument($this, $property);
     if ($objProperty !== null) {
         unset($this->arrProperties[$strName]);
         unset($this->definition['fields'][$strName]);
         foreach ($this->getPalettes() as $strName => $objPalette) {
             $objPalette->removeProperty($strName);
         }
         foreach ($this->getSubPalettes() as $strName => $objSubPalette) {
             $objSubPalette->removeProperty($strName);
         }
         if (in_array($strName, $this->definition['palettes']['__selector__'])) {
             $intKey = array_search($strName, $this->definition['palettes']['__selector__']);
             unset($this->definition['palettes']['__selector__'][$intKey]);
             $this->definition['palettes']['__selector__'] = array_values($this->definition['palettes']['__selector__']);
         }
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Move property to new position
  *
  * @param Property|string $property
  * @param string $strLegend
  * @param null $reference
  * @param int $intPosition
  *
  * @return $this
  */
 public function moveProperty($property, $strLegend = 'default', $reference = null, $intPosition = Definition::LAST)
 {
     list($strName, $objProperty) = Property::argument($this, $property);
     if (!$this->hasLegend($strLegend)) {
         $this->createLegend($strLegend);
     }
     /** @var \DcaTools\Definition\Property $objProperty */
     if ($objProperty === null) {
         if ($this->hasProperty($strName)) {
             $objProperty = $this->getProperty($strName);
             if ($objProperty->getParent() != $this) {
                 $objProperty->getParent()->removeProperty($objProperty);
                 $this->getLegend($strLegend)->addProperty($objProperty);
             }
         } else {
             $objProperty = $this->getDataContainer()->getProperty($this);
             $this->getLegend($strLegend)->addProperty($objProperty);
         }
     } elseif ($objProperty->getParent() != $this && !$this->getLegend($strLegend)->hasProperty($strName)) {
         $objProperty->getParent()->removeProperty($objProperty);
         $this->getLegend($strLegend)->addProperty($objProperty);
     }
     $this->getLegend($strLegend)->moveProperty($objProperty, $reference, $intPosition);
     return $this;
 }
 /**
  * Move property to new position
  *
  * @param Property|string $property
  * @param null $reference
  * @param $intPosition
  * @return $this
  */
 public function moveProperty($property, $reference = null, $intPosition = Definition::LAST)
 {
     /** @var Property $objProperty */
     list($strName, $objProperty) = Property::argument($this, $property, false);
     $this->requireSameDataContainer($objProperty);
     if ($objProperty->getParent() instanceof DataContainer) {
         if ($this != $objProperty->getParent()) {
             $objProperty = clone $objProperty;
             $objProperty->setParent($this);
         }
     } elseif ($objProperty->getParent() !== null && $this !== $objProperty->getParent()) {
         $objProperty->getParent()->remove();
     }
     if ($this->hasProperty($strName)) {
         unset($this->arrProperties[$strName]);
         $this->addAtPosition($this->arrProperties, $objProperty, $reference, $intPosition);
         $this->updateDefinition();
     } else {
         $this->addProperty($objProperty, $reference, $intPosition);
     }
     return $this;
 }