public function createOptionsForms()
    {
        // construct form
        $factory = new \Zend\Form\Factory();
        $formElements = $this->getServiceLocator()->get('FormElementManager');
        $factory->setFormElementManager($formElements);
        $formConfig = $this->pluginBackConfig['modal_form'];

        $response = [];
        $render   = [];
        if (!empty($formConfig)) {
            foreach ($formConfig as $formKey => $config) {
                $form = $factory->createForm($config);
                $request = $this->getServiceLocator()->get('request');
                $parameters = $request->getQuery()->toArray();

                if (!isset($parameters['validate'])) {

                    $form->setData($this->getFormData());

                    $viewModelTab = new ViewModel();
                    $viewModelTab->setTemplate($config['tab_form_layout']);
                    $viewModelTab->modalForm = $form;
                    $viewModelTab->formData   = $this->getFormData();
                    $viewRender = $this->getServiceLocator()->get('ViewRenderer');
                    $html = $viewRender->render($viewModelTab);
                    array_push($render, [
                            'name' => $config['tab_title'],
                            'icon' => $config['tab_icon'],
                            'html' => $html
                        ]
                    );
                }
                else {

                    // validate the forms and send back an array with errors by tabs
                    $post = get_object_vars($request->getPost());
                    $success = false;
                    $form->setData($post);

                    $errors = array();
                    if ($form->isValid()) {
                        $data = $form->getData();
                        $success = true;
                        array_push($response, [
                            'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'],
                            'success' => $success,
                        ]);
                    } else {
                        $errors = $form->getMessages();

                        foreach ($errors as $keyError => $valueError) {
                            foreach ($config['elements'] as $keyForm => $valueForm) {
                                if ($valueForm['spec']['name'] == $keyError &&
                                    !empty($valueForm['spec']['options']['label'])
                                )
                                    $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                            }
                        }

                        array_push($response, [
                            'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'],
                            'success' => $success,
                            'errors' => $errors,
                            'message' => '',
                        ]);
                    }

                }
            }
        }

        if (!isset($parameters['validate'])) {
            return $render;
        }
        else {
            return $response;
        }

    }
public function createOptionsForms()
    {
        // construct form
        $factory = new \Zend\Form\Factory();
        $formElements = $this->getServiceLocator()->get('FormElementManager');
        $factory->setFormElementManager($formElements);
        $formConfig = $this->pluginBackConfig['modal_form'];

        $response = [];
        $render   = [];
        if (!empty($formConfig)) {
            foreach ($formConfig as $formKey => $config) {
                $form = $factory->createForm($config);
                $request = $this->getServiceLocator()->get('request');
                $parameters = $request->getQuery()->toArray();

                if (!isset($parameters['validate'])) {

                    $form->setData($this->getFormData());

                    $viewModelTab = new ViewModel();
                    $viewModelTab->setTemplate($config['tab_form_layout']);
                    $viewModelTab->modalForm = $form;
                    $viewModelTab->formData   = $this->getFormData();
                    $viewRender = $this->getServiceLocator()->get('ViewRenderer');
                    $html = $viewRender->render($viewModelTab);
                    array_push($render, [
                            'name' => $config['tab_title'],
                            'icon' => $config['tab_icon'],
                            'html' => $html
                        ]
                    );
                }
                else {

                    // validate the forms and send back an array with errors by tabs
                    $post = get_object_vars($request->getPost());
                    $success = false;
                    $form->setData($post);

                    $errors = array();
                    if ($form->isValid()) {
                        $data = $form->getData();
                        $success = true;
                        array_push($response, [
                            'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'],
                            'success' => $success,
                        ]);
                    } else {
                        $errors = $form->getMessages();

                        foreach ($errors as $keyError => $valueError) {
                            foreach ($config['elements'] as $keyForm => $valueForm) {
                                if ($valueForm['spec']['name'] == $keyError &&
                                    !empty($valueForm['spec']['options']['label'])
                                )
                                    $errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
                            }
                        }

                        array_push($response, [
                            'name' => $this->pluginBackConfig['modal_form'][$formKey]['tab_title'],
                            'success' => $success,
                            'errors' => $errors,
                            'message' => '',
                        ]);
                    }

                }
            }
        }

        if (!isset($parameters['validate'])) {
            return $render;
        }
        else {
            return $response;
        }

    }
public function createOptionsForms ( ) { // construct form $ factory = new \ Zend \ Form \ Factory ( ) ; $ formElements = $ this -> getServiceLocator ( ) -> get ( 'FormElementManager' ) ; $ factory -> setFormElementManager ( $ formElements ) ; $ formConfig = $ this -> pluginBackConfig [ 'modal_form' ] ; $ response = [ ] ; $ render = [ ] ; if ( ! empty ( $ formConfig ) ) { foreach ( $ formConfig as $ formKey => $ config ) { $ form = $ factory -> createForm ( $ config ) ; $ request = $ this -> getServiceLocator ( ) -> get ( 'request' ) ; $ parameters = $ request -> getQuery ( ) -> toArray ( ) ; if ( ! isset ( $ parameters [ 'validate' ] ) ) { $ form -> setData ( $ this -> getFormData ( ) ) ; $ viewModelTab = new ViewModel ( ) ; $ viewModelTab -> setTemplate ( $ config [ 'tab_form_layout' ] ) ; $ viewModelTab -> modalForm = $ form ; $ viewModelTab -> formData = $ this -> getFormData ( ) ; $ viewRender = $ this -> getServiceLocator ( ) -> get ( 'ViewRenderer' ) ; $ html = $ viewRender -> render ( $ viewModelTab ) ; array_push ( $ render , [ 'name' => $ config [ 'tab_title' ] , 'icon' => $ config [ 'tab_icon' ] , 'html' => $ html ] ) ; } else { // validate the forms and send back an array with errors by tabs $ post = get_object_vars ( $ request -> getPost ( ) ) ; $ success = false ; $ form -> setData ( $ post ) ; $ errors = array ( ) ; if ( $ form -> isValid ( ) ) { $ data = $ form -> getData ( ) ; $ success = true ; array_push ( $ response , [ 'name' => $ this -> pluginBackConfig [ 'modal_form' ] [ $ formKey ] [ 'tab_title' ] , 'success' => $ success , ] ) ; } else { $ errors = $ form -> getMessages ( ) ; foreach ( $ errors as $ keyError => $ valueError ) { foreach ( $ config [ 'elements' ] as $ keyForm => $ valueForm ) { if ( $ valueForm [ 'spec' ] [ 'name' ] == $ keyError && ! empty ( $ valueForm [ 'spec' ] [ 'options' ] [ 'label' ] ) ) $ errors [ $ keyError ] [ 'label' ] = $ valueForm [ 'spec' ] [ 'options' ] [ 'label' ] ; } } array_push ( $ response , [ 'name' => $ this -> pluginBackConfig [ 'modal_form' ] [ $ formKey ] [ 'tab_title' ] , 'success' => $ success , 'errors' => $ errors , 'message' => '' , ] ) ; } } } } if ( ! isset ( $ parameters [ 'validate' ] ) ) { return $ render ; } else { return $ response ; } }
This function generates the form displayed when editing the parameters of the plugin
@return array
This function generates the form displayed when editing the parameters of the plugin