northcreation-agency / multilingual

Multilingual support for Silverstripe, an alternative way
http://www.kreationsbyran.se/blogg/multilingual-module-for-silverstripe
Other
7 stars 2 forks source link

Multilingual doesn't work correct with UserDefinedForms module #2

Open mschilder opened 9 years ago

mschilder commented 9 years ago

When using Multilingual together with UserDefinedForm module this error occurs when trying to opening the UserDefinedForm in the CMS:

[User Error] collateDataFields() I noticed that a field called 'Title_en' 
appears twice in your form: '(unknown form)'. One is a 'TextField' 
and the other is a 'TextField'

I can make the error go away by removing $this->extend('updateCMSFields', $fields); from UserForms' public function getCMSFields()

What is the best way to deal with this?

mschilder commented 9 years ago

PS. This is the full getCMSFields() from UserDefinedForm:

public function getCMSFields() {
        // call updateCMSFields after userforms 
        SiteTree::disableCMSFieldsExtensions();
        $fields = parent::getCMSFields();
        SiteTree::enableCMSFieldsExtensions();
        // define tabs
        $fields->findOrMakeTab('Root.FormContent', _t('UserDefinedForm.FORM', 'Form'));
        $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
        $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));

        // field editor
        $fields->addFieldToTab("Root.FormContent", new FieldEditor("Fields", 'Fields', "", $this ));

        // text to show on complete
        $onCompleteFieldSet = new CompositeField(
            $label = new LabelField('OnCompleteMessageLabel',_t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
            $editor = new HtmlEditorField( "OnCompleteMessage", "", _t('UserDefinedForm.ONCOMPLETEMESSAGE', $this->OnCompleteMessage))
        );

        $onCompleteFieldSet->addExtraClass('field');

        $editor->setRows(3);
        $label->addExtraClass('left');      

        // Set the summary fields of UserDefinedForm_EmailRecipient dynamically via config system
        Config::inst()->update(
            'UserDefinedForm_EmailRecipient',
            'summary_fields',
            array(
                'EmailAddress' => _t('UserDefinedForm.EMAILADDRESS', 'Email'),
                'EmailSubject' => _t('UserDefinedForm.EMAILSUBJECT', 'Subject'),
                'EmailFrom' => _t('UserDefinedForm.EMAILFROM', 'From'),
            )
        );

        // who do we email on submission
        $emailRecipients = new GridField("EmailRecipients", _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $this->EmailRecipients(), GridFieldConfig_RecordEditor::create(10));
        $emailRecipients->getConfig()->getComponentByType('GridFieldAddNewButton')->setButtonName(
            _t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
        );

        $fields->addFieldsToTab("Root.FormOptions", $onCompleteFieldSet);       
        $fields->addFieldToTab("Root.FormOptions", $emailRecipients);
        $fields->addFieldsToTab("Root.FormOptions", $this->getFormOptions());

        // view the submissions
        $submissions = new GridField(
            "Submissions", 
            _t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
             $this->Submissions()->sort('Created', 'DESC')
        );

        // make sure a numeric not a empty string is checked against this int column for SQL server
        $parentID = (!empty($this->ID)) ? $this->ID : 0;

        // get a list of all field names and values used for print and export CSV views of the GridField below.
        $columnSQL = <<<SQL
SELECT "Name", "Title"
FROM "SubmittedFormField"
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
WHERE "SubmittedForm"."ParentID" = '$parentID'
ORDER BY "Title" ASC
SQL;
        $columns = DB::query($columnSQL)->map();

        $config = new GridFieldConfig();
        $config->addComponent(new GridFieldToolbarHeader());
        $config->addComponent($sort = new GridFieldSortableHeader());
        $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
        $config->addComponent(new GridFieldDataColumns());
        $config->addComponent(new GridFieldEditButton());
        $config->addComponent(new GridState_Component());
        $config->addComponent(new GridFieldDeleteAction());
        $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
        $config->addComponent($pagination = new GridFieldPaginator(25));
        $config->addComponent(new GridFieldDetailForm());
        $config->addComponent($export = new GridFieldExportButton());
        $config->addComponent($print = new GridFieldPrintButton());

        /**
         * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
         */
        if(class_exists('GridFieldBulkManager')) {
            $config->addComponent(new GridFieldBulkManager());
        }

        $sort->setThrowExceptionOnBadDataType(false);
        $filter->setThrowExceptionOnBadDataType(false);
        $pagination->setThrowExceptionOnBadDataType(false);

        // attach every column to the print view form 
        $columns['Created'] = 'Created';
        $filter->setColumns($columns);

        // print configuration
        $print->setPrintHasHeader(true);
        $print->setPrintColumns($columns);

        // export configuration
        $export->setCsvHasHeader(true);
        $export->setExportColumns($columns);

        $submissions->setConfig($config);
        $fields->addFieldToTab("Root.Submissions", $submissions);
        $fields->addFieldToTab("Root.FormOptions", new CheckboxField('DisableSaveSubmissions',_t('UserDefinedForm.SAVESUBMISSIONS',"Disable Saving Submissions to Server")));

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }
northcreation-agency commented 9 years ago

Weird, how does the getCMSFunction in your page.php look like?

Med vänliga hälsningar Herbert Cuba Garcia  kreationsbyrån 

http://www.kreationsbyran.se/ E-post: herbert@kreationsbyran.se Mobil: 0704 71 91 51

På 11 juni 2015 till 11:45:42, mschilder (notifications@github.com) skrev:

When using Multilingual together with UserDefinedForm module this error occurs when trying to opening the UserDefinedForm in the CMS:

[User Error] collateDataFields() I noticed that a field called 'Title_en' appears twice in your form: '(unknown form)'. One is a 'TextField' and the other is a 'TextField'

I can make the error go away by removing $this->extend('updateCMSFields', $fields); from UserForms' public function getCMSFields()

What is the best way to deal with this?

— Reply to this email directly or view it on GitHub.

mschilder commented 9 years ago

Thanks, there I found the cause of this problem:

SiteTree::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); SiteTree::enableCMSFieldsExtensions();

Sorry for bringing this up!

On Thursday 11 June 2015 at 14:18, Kreationsbyrån wrote:

Weird, how does the getCMSFunction in your page.php look like?

Med vänliga hälsningar Herbert Cuba Garcia kreationsbyrån

http://www.kreationsbyran.se/ E-post: herbert@kreationsbyran.se (mailto:herbert@kreationsbyran.se) Mobil: 0704 71 91 51

På 11 juni 2015 till 11:45:42, mschilder (notifications@github.com (mailto:notifications@github.com)) skrev:

When using Multilingual together with UserDefinedForm module this error occurs when trying to opening the UserDefinedForm in the CMS:

[User Error] collateDataFields() I noticed that a field called 'Title_en' appears twice in your form: '(unknown form)'. One is a 'TextField' and the other is a 'TextField'

I can make the error go away by removing $this->extend('updateCMSFields', $fields); from UserForms' public function getCMSFields()

What is the best way to deal with this?

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub (https://github.com/kreationsbyran/multilingual/issues/2#issuecomment-111112500).