We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37743
    • 49 Posts
    I'm currently working on a custom resource class (Revo 2.2+). The work-in-progress source is held on github


    I have extended the modResource class to return different values for text fields (pagetitle, introtext, content etc) depending on the language specified by the request. This means that a single resource/node can provide information in multiple languages, without having to worry about separate trees and contexts.

    The content retrieval seems to be working fine, but I'm struggling somewhat connecting the Ext interface to a php processor for saving the amended data.

    Are there any ModExt ninjas out there who can point me in the right direction to hook up an extra database update when saving a resource?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Hey Alan,

      I think you're asking a few things here.

      First of all updating the database should be done in your processors. CRCs allow you to override any or all methods in the new class-based processors, and it's explained/showed here: http://rtfm.modx.com/display/revolution20/Creating+a+Resource+Class+-+Step+4
      There's not much in depth docs yet, but I'd advise to just open the resource update/create processor and see what it does, and what you would need to customize for your needs.

      I think the second thing you're asking is how to change the fields in the Ext JS, which again really is just overriding methods. You'll need to register your own JS which takes the MODx.panel.Resource object, extends for example its getFields method and throws that into the page instead of the generic resource one. I've done some fiddling with this myself on a pet project, and while I do have it working this is not code that I am comfortable about sharing publicly (both to avoid people possibly mimicking my fooling around, and as this is to some extent bespoke work), but if you're really stuck and need some points do add me on skype or Google Talk and I'll see if I can help you out.

      Back in Evo I did two sites with YAMS which really made sense (but was clunky / needed more work), and you really seem to be on the right track with something here.

      Of course Shaun's Articles is a great example as well, though it does completely change things around which was (for me) confusing in the beginning.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 37743
        • 49 Posts
        Mark, thanks for the advice. After trolling through all the related processors and controllers I've managed to hook the extra fields into the resource save process.

        The resource type is now functional, and so very nearly ready for a beta release. The last hurdle to overcome is a rogue javascript error that fires when the resource is saved, crashing the interface. The new data is saved to the database, so the error must come on the return of the ajax request. Unfortunately chrome's dev tools don't seem to be able to narrow it down at all. Any suggestions on ways to debug the Ext environment?

        The specific error is
        Uncaught SyntaxError: Invalid regular expression: missing /
        (although out of context i'm sure it's not much help!)
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Glad you managed to get it sorted out so far smiley

          When working with ExtJS I tend to use Firefox + Firebug myself, that's just so much superior in terms of debugging complex javascript. I do use Chrome for most regular browsing / web dev smiley

          As you say, out of context I have no idea where that error would come from. As a quick look on your code, I would advise to extend the resource update panel (widget) instead of completely recreating it like you are doing now (you can register it as the same xtype), so you don't have to hardwire all existing fields you are keeping in place, but can just have those methods inherited. Eg getMainLeftFields: https://github.com/alanpich/modTranslatedDocument/blob/master/assets/components/translations/js/mgr/widgets/modx.panel.resource.js#L403
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 37743
            • 49 Posts
            OK this javascript error is still giving me nightmares... The database update works fine, so the processor is sound, but the error is thrown when the response is returned (i think). Somehow a random '</p>' is included INSIDE the json response string?!

            My custom processor doesnt even overwrite the process function, so I'm stumped as to where it comes from... has anyone come across this before, or could hazard a guess to what might be causing it?

            See below for screenshot of error in firebug. Source code on github https://github.com/alanpich/modTranslatedDocument

              • 40804
              • 7 Posts
              plantwebdesign Reply #6, 14 years ago
              Hi Alan.

              Did you ever get to the bottom of this error message? I am working a custom CMP element just now and am receiving the same message. Trying to suss out where the issue is coming from...

              Thanks,

              Pete
                • 40804
                • 7 Posts
                plantwebdesign Reply #7, 14 years ago
                I have worked out that my issue is actually to do with a tinymce textarea xtype I am using. Just need to suss out what is going wrong...