Get related Form instance or create it

@param   bool|Form
@return  Form
12933
public function form($instance = true)
	{
		if ($instance instanceof Form)
		{
			$this->form = $instance;
			return $instance;
		}

		if (empty($this->form) and $instance === true)
		{
			$this->form = \Form::forge($this);
		}

		return $this->form;
	}
367358
protected function getAutoSearchForm()
    {
        $data = $this->getSearchData();
        // \MUtil_Echo::track($data);

        $this->form = $form = $this->createForm(array('name' => 'autosubmit', 'class' => 'form-inline', 'role' => 'form'));

        $elements = $this->getAutoSearchElements($data);

        if ($elements) {
            // Assign a name so autosubmit will only work on this form (when there are others)
            $form->setHtml('div');
            $div = $form->getHtml();
            $div->class = 'search';

            $span = $div->div(array('class' => 'panel panel-default'))->div(array('class' => 'inputgroup panel-body'));

            $elements[] = $this->getAutoSearchSubmit();

            if ($reset = $this->getAutoSearchReset()) {
                $elements[] = $reset;
            }

            $prev = null;
            foreach (\MUtil_Ra::flatten($elements) as $element) {
                if ($element instanceof \Zend_Form_Element) {
                    $appendLabel = false;
                    if ($element->getLabel()) {
                        $labelDecor = $element->getDecorator('Label');

                        if ($labelDecor) {
                            $appendLabel = \Zend_Form_Decorator_Abstract::APPEND === $labelDecor->getPlacement();

                            if (! $appendLabel) {
                                $span->label($element);
                            }
                        }
                    }
                    $span->input($element);
                    if ($appendLabel) {
                        $span->label($element);
                    }
                    // TODO: Elementen automatisch toevoegen in \MUtil_Form
                    $form->addElement($element);
                } elseif (null === $element && $prev !== null) {
                    $span = $div->div(array('class' => 'panel panel-default'))->div(array('class' => 'inputgroup panel-body'));
                } else {
                    $span[] = $element;
                }
                $prev = $element;
            }

            // \MUtil_Echo::track($data);
            if ($this->request->isPost()) {
                if (! $form->isValid($data)) {
                    $this->addMessage($form->getErrorMessages());
                    $this->addMessage($form->getMessages());
                }
            } else {
                $form->populate($data);
            }

            if ($this->containingId) {
                $href = $this->getAutoSearchHref();
                if ($href) {
                    $form->setAutoSubmit($href, $this->containingId);
                }
            }

            return $form;
        }
    }
1138367
public function formProperty()
    {
        if ($this->formProperty === null) {
            $this->formProperty = false;

            if ($this->objType() && $this->propertyIdent()) {
                $propertyIdent = $this->propertyIdent();

                $model = $this->modelFactory()->create($this->objType());
                $props = $model->metadata()->properties();

                if (isset($props[$propertyIdent])) {
                    $propertyMetadata = $props[$propertyIdent];

                    $property = $this->propertyFactory()->create($propertyMetadata['type']);

                    $property->setIdent($propertyIdent);
                    $property->setData($propertyMetadata);

                    $this->formProperty = $property;
                }
            }
        }

        return $this->formProperty;
    }
480093
public function Form()
    {
        $form = new Form(
            $this,
            'SilverStripe\\Forms\\Form',
            new FieldList($root = new TabSet('Root', new Tab('Main'))),
            new FieldList()
        );

        if ($this->getTopLevelController() instanceof LeftAndMain) {
            $form->setTemplate('LeftAndMain_EditForm');
            $form->addExtraClass('cms-content cms-edit-form cms-tabset center');
            $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');

            $root->setTemplate('CMSTabSet');
            $form->Backlink = $this->getBackLink();
        }

        return $form;
    }
104767
def get_form(self, key, form_class=None):
        
        if form_class is None:
            form_class = self.get_form_class(key)
        return form_class(**self.get_form_kwargs(key))
918628
public function SearchForm()
    {
        $searchText = $this->owner->getRequest()->getVar('Search');

        $fields = FieldList::create(
            TextField::create('Search', false, $searchText)
        );
        $actions = FieldList::create(
            FormAction::create('results', _t('SilverStripe\\CMS\\Search\\SearchForm.GO', 'Go'))
        );

        $form = SearchForm::create($this->owner, SearchForm::class, $fields, $actions);
        $form->setFormAction('search/SearchForm');

        return $form;
    }
1220083
def get_form(self, request, obj=None, **kwargs):
        
        defaults = {}
        if obj is None:
            defaults['form'] = self.add_form
        defaults.update(kwargs)
        return super(SettingsAdmin, self).get_form(request, obj, **defaults)
360500
public function CartForm()
    {   
        $form = Form::create(
            $this,
            "CartForm",
            FieldList::create(),
            FieldList::create(
                FormAction::create(
                    'doUpdate',
                    _t('ShoppingCart.UpdateCart', 'Update Cart')
                )->addExtraClass('btn btn-info')
            )
        )->setTemplate("SilverCommerce\ShoppingCart\Forms\Includes\ShoppingCartForm");
        
        $this->extend("updateCartForm", $form);
        
        return $form;
    }
127616
public function createForm(bool $edit = false)
    {
        $form = [
            'storageURL' => route('admin.api.regions.streets'),
            'buttons'    => [
                [
                    "class" => "col-centered",
                    "label" => trans('HCTranslations::core.buttons.submit'),
                    "type"  => "submit",
                ],
            ],
            'structure'  => [
                [
                    "type"            => "dropDownList",
                    "fieldID"         => "country_id",
                    "label"           => trans("HCRegions::regions_municipalities.country_id"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                    "options"         => HCCountries::select('id', 'translation_key')->get(),
                    "search"          => [
                        "maximumSelectionLength" => 1,
                        "minimumSelectionLength" => 1,
                        "showNodes"              => ["translation"]
                    ]
                ],
                [
                    "type"            => "dropDownList",
                    "fieldID"         => "municipality_id",
                    "label"           => trans("HCRegions::regions.municipality"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                    "search"          => [
                        "maximumSelectionLength" => 1,
                        "minimumSelectionLength" => 1,
                        "showNodes"              => ["translation"]
                    ],
                    "dependencies"    => [
                        [
                            "field_id"    => "country_id",
                            "options_url" => route('admin.api.regions.municipalities.list'),
                        ],
                    ],
                ],
                [
                    "type"            => "dropDownList",
                    "fieldID"         => "city_id",
                    "label"           => trans("HCRegions::regions.cities"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                    "search"          => [
                        "maximumSelectionLength" => 1,
                        "minimumSelectionLength" => 1,
                        "showNodes"              => ["name"]
                    ],
                    "dependencies"    => [
                        [
                            "field_id"    => "municipality_id",
                            "options_url" => route('admin.api.regions.cities.list'),
                        ],
                    ],
                ],
                [
                    "type"            => "dropDownList",
                    "fieldID"         => "city_parts",
                    "label"           => trans("HCRegions::regions.parts"),
                    "required"        => 0,
                    "requiredVisible" => 0,
                    "search"          => [
                        "showNodes" => ["name"]
                    ],
                    "dependencies"    => [
                        [
                            "field_id"    => "city_id",
                            "options_url" => route('admin.api.regions.parts.list'),
                        ],
                    ],
                ],
                [
                    "type"            => "singleLine",
                    "fieldID"         => "name",
                    "label"           => trans("HCRegions::regions_streets.name"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                    "dependencies"    => [
                        [
                            "field_id" => "country_id",
                        ],
                        [
                            "field_id" => "municipality_id",
                        ],
                        [
                            "field_id" => "city_id",
                        ],
                    ],
                ],
            ],
        ];

        if ($this->multiLanguage)
            $form['availableLanguages'] = []; //TOTO implement honeycomb-languages package

        if (!$edit)
            return $form;

        //Make changes to edit form if needed
        // $form['structure'][] = [];

        return $form;
    }
1019977
public function setForm(Form $form)
	{
		$this->form = $form;
		$this->formControl = $form->getFormControl();

		return $this;
	}
90119
public function createForm(bool $edit = false): array
    {
        $form = [
            'storageUrl' => route('admin.api.regions.continents'),
            'buttons' => [
                'submit' => [
                    'label' => $this->getSubmitLabel($edit),
                ],
            ],
            'structure' => $this->getStructure($edit),
        ];

        if ($this->multiLanguage) {
            $form['availableLanguages'] = getHCContentLanguages();
        }

        return $form;
    }
406009
async def get_form(self, request):
        """"""
        if not self.form:
            return None
        formdata = await request.post()
        return self.form(formdata, obj=self.resource)
356670
public function Form()
    {
        if ($this->currentRecord) {
            $fields = $this->currentRecord->getFrontEndFields();
            $required = $this->currentRecord->getRequiredFields();
        } else {
            $fields = singleton($this->recordType)->getFrontEndFields();
            $required = singleton($this->recordType)->getFrontEndFields();
        }

        $fields->push(new HiddenField('ID'));
        $form = new Form($this, __function__, $fields, new FieldList(new FormAction('doSave', 'Save')), $required);
        if ($this->currentRecord) {
            $form->loadDataFrom($this->currentRecord);
        }
        return $form;
    }
216185
public function form($form = null)
    {
        if (func_num_args() === 1) {
            $form = $form ?: [];
            $this->_form = $form;
            $this->set($form);
            return $this;
        }
        return $this->_form;
    }
333207
public function createForm(bool $edit = false)
    {
        $this->getRolesForUserCreation();

        $rolesStructure = [
            "type"            => 'checkBoxList',
            "fieldID"         => 'roles',
            "tabID"           => trans('HCACL::users.roles'),
            "label"           => trans("HCACL::users.role_groups"),
            "required"        => 1,
            "requiredVisible" => 1,
            "options"         => $this->getRolesForUserCreation(),
        ];

        $form = [
            'storageURL' => route('admin.api.users'),
            'buttons'    => [
                [
                    "class" => "col-centered",
                    "label" => trans('HCTranslations::core.buttons.submit'),
                    "type"  => "submit",
                ],
            ],
            'structure'  => [
                [
                    "type"            => "email",
                    "fieldID"         => "email",
                    "tabID"           => trans('HCTranslations::core.general'),
                    "label"           => trans("HCACL::users.email"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                ],
                [
                    "type"            => "password",
                    "fieldID"         => "password",
                    "tabID"           => trans('HCTranslations::core.general'),
                    "label"           => trans("HCACL::users.register.password"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                ],
                formManagerYesNo('checkBoxList', 'is_active', trans("HCACL::users.active"), 0, 0, trans('HCTranslations::core.general'), false),
                formManagerYesNo('checkBoxList', 'send_welcome_email', trans("HCACL::users.send_welcome_email"), 0, 0, trans('HCTranslations::core.general'), false),
                formManagerYesNo('checkBoxList', 'send_password', trans("HCACL::users.send_password"), 0, 0, trans('HCTranslations::core.general'), false),
                $rolesStructure
            ],
        ];

        if( $this->multiLanguage )
            $form['availableLanguages'] = []; //TOTO implement honeycomb-languages package

        if( ! $edit )
            return $form;

        //Make changes to edit form if needed

        $form['structure'] = [];

        $form['structure'] = array_merge($form['structure'], [
            [
                "type"            => "email",
                "fieldID"         => "email",
                "tabID"           => trans('HCTranslations::core.general'),
                "label"           => trans("HCACL::users.email"),
                "required"        => 1,
                "requiredVisible" => 1,
            ],
            [
                "type"            => "password",
                "fieldID"         => "old_password",
                "tabID"           => trans('HCTranslations::core.general'),
                "label"           => trans('HCACL::users.passwords.old'),
                "editType"        => 0,
                "required"        => 0,
                "requiredVisible" => 0,
                "properties"      => [
                    "strength" => "1" // case 0: much, case 1: 4 symbols, case 2: 6 symbols
                ],
            ],
            [
                "type"            => "password",
                "fieldID"         => "password",
                "tabID"           => trans('HCTranslations::core.general'),
                "label"           => trans('HCACL::users.passwords.new'),
                "editType"        => 0,
                "required"        => 0,
                "requiredVisible" => 0,
                "properties"      => [
                    "strength" => "1" // case 0: much, case 1: 4 symbols, case 2: 6 symbols
                ],
            ],
            [
                "type"            => "password",
                "fieldID"         => "password_confirmation",
                "tabID"           => trans('HCTranslations::core.general'),
                "label"           => trans('HCACL::users.passwords.new_again'),
                "editType"        => 0,
                "required"        => 0,
                "requiredVisible" => 0,
                "properties"      => [
                    "strength" => "1" // case 0: much, case 1: 4 symbols, case 2: 6 symbols
                ],
            ],
            formManagerYesNo('checkBoxList', 'is_active', trans("HCACL::users.active"), 0, 0, trans('HCTranslations::core.general'), false),
            $rolesStructure,
            [
                "type"            => "singleLine",
                "fieldID"         => "last_login",
                "tabID"           => trans('HCACL::users.activity'),
                "label"           => trans("HCACL::users.last_login"),
                "required"        => 0,
                "requiredVisible" => 0,
                "readonly"        => 1,
            ],
            [
                "type"            => "singleLine",
                "fieldID"         => "last_activity",
                "tabID"           => trans('HCACL::users.activity'),
                "label"           => trans("HCACL::users.last_activity"),
                "required"        => 0,
                "requiredVisible" => 0,
                "readonly"        => 1,
            ],
            [
                "type"            => "singleLine",
                "fieldID"         => "activated_at",
                "tabID"           => trans('HCACL::users.activity'),
                "label"           => trans("HCACL::users.activation.activated_at"),
                "required"        => 0,
                "requiredVisible" => 0,
                "readonly"        => 1,
            ],
        ]);

        return $form;
    }
227535
public function CartForm()
    {
        $fields = new FieldList();

        $actions = new FieldList(
            FormAction::create('doUpdate', _t('Checkout.UpdateCart', 'Update Cart'))
                ->addExtraClass('btn')
                ->addExtraClass('btn-blue btn-info')
        );

        $form = Form::create($this, "CartForm", $fields, $actions)
            ->addExtraClass("forms")
            ->setTemplate("ShoppingCartForm");

        $this->extend("updateCartForm", $form);

        return $form;
    }
280189
def get_form(self, form_class):
        """"""
        kwargs = self.kwargs
        kwargs.update(self.get_form_kwargs())
        kwargs.update({
            'request': self.request,
            'next_view': WidgetCreateView
        })
        return form_class(**kwargs)