code/extensions/QuickAddNewExtension.php
public function doAddNew($data, $form)
    {
        $obj = Object::create($this->addNewClass);
        if (!$obj->canCreate()) {
            return Security::permissionFailure(Controller::curr(), "You don't have permission to create this object");
        }
        $form->saveInto($obj);

        try {
            $obj->write();
        } catch (Exception $e) {
            $form->setMessage($e->getMessage(), 'error');
            return $form->forTemplate();
        }

        $callback = $this->sourceCallback;
        $items = $callback($obj);
        $this->owner->setSource($items);

        // if this field is a multiselect field, we add the new Object ID to the existing
        // options that are selected on the field then set that as the value
        // otherwise we just set the new Object ID as the value
        if (isset($data['existing'])) {
            $existing = $data['existing'];
            $value = explode(',', $existing);
            $value[] = $obj->ID;
        } else {
            $value = $obj->ID;
        }

        $this->owner->setValue($value);
        // NOTE(Jake): Below line causes cyclic issues, I assume it's not necessary.
        //$this->owner->setForm($form);
        return $this->owner->FieldHolder();
    }
public function doAddNew($data, $form)
    {
        $obj = Object::create($this->addNewClass);
        if (!$obj->canCreate()) {
            return Security::permissionFailure(Controller::curr(), "You don't have permission to create this object");
        }
        $form->saveInto($obj);

        try {
            $obj->write();
        } catch (Exception $e) {
            $form->setMessage($e->getMessage(), 'error');
            return $form->forTemplate();
        }

        $callback = $this->sourceCallback;
        $items = $callback($obj);
        $this->owner->setSource($items);

        // if this field is a multiselect field, we add the new Object ID to the existing
        // options that are selected on the field then set that as the value
        // otherwise we just set the new Object ID as the value
        if (isset($data['existing'])) {
            $existing = $data['existing'];
            $value = explode(',', $existing);
            $value[] = $obj->ID;
        } else {
            $value = $obj->ID;
        }

        $this->owner->setValue($value);
        // NOTE(Jake): Below line causes cyclic issues, I assume it's not necessary.
        //$this->owner->setForm($form);
        return $this->owner->FieldHolder();
    }
public function doAddNew ( $ data , $ form ) { $ obj = Object :: create ( $ this -> addNewClass ) ; if ( ! $ obj -> canCreate ( ) ) { return Security :: permissionFailure ( Controller :: curr ( ) , "You don't have permission to create this object" ) ; } $ form -> saveInto ( $ obj ) ; try { $ obj -> write ( ) ; } catch ( Exception $ e ) { $ form -> setMessage ( $ e -> getMessage ( ) , 'error' ) ; return $ form -> forTemplate ( ) ; } $ callback = $ this -> sourceCallback ; $ items = $ callback ( $ obj ) ; $ this -> owner -> setSource ( $ items ) ; // if this field is a multiselect field, we add the new Object ID to the existing // options that are selected on the field then set that as the value // otherwise we just set the new Object ID as the value if ( isset ( $ data [ 'existing' ] ) ) { $ existing = $ data [ 'existing' ] ; $ value = explode ( ',' , $ existing ) ; $ value [ ] = $ obj -> ID ; } else { $ value = $ obj -> ID ; } $ this -> owner -> setValue ( $ value ) ; // NOTE(Jake): Below line causes cyclic issues, I assume it's not necessary. //$this->owner->setForm($form); return $ this -> owner -> FieldHolder ( ) ; }
Handles adding the new object
Returns the updated FieldHolder of this form to replace the existing one

@return string
Handles adding the new object Returns the updated FieldHolder of this form to replace the existing one