We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    How can I insert and display another field into the resource editing forms?

    Static elements have a layout item for selecting a Media Source.
                       xtype: 'modx-combo-source'
                            ,fieldLabel: _('static_source')
                            ,description: MODx.expandHelp ? '' : _('static_source_msg')
                            ,name: 'source'
                            ,id: 'modx-chunk-static-source'
                            ,anchor: '100%'
                            ,maxLength: 255
                            ,value: config.record.source != null ? config.record.source : MODx.config.default_media_source
                            ,hidden: !config.record['static']
                            ,hideMode: 'offsets'
                            ,baseParams: {
                                action: 'getList'
                                ,showNone: true
                                ,streamsOnly: true
                            }


    I'm attempting to insert this item into the Static Resource panel widget. I can in fact insert it, and it is in the source (as viewed with Firebug) but it does not display in the browser.

    Files involved:
    manager/assets/modext/widgets/element/modx.panel.chunk.js - around line 166
    manager/assets/modext/widgets/resource/modx.panel.resource.static.js - around line 35
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Ok, maybe more information will shake loose some ideas.

      What I'm trying to do is have the Static Resource editing page be like the element editing page, when the "static" box is checked. The form is already modified when the resource's type is changed to modStaticResource (modx.panel.resource.static.js), I just need to change it more. Instead of simply turning the content's textarea field into a text field with a button to open the file browser, I want a Static Resource to have the two extra fields, "source" and "static_file". Or to start with, just to add the "source" field with a select drop-down to select the media source.

      I'm not concerning myself with the content field at this point, later it will need to be able to read and write to the source+static_file path (again, as static elements do). Getting data in and out of the database or a file either for the form or for use in the request processor is trivial. My concern at this point is getting the fields into the form past ExtJS and Smarty in the first place.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        If you look at the ClassExtender package, there's code to modify the Create/Edit Resource form (as well as the Create/Edit User form).

        You do it with a plugin attached to OnDocFormPrerender, IIRC. The trick in your case will be to make it happen only for Static Resources. You should be able to check the action ID in the plugin for that.

        I'm just suggesting ClassExtender for the example code, but if you're going to create extra fields, it might make sense to actually extend modResource and use a custom table for the extra fields.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Yeah, I thought it was interesting that your ClassExtender came along just now.

          However, my intent is to actually provide a patch to the core to build this in - including adding the two extra fields and modifying the build scripts and setup to include them. In a discussion I had last year in Cologne with some of the people who worked on static elements, they were surprised that static resources didn't work the same way. Apparently nobody ever got around to dealing with it. I'm good with the form processors and with the request processors. The holdup is figuring out how to modify the Manager forms themselves to work more like the forms for static elements. Except since modStaticResource has its own panel widget, it should be easier than the checkbox to trigger the show/hide business that static elements go through. This Smarty/ExtJS <expletive deleted> was at least half the reason why I avoided working with Revo for so many years.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4172
            • 5,888 Posts
            this seems to work
            https://github.com/Bruno17/revolution/commit/d5550e59f2efec25b8bf4cead0a7bf5eac813abd

            the secret was

            ,hidden: config.record.class_key != 'modStaticResource'
            [ed. note: Bruno17 last edited this post 12 years, 5 months ago.]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Aha! Thank you! That line was the problem.

              Since I'm only modifying the modx.panel.resource.static.js code, I think that line actually isn't even needed, since it's only used for static resources.

              One giant step towards my final goal of having static resources add the two fields, one for the media source and one for the path, as static elements do, instead of just (sloppy!) using the content for the path to the file.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org