We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6316
    • 92 Posts
    I’m sorry in advance for a noob question, but I failed to find the answer in the search.

    I have a plugin in mind which would automate some routine things my managers tend to forget.

    How do I set the variable [’richtext’] of a document to 0 in such plugin?

    global $content;
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnBeforeDocFormSave':
      if ($content['parent'] == 32)
      {
        $content['richtext'] = 0;
      }
      break;
    
      default:
        return;
        break;
    }


    Thank you!
      • 6316
      • 92 Posts
      Thanks for the reply Bob, but unfortunately it didn’t work sad
        • 3749
        • 24,544 Posts
        Sorry, I was thinking snippet rather than plugin.

        It may take someone with more plugin experience to answer this.
          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
          • 10449
          • 956 Posts
          Just add a regular mysql query to update the site_content table. I don’t think there’s an API shortcut for setting richtext on/off.

          $table = $modx->db->config['table_prefix'] . 'site_content';
          mysql_query("UPDATE $table SET richtext=0 WHERE id='$id'");
          


          $content[’richtext’] is just a value you got OUT of the database (i.e. read-only). If you change this array item, it won’t change the actual database record.
            • 26903
            • 1,336 Posts
            Without looking, isn’t the current doc id passed to the plugin in the triggering event structure? Or obtainable from this data, I’m sure there’s a way to do this.
              Use MODx, or the cat gets it!
              • 6316
              • 92 Posts
              Thanks everyone. The basic version of my "admin helper" is

              $e = &$modx->Event;
              
              switch($e->name) {
                case 'OnDocFormSave':
                $pageinfo = $modx->getPageInfo($id,1,'parent');
                if ($pageinfo['parent'] == 32)
                {
                  $table = $modx->db->config['table_prefix'] . 'site_content';
                  mysql_query("UPDATE $table SET richtext=0 WHERE id='$id'");
                }
                break;
              
                default:
                  return;
                  break;
              }
              


              (this one works)