/**
  * Set the value of this field in various formats.
  * Used by {@link DataObject->getField()}, {@link DataObject->setCastedField()}
  * {@link DataObject->dbObject()} and {@link DataObject->write()}.
  * 
  * As this method is used both for initializing the field after construction,
  * and actually changing its values, it needs a {@link $markChanged}
  * parameter. 
  * 
  * @param DBField|array $value
  * @param array $record Map of values loaded from the database
  * @param boolean $markChanged Indicate wether this field should be marked changed. 
  *  Set to FALSE if you are initializing this field after construction, rather
  *  than setting a new value.
  */
 public function setValue($value, $record = null, $markChanged = true)
 {
     if ($value instanceof NamedLinkField && $value->exists()) {
         $this->setPageID($value->getPageID(), $markChanged);
         $this->setCustomURL($value->getCustomURL(), $markChanged);
         $this->setTitle($value->getTitle(), $markChanged);
         $this->setLinkmode($value->getLinkmode(), $markChanged);
     } elseif ($record && (isset($record[$this->name . 'PageID']) || isset($record[$this->name . 'CustomURL']) || isset($record[$this->name . 'Title']) || isset($record[$this->name . 'Linkmode']))) {
         $this->setPageID(isset($record[$this->name . 'PageID']) ? $record[$this->name . 'PageID'] : null, $markChanged);
         $this->setCustomURL(isset($record[$this->name . 'CustomURL']) ? $record[$this->name . 'CustomURL'] : null, $markChanged);
         $this->setTitle(isset($record[$this->name . 'Title']) ? $record[$this->name . 'Title'] : null, $markChanged);
         $this->setLinkmode(isset($record[$this->name . 'Linkmode']) ? $record[$this->name . 'Linkmode'] : null, $markChanged);
     } else {
         if (is_array($value)) {
             if (array_key_exists('PageID', $value)) {
                 $this->setPageID($value['PageID'], $markChanged);
             }
             if (array_key_exists('CustomURL', $value)) {
                 $this->setCustomURL($value['CustomURL'], $markChanged);
             }
             if (array_key_exists('Title', $value)) {
                 $this->setTitle($value['Title'], $markChanged);
             }
             if (array_key_exists('Linkmode', $value)) {
                 $this->setLinkmode($value['Linkmode'], $markChanged);
             }
         } else {
             //			user_error('Invalid value in LinkField->setValue()', E_USER_ERROR);
         }
     }
 }