Creating form

@param bool $edit
@return array
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;
    }
554633
public static function config_set_edit_form_data(moodleform $editform, array $config) {
        $data = array();
        if (!empty($config['servers'])) {
            $servers = array();
            foreach ($config['servers'] as $server) {
                $servers[] = join(":", $server);
            }
            $data['servers'] = join("\n", $servers);
        }
        if (isset($config['compression'])) {
            $data['compression'] = (bool)$config['compression'];
        }
        if (!empty($config['serialiser'])) {
            $data['serialiser'] = $config['serialiser'];
        }
        if (!empty($config['prefix'])) {
            $data['prefix'] = $config['prefix'];
        }
        if (!empty($config['hash'])) {
            $data['hash'] = $config['hash'];
        }
        if (isset($config['bufferwrites'])) {
            $data['bufferwrites'] = (bool)$config['bufferwrites'];
        }
        if (isset($config['clustered'])) {
            $data['clustered'] = (bool)$config['clustered'];
        }
        if (!empty($config['setservers'])) {
            $servers = array();
            foreach ($config['setservers'] as $server) {
                $servers[] = join(":", $server);
            }
            $data['setservers'] = join("\n", $servers);
        }
        if (isset($config['isshared'])) {
            $data['isshared'] = $config['isshared'];
        }
        $editform->set_data($data);
    }
1187120
private function getFieldsForEdit() {
        global $editors, $field_editors, $translator;
        
        if ($this->fields_def) return;
		
		ob_start();
        
        $fields = $this->objectDefinition->getFields($this->catalog);
        
        $this->fields_def = array();   
        
        foreach ($fields as $id => $f) {         

            if (!$f['shw'] &&  $f['name'] != 'alias') continue;
    
            $this->fields_def[$id] = $f;
          
        	$_editor = (int)$f['editor'];
          
        	if ($f['pseudo_type']) 
                $f['type'] = $f['pseudo_type'];
              
        	if (isset($editors[EDITOR_HIDDEN])) 
                $this->fields_def[$id]['editor_str'] = $editors[EDITOR_HIDDEN];
              
        	if (is_array($field_editors[$f['type']])) {
          
        	    if (!in_array($_editor, $field_editors[$f['type']])) 
        			   $_editor = $field_editors[$f['type']][0];
                 
        		  if ($_editor == EDITOR_USER) {
        		      if (file_exists(PLUGIN_MATH_DIR.'/'.$f['editor_user'].'.php')) {
        				      $this->fields_def[$id]['editor_str'] = $f['editor_user'];
        				      include_once(PLUGIN_MATH_DIR.'/'.$f['editor_user'].'.php');	        
        		      } 
					  else {
						  $_editor = $field_editors[$f['type']][0];
					  }
        	    }
        
            	if ( isset($editors[$_editor]) ) {
            	    $this->fields_def[$id]['editor_str'] = $editors[$_editor];
            	    if ( file_exists('editors/'.$editors[$_editor].'.php') ) 
                        include_once('editors/'.$this->fields_def[$id]['editor_str'].'.php');
            	}
        	}
        }
		
		$this->initData = ob_get_contents();
		ob_end_clean();		
    }
828557
public function form()
    {
        $userModel = config('admin.database.users_model');
        $permissionModel = config('admin.database.permissions_model');
        $roleModel = config('admin.database.roles_model');

        $form = new Form(new $userModel());

        $form->display('id', 'ID');

        if (request()->isMethod('POST')) {
            $userTable = config('admin.database.users_table');
            $userNameRules = "required|unique:{$userTable}";
        } else {
            $userNameRules = 'required';
        }

        $form->text('username', trans('admin.username'))->rules($userNameRules);
        $form->text('name', trans('admin.name'))->rules('required');
        $form->image('avatar', trans('admin.avatar'));
        $form->password('password', trans('admin.password'))->rules('required|confirmed');
        $form->password('password_confirmation', trans('admin.password_confirmation'))->rules('required')
            ->default(function ($form) {
                return $form->model()->password;
            });

        $form->ignore(['password_confirmation']);

        $form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'));
        $form->multipleSelect('permissions', trans('admin.permissions'))->options($permissionModel::all()->pluck('name', 'id'));

        $form->display('created_at', trans('admin.created_at'));
        $form->display('updated_at', trans('admin.updated_at'));

        $form->saving(function (Form $form) {
            if ($form->password && $form->model()->password != $form->password) {
                $form->password = bcrypt($form->password);
            }
        });

        return $form;
    }
343193
private function getActionFormData()
    {
        $request    = oxNew(Request::class);
        $formData   = $request->getRequestEscapedParameter("editval");
        $formData   = $this->normalizeActionFormData($formData);

        return $formData;
    }
762069
public function save($item, bool $update = false)
    {
        return Craft::$app->sections->saveEntryType($item);
    }
292989
private function get_edit_options() {
        $editoroptions = array(
            'noclean' => false,
            'maxfiles' => EDITOR_UNLIMITED_FILES,
            'maxbytes' => $this->assignment->get_course()->maxbytes,
            'context' => $this->assignment->get_context(),
            'return_types' => (FILE_INTERNAL | FILE_EXTERNAL | FILE_CONTROLLED_LINK),
            'removeorphaneddrafts' => true // Whether or not to remove any draft files which aren't referenced in the text.
        );
        return $editoroptions;
    }
1301637
public function getEditableControl()
    {
        if ($this->editableControl === NULL) {
            $this->editableControl = new \Nette\Forms\Controls\TextInput;
            $this->editableControl->controlPrototype->class[] = 'form-control';
        }

        return $this->editableControl;
    }
120882
public static function create_from_submission(\assign $assign, \stdClass $submission, $editable) {
        global $USER;

        $data = array(
            'context' => $assign->get_context(),
            'objectid' => $submission->id,
            'other' => array(
                'submission_editable' => $editable,
            ),
        );
        if (!empty($submission->userid) && ($submission->userid != $USER->id)) {
            $data['relateduserid'] = $submission->userid;
        }
        /** @var assessable_submitted $event */
        $event = self::create($data);
        $event->set_assign($assign);
        $event->add_record_snapshot('assign_submission', $submission);
        return $event;
    }
403149
public function optionForm()
    {
        $fields = [];
        $default = $this->defaultInstallOptions();

        $fields[] = (new BooleanField('site', 'Setup Drupal site options?'))
            ->setDefault(false)
            ->setSubform(function ($subform, $value) use ($default) {
                if ($value === true) {
                    $subform->addFields([
                        (new TextField('name', 'Drupal site name?'))
                            ->setDefault($default['site']['name']),
                        (new TextField('profile', 'Drupal site profile?'))
                            ->setDefault($default['site']['profile']),
                    ]);
                }
            });

        $fields[] = (new BooleanField('account', 'Setup Drupal account options?'))
            ->setDefault(false)
            ->setSubform(function ($subform, $value) use ($default) {
                if ($value === true) {
                    $subform->addFields([
                        (new TextField('mail', 'Account email:'))
                            ->setDefault($default['account']['mail']),
                        (new TextField('name', 'Account username:'))
                            ->setDefault($default['account']['name']),
                        (new TextField('pass', 'Account password:'))
                            ->setHidden(true)
                            ->setDefault($default['account']['pass']),
                    ]);
                }
            });

        return (new Form())
            ->addFields($fields);
    }
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;
	}
20940
protected function createActivationForm(): FormInterface
    {
        return $this->createFormBuilder(null, ['translation_domain' => 'ngsite_user'])
            ->add(
                'email',
                EmailType::class,
                [
                    'constraints' => [
                        new Constraints\Email(),
                        new Constraints\NotBlank(),
                    ],
                ]
            )->getForm();
    }
649931
public function output_edit_form( $post ) {
		$params = $this->get_edit_form_params( $post );
		$this->before_output_edit_form( $post, $params );
		$this->add_style_view( 'admin/style/custom_post', $params );
		$this->add_style_view( 'admin/style/custom_post/' . $this->get_post_type_slug(), $params );
		$this->add_script_view( 'admin/script/custom_post', $params );
		$this->add_script_view( 'admin/script/custom_post/' . $this->get_post_type_slug(), $params );
		if ( ! $this->get_view( 'admin/custom_post/' . $this->get_post_type_slug(), $params, true, false ) ) {
			$columns = $this->app->utility->array_pluck( $params['columns'], 'is_user_defined' );
			unset( $columns['post_id'] );
			if ( ! empty( array_filter( $columns ) ) ) {
				$this->get_view( 'admin/custom_post', $params, true, false );
			}
		}
		$this->after_output_edit_form( $post, $params );
	}
269045
public function createForm (bool $edit = false)
    {
        $users = HCUsers::get();

        $form = [
            'storageURL' => route ('admin.api.routes.users.groups'),
            'buttons'    => [
                [
                    "class" => "col-centered",
                    "label" => trans ('HCTranslations::core.buttons.submit'),
                    "type"  => "submit",
                ],
            ],
            'structure'  => [
                [
                    "type"            => "singleLine",
                    "fieldID"         => "label",
                    "label"           => trans ("HCACL::users_groups.label"),
                    "required"        => 1,
                    "requiredVisible" => 1,
                ],
                [
                    "type"            => "dropDownList",
                    "fieldID"         => "users",
                    "label"           => trans ("HCACL::users_groups.users"),
                    "required"        => 0,
                    "requiredVisible" => 0,
                    "options"         => $users,
                    "search"          => [
                        "showNodes" => ['email']
                    ]
                ],
            ],
        ];

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

        if (!$edit)
            return $form;

        //Make changes to edit form if needed
        $form['structure'][] = [
            "type"            => "dropDownList",
            "fieldID"         => "creator_id",
            "label"           => trans ("HCACL::users_groups.creator_id"),
            "readonly"        => 1,
            "requiredVisible" => 1,
            "options"         => $users,
            "search"          => [
                "maximumSelectionLength" => 1,
                "minimumSelectionLength" => 1,
                "showNodes" => ['email']
            ]
        ];

        return $form;
    }
930465
public static function config_set_edit_form_data(moodleform $editform, array $config) {
        $data = array();
        if (!empty($config['path'])) {
            $data['path'] = $config['path'];
        }
        if (isset($config['autocreate'])) {
            $data['autocreate'] = (bool)$config['autocreate'];
        }
        if (isset($config['singledirectory'])) {
            $data['singledirectory'] = (bool)$config['singledirectory'];
        }
        if (isset($config['prescan'])) {
            $data['prescan'] = (bool)$config['prescan'];
        }
        $editform->set_data($data);
    }
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;
    }
534836
public static function config_set_edit_form_data(moodleform $editform, array $config) {
        $data = array();
        if (!empty($config['server'])) {
            $data['server'] = $config['server'];
        }
        if (!empty($config['database'])) {
            $data['database'] = $config['database'];
        }
        if (isset($config['extendedmode'])) {
            $data['extendedmode'] = (bool)$config['extendedmode'];
        }
        if (!empty($config['username'])) {
            $data['username'] = $config['username'];
        }
        if (!empty($config['password'])) {
            $data['password'] = $config['password'];
        }
        if (!empty($config['replicaset'])) {
            $data['replicaset'] = $config['replicaset'];
        }
        if (isset($config['usesafevalue'])) {
            $data['usesafe'] = true;
            $data['usesafevalue'] = (int)$data['usesafe'];
        } else if (isset($config['usesafe'])) {
            $data['usesafe'] = (bool)$config['usesafe'];
        }
        $editform->set_data($data);
    }