public function createNewOption($name, $value, $itemdata = null)
 {
     if ($this->getType() == self::CALCULATED_FIELD) {
         // Only allow one option/formula for the calculated field
         $opts = $this->getOptions();
         foreach ($opts as $option) {
             $option->delete();
         }
     }
     $option = new TBGCustomDatatypeOption();
     $option->setName($name);
     $option->setKey($this->getKey());
     $option->setValue($value);
     $option->setItemdata($itemdata);
     $option->setCustomdatatype($this->_id);
     $option->save();
     // In order to set permissions correctly the item type has to be the same
     // as the option id not the item field. set the opton id with the newly generated
     // option ID and save again
     $option->setItemtype($option->getID());
     $option->save();
     $this->_options = null;
     return $option;
 }
 public function createNewOption($name, $value, $itemdata = null)
 {
     $option = new TBGCustomDatatypeOption();
     $option->setName($name);
     $option->setItemtype($this->_itemtype);
     $option->setKey($this->getKey());
     $option->setValue($value);
     $option->setItemdata($itemdata);
     $option->save();
     $this->_options = null;
     return $option;
 }