We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44665
    • 60 Posts
    sebastian-marinescu Reply #1, 10 years, 10 months ago
    Hi MODx-Community,
    Hi Bruno,

    I'm stuck with the programmatically creation of a MIGx-Configuration.
    I'd like to be able to ship a Configuration with a package and setup the Config in a resolver.

    I tried this, but with no avail:

    $migxCfg = $modx->newObject('migxConfig');
    
    $migxCfg->fromArray(array(
        'name' => 'ConfigTest',
        'formtabs' => '[{"MIGX_id":1,"caption":"Neuer Slide","print_before_tabs":"0","fields":[{"MIGX_id":1,"field":"slideTitle","caption":"Titel","description":"","description_is_code":"0","inputTV":"","inputTVtype":"","validation":"","configs":"","restrictive_condition":"","display":"","sourceFrom":"config","sources":"","inputOptionValues":"","default":"","useDefaultIfEmpty":"0","pos":1},{"MIGX_id":2,"field":"slideText","caption":"Text","description":"","description_is_code":"0","inputTV":"","inputTVtype":"text","validation":"","configs":"","restrictive_condition":"","display":"","sourceFrom":"config","sources":"","inputOptionValues":"","default":"","useDefaultIfEmpty":"0","pos":2},{"MIGX_id":3,"field":"slideImage","caption":"Bild","description":"","description_is_code":"0","inputTV":"","inputTVtype":"image","validation":"","configs":"","restrictive_condition":"","display":"","sourceFrom":"config","sources":"[{\"MIGX_id\":1,\"context\":\"web\",\"sourceid\":2}]","inputOptionValues":"","default":"","useDefaultIfEmpty":"0","pos":3}],"pos":1}]',
        'extended' => '{"migx_add":"Neuer Slide","disable_add_item":"","add_items_directly":"","formcaption":"","update_win_title":"Neuen Slide einstellen","win_id":"","maxRecords":5,"addNewItemAt":"bottom","multiple_formtabs":"","multiple_formtabs_label":"","multiple_formtabs_field":"","multiple_formtabs_optionstext":"","multiple_formtabs_optionsvalue":"","actionbuttonsperrow":4,"winbuttonslist":"","extrahandlers":"","filtersperrow":4,"packageName":"","classname":"","task":"","getlistsort":"","getlistsortdir":"","sortconfig":"","gridpagesize":"","use_custom_prefix":"0","prefix":"","grid":"","gridload_mode":1,"check_resid":1,"check_resid_TV":"","join_alias":"","has_jointable":"yes","getlistwhere":"","joins":"","hooksnippets":"","cmpmaincaption":"","cmptabcaption":"","cmptabdescription":"","cmptabcontroller":"","winbuttons":"","onsubmitsuccess":"","submitparams":""}',
        'columns' => '[{"MIGX_id":1,"header":"Titel","dataIndex":"slideTitle","width":150,"sortable":"false","show_in_grid":1,"customrenderer":"","renderer":"","clickaction":"","selectorconfig":"","renderchunktpl":"","renderoptions":"","editor":""},{"MIGX_id":2,"header":"Text","dataIndex":"slideText","width":200,"sortable":"false","show_in_grid":1,"customrenderer":"","renderer":"","clickaction":"","selectorconfig":"","renderchunktpl":"","renderoptions":"","editor":""},{"MIGX_id":3,"header":"Bild","dataIndex":"slideImage","width":"","sortable":"false","show_in_grid":1,"customrenderer":"","renderer":"this.renderImage","clickaction":"","selectorconfig":"","renderchunktpl":"","renderoptions":"","editor":""}]',
        'contextmenus' => 'update||duplicate||remove||movetotop_migx||movetotop_bottom',
    ), '', true, true);
    $migxCfg->save();
    


    I thought because the class migxConfig extends xPDOSimpleObject I could just initiate it and add the raw fields fromArray.

    But how do I initiate a new migxConfig correctly via API?

    Thanks in advance for any answer and clue.

    With best regards,
    Sebastian

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      you don't need to import configs, you can just add the packagename to the configname like:

      yourconfig:yourpackage


      this does read the config from file instaed from db.

      Otherwise, see this processor:
      https://github.com/Bruno17/MIGX/blob/master/core/components/migx/processors/mgr/migxconfigs/importfrompackage.php

      and this function:
      https://github.com/Bruno17/MIGX/blob/master/core/components/migx/model/migx/migx.class.php#L2457
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 44665
        • 60 Posts
        sebastian-marinescu Reply #3, 10 years, 10 months ago
        Quote from: Bruno17 at Dec 04, 2015, 06:57 AM
        you don't need to import configs, you can just add the packagename to the configname like:

        yourconfig:yourpackage


        this does read the config from file instaed from db.

        This is great! Thank you very much smiley

        I've put the MIGx-JSON-Config in /core/components/packageName/migxconfigs/configName.config.js

        And added the right settings in the TV-creation on the Builder:

        $tvs[$i]= $modx->newObject('modTemplateVar');
        $tvs[$i]->fromArray(array(
            'id' => $i,
            'name' => 'slideshow',
            'caption' => 'Slideshow',
            'description' => 'MIGx Slideshow Template-Variable',
            'type' => 'migx',
            'display' => 'default',
            'locked' => 0,
            'rank' => 0,
            'default_text' => '',
            'input_properties' => 'a:7:{s:7:"configs";s:23:"configName:packageName";s:8:"formtabs";s:0:"";s:7:"columns";s:0:"";s:7:"btntext";s:0:"";s:10:"previewurl";s:0:"";s:10:"jsonvarkey";s:0:"";s:19:"autoResourceFolders";s:5:"false";}',
        ),'',true,true); $i++;


        This works perfect!
          • 4172
          • 5,888 Posts
          you can do 'export to package' on a MIGX-config
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!