Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilingual doesn't work correct with UserDefinedForms module #2

Open
mschilder opened this issue Jun 11, 2015 · 3 comments
Open

Multilingual doesn't work correct with UserDefinedForms module #2

mschilder opened this issue Jun 11, 2015 · 3 comments

Comments

@mschilder
Copy link

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
Copy link
Author

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
Copy link
Collaborator

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: [email protected]
Mobil: 0704 71 91 51

På 11 juni 2015 till 11:45:42, mschilder ([email protected]) 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
Copy link
Author

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: [email protected] (mailto:[email protected])
Mobil: 0704 71 91 51

På 11 juni 2015 till 11:45:42, mschilder ([email protected] (mailto:[email protected])) 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 (#2 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant