CRUDlex\AbstractData::createEmpty PHP Method

createEmpty() public method

Creates a new, empty entity instance having all fields prefilled with null or the defined value in case of fixed fields.
public createEmpty ( ) : Entity
return Entity the newly created entity
    public function createEmpty()
    {
        $entity = new Entity($this->definition);
        $fields = $this->definition->getEditableFieldNames();
        foreach ($fields as $field) {
            $value = null;
            if ($this->definition->getType($field) == 'fixed') {
                $value = $this->definition->getField($field, 'value');
            }
            $entity->set($field, $value);
        }
        $entity->set('id', null);
        return $entity;
    }