code/extensions/QuickAddNewExtension.php
public function useAddNew(
        $class,
        $sourceCallback,
        FieldList $fields = null,
        RequiredFields $required = null,
        $isFrontend = false
    ) {
        if (!is_callable($sourceCallback)) {
            throw new Exception(
                'the useAddNew method must be passed a callable $sourceCallback parameter, ' . gettype($sourceCallback) . ' passed.'
            );
        }

        // if the user can't create this object type, don't modify the form
        if (!singleton($class)->canCreate()) {
            return $this->owner;
        }

        Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
        Requirements::javascript(QUICKADDNEW_MODULE . '/javascript/quickaddnew.js');
        Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
        Requirements::css(QUICKADDNEW_MODULE . '/css/quickaddnew.css');
        Requirements::add_i18n_javascript(QUICKADDNEW_MODULE . '/javascript/lang');
        if (!$fields) {
            if (singleton($class)->hasMethod('getAddNewFields')) {
                $fields = singleton($class)->getAddNewFields();
            } else {
                $fields = singleton($class)->getCMSFields();
            }
        }

        if (!$required) {
            if (singleton($class)->hasMethod('getAddNewValidator')) {
                $required = singleton($class)->getAddNewValidator();
            }
        }

        $this->owner->addExtraClass('quickaddnew-field');
        $this->addNewEnabled = true;

        $this->sourceCallback        = $sourceCallback;
        $this->isFrontend            = $isFrontend;
        $this->addNewClass            = $class;
        $this->addNewFields        = $fields;
        $this->addNewRequiredFields = $required;

        return $this->owner;
    }
public function useAddNew(
        $class,
        $sourceCallback,
        FieldList $fields = null,
        RequiredFields $required = null,
        $isFrontend = false
    ) {
        if (!is_callable($sourceCallback)) {
            throw new Exception(
                'the useAddNew method must be passed a callable $sourceCallback parameter, ' . gettype($sourceCallback) . ' passed.'
            );
        }

        // if the user can't create this object type, don't modify the form
        if (!singleton($class)->canCreate()) {
            return $this->owner;
        }

        Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
        Requirements::javascript(QUICKADDNEW_MODULE . '/javascript/quickaddnew.js');
        Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
        Requirements::css(QUICKADDNEW_MODULE . '/css/quickaddnew.css');
        Requirements::add_i18n_javascript(QUICKADDNEW_MODULE . '/javascript/lang');
        if (!$fields) {
            if (singleton($class)->hasMethod('getAddNewFields')) {
                $fields = singleton($class)->getAddNewFields();
            } else {
                $fields = singleton($class)->getCMSFields();
            }
        }

        if (!$required) {
            if (singleton($class)->hasMethod('getAddNewValidator')) {
                $required = singleton($class)->getAddNewValidator();
            }
        }

        $this->owner->addExtraClass('quickaddnew-field');
        $this->addNewEnabled = true;

        $this->sourceCallback        = $sourceCallback;
        $this->isFrontend            = $isFrontend;
        $this->addNewClass            = $class;
        $this->addNewFields        = $fields;
        $this->addNewRequiredFields = $required;

        return $this->owner;
    }
public function useAddNew ( $ class , $ sourceCallback , FieldList $ fields = null , RequiredFields $ required = null , $ isFrontend = false ) { if ( ! is_callable ( $ sourceCallback ) ) { throw new Exception ( 'the useAddNew method must be passed a callable $sourceCallback parameter, ' . gettype ( $ sourceCallback ) . ' passed.' ) ; } // if the user can't create this object type, don't modify the form if ( ! singleton ( $ class ) -> canCreate ( ) ) { return $ this -> owner ; } Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/jquery.js' ) ; Requirements :: javascript ( THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js' ) ; Requirements :: javascript ( THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js' ) ; Requirements :: javascript ( QUICKADDNEW_MODULE . '/javascript/quickaddnew.js' ) ; Requirements :: css ( THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css' ) ; Requirements :: css ( QUICKADDNEW_MODULE . '/css/quickaddnew.css' ) ; Requirements :: add_i18n_javascript ( QUICKADDNEW_MODULE . '/javascript/lang' ) ; if ( ! $ fields ) { if ( singleton ( $ class ) -> hasMethod ( 'getAddNewFields' ) ) { $ fields = singleton ( $ class ) -> getAddNewFields ( ) ; } else { $ fields = singleton ( $ class ) -> getCMSFields ( ) ; } } if ( ! $ required ) { if ( singleton ( $ class ) -> hasMethod ( 'getAddNewValidator' ) ) { $ required = singleton ( $ class ) -> getAddNewValidator ( ) ; } } $ this -> owner -> addExtraClass ( 'quickaddnew-field' ) ; $ this -> addNewEnabled = true ; $ this -> sourceCallback = $ sourceCallback ; $ this -> isFrontend = $ isFrontend ; $ this -> addNewClass = $ class ; $ this -> addNewFields = $ fields ; $ this -> addNewRequiredFields = $ required ; return $ this -> owner ; }
Tell this form field to apply the add new UI and fucntionality

@param string $class - the class name of the object being managed on the relationship
@param Function $sourceCallback - the function called to repopulate the field's source array
@param FieldList $fields - Fields to create the object via dialog form - defaults to the object's getAddNewFields() method
@param RequiredFields $required - to create the validator for the dialog form
@param Boolean $isFrontend - If this is set to true, the css classes for the CMS ui will not be set of the form elements
this also opens the opportunity to manipulate the form for Frontend uses via an extension
@return FormField $this->owner
Tell this form field to apply the add new UI and fucntionality