Usage - Teamsisu/contao-mm-frontendInput GitHub Wiki

To use this extension you had to create an own module with an content element. Currently only existing MetaModel Items are tested, we do not know if this extension work with new/empty MetaModel Items, if you got any information's about that please create a ticket.

tl_content.php

Use the existing mmfi palette to enhance your own content element

$GLOBALS['TL_DCA']['tl_content']['palettes']['myContentElement'] = '{type_legend},type;'.$GLOBALS['TL_DCA']['tl_content']['palettes']['mmfi'];

MyContentElementClass

This is my personal CTE compile function which creates the form, bind an existing item and save it if the form is valid

    /**
     * Compile the current element
     */
    protected function compile()
    {

        /**
         * Set upload Path for FileUploads
         */
        $uploadPath = $this->mmfi_uploadPath;

        // override if memberhome is set
        if($this->mmfi_useMemberHome && FE_USER_LOGGED_IN){
            $objUser = FrontendUser::getInstance();
            if($objUser->assignDir && $objUser->homeDir){
                $uploadPath = $objUser->homeDir;
            }
        }

        /**
         * Load Metamodels InputScreen
         */
        $inputMaskProvider = new InputMaskProvider($this->mmfi_metamodel_id, $this->mmfi_inputMask_id, $uploadPath);


        $MetaModel = Factory::byId($this->mmfi_metamodel_id);
        $mmItem = $MetaModel->findById(3); // change this code to match your personal usage

        // check if item is not null
        if($mmItem){
            $inputMaskProvider->setItem($mmItem);
        }

        $inputMaskProvider->parseFields();

        /**
         * Instantiate Haste Form
         */
        $hasteForm = new \Haste\Form\Form('baseInformations', 'POST', function($objHaste) { //instead of "baseInformations" you could use any form identifier string you like
            return \Input::post('FORM_SUBMIT') === $objHaste->getFormId();
        });

        /**
         * Add Contao hidden fields
         */
        $hasteForm->addContaoHiddenFields();

        /**
         * Add Form Fields
         */
        $inputMaskProvider->addFieldsToForm($hasteForm);
        $hasteForm->addSubmitFormField('submit', 'Submit form');

        if($hasteForm->isSubmitted()){

            $hasteForm->validate();

            if($hasteForm->isValid()){
                $inputMaskProvider->bindFormToItem($hasteForm);
                $mmItem->save();

                $inputMaskProvider->loadValues(); // reload values from MM Item
                $inputMaskProvider->addFieldsToForm($hasteForm); // overwrite the existing fields again
            }

        }

        /**
         * Alternatively, you can pass it to any other object
         */
        $objForm = new \stdClass();
        $hasteForm->setNoValidate($this->mmfi_noHtmlValidation);
        $hasteForm->addToObject($objForm);
        $this->Template->Form = $objForm;

    }

That's it.

Here is an Template example

https://gist.github.com/MrTool/9567c0cd6f0ac663e96a

Tested fields

  • Text
  • Select
  • File
  • Tags
  • Url