Пример #1
0
 /**
  * Populates the default on a single field if it's not already set
  * and the default generated is not a null value or empty array.
  *
  * @param Field $field
  * @return bool Returns true if a non null/empty default was applied or already present.
  */
 private function populateDefault(Field $field)
 {
     if ($this->has($field->getName())) {
         return true;
     }
     $default = $field->getDefault($this);
     if (null === $default) {
         return false;
     }
     if ($field->isASingleValue()) {
         $this->data[$field->getName()] = $default;
         unset($this->clearedFields[$field->getName()]);
         return true;
     }
     if (empty($default)) {
         return false;
     }
     /*
      * sets have a special handling to deal with unique values
      */
     if ($field->isASet()) {
         $this->addToSet($field->getName(), $default);
         return true;
     }
     $this->data[$field->getName()] = $default;
     unset($this->clearedFields[$field->getName()]);
     return true;
 }