We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28539
    • 6 Posts
    Hi All!

    Wondering if there’s a way to alter the output of the mutate actions without hacking the core (Evolution).

    I’m writing a plugin that pulls in an html/php/js/&more javascript syntax highlighter (CodeMirror) into the manager.

    So when editing templates, plugins, snippets, etc, I’ll be able to have nice syntax highlighting. So far, I’ve got this thing working for editing templates, but I’ve had to hack some core files, specifically manager/actions/mutate_templates.dynamic.php. To show nice syntax highlighting on snippets, chunks, etc, I’ll have to hack the other appropriate mutate_* files.

    I simply added an id="code" attribute to the textarea (name="post"). I needed an id to have CodeMIrror ’see’ the textarea to add its syntax highlighting.

    I was hoping to use some javascript to force the id attribute to the textarea, but didn’t have much luck. Plus, using javascript to force the id doesn’t take care of everything; I also needed to remove the call to htmlentities() for the textarea’s value, so I’m pretty sure the only way to achieve what I want is to modify the literal code in the mutate file.

    Any ideas on this one?

    If I could get this worked out, it’d make a great plugin for all to use!

    Thanks!
      • 20413
      • 2,877 Posts
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 28539
        • 6 Posts
        Well gosh golly gee.

        I’d found another post about a code syntax plugin, but it was from a few years ago and seemed to die out. Too bad I didn’t see this one before spending all that time last night at 3am! smiley

        Thanks!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The problem is that the original core files used PHP inline code in an HTML document. The forms are built line-by-line, with inline PHP getting data where needed and inserting it into the HTML. The two relevant events only trigger before the form is built and after it’s finished being built, but with no way to modify the form or the data being used in its construction.

          If all the data it would need had been gathered and organized into an array before the form was built, then the first event could have been used to manipulate the data to be used. And if the form had been loaded into a string as it was being built, then the whole string echoed or returned (like the document parser’s documentOutput string), the second event could have been used to manipulate the finished form before it was displayed.

          The way modules and plugins like ManagerManager work is to write javascript to the HTML to make changes to the DOM in the browser.
            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
            • 28539
            • 6 Posts
            Thanks for the feedback, sottwell.

            That’s pretty much the conclusion I’d reached, but I didn’t have much luck manipulating the textarea with javascript. No worries, though. I’ll try out the info from the EditArea post that mrhaw linked to.