We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1932
    • 137 Posts
    I was unable to find anything that allowed the QuickEdit to be disabled on a per-page basis, I decided to write a quick little plugin.

    The goal of the plugin is to simplify content management from the front end by allowing designers/administrators to disable the QuickEdit option on pages which do not contain content that should normally be editable, eg. pages with just snippet calls. The plugin will read a custom Template Variable to either show or hide the Quick Edit toolbar and/or content edit link.

    The plugin uses Javascript to disable the QuickEdit elements, making it as unobtrusive as possible and execution order independent. The javascript is inserted just before the </body> tag, so make sure you have the tag in your template and that it’s all lowercase.

    TV Version

    To install:
    1) Copy and paste the below plugin code (without the beginning and ending PHP tags)
    2) Select the "OnWebPagePrerender" event
    3) Create a new Template Variable and associate it with your templates
    - Select "DropDown List Menu" for the Input Type
    - Enter "Show Editor==0||Hide Toolbar==1||Hide Edit Link==2||Hide Both==3" for Input Option Values
    - Enter "0" for Default Value

    <?php
    /**
     * @name     Hide QuickEdit
     * @author   Brian Stanback <www.stanback.net>
     *
     * @license  GNU General Public License
     * @version  0.0.1 (01/12/07)
     *
     * @purpose  Hides the quick editor plugin based on Template Variable
     *
     * @install  - Copy and paste the plugin code (without the beginning and ending PHP tags)
     *           - Select the "OnWebPagePrerender" event
     *           - Create a new Template Variable and associate it with your templates
     *             - Select "DropDown List Menu" for the Input Type
     *             - Enter "Show Editor==0||Hide Toolbar==1||Hide Edit Link==2||Hide Both==3" for Input Option Values
     *             - Enter "0" for Default Value
     */
    
    $tvName = "hideEditor";  // Set the name of the Template Variable
    
    /**
    * Begin plugin code
    */
    
    // Don't do anything if we aren't logged in
    if(!isset($_SESSION['mgrValidated']) || !$_SESSION['mgrValidated']) return;
    
    $e = &$modx->Event;  // Get the MODx event
    
    // Check for the correct event
    if ($e->name == 'OnWebPagePrerender')
    {
    	// Get the current document ID or the error_document ID if document is not found
    	$documentIdentifier = ($modx->documentIdentifier) ? $modx->documentIdentifier : $modx->config['error_page'];
    
    	// Get the template value using API call
    	$hidden = $modx->getTemplateVarOutput($tvName,$documentIdentifier);
    
            // Check the template value
            if ($hidden[$tvName] > 0)
    	{
    		// JS code for hiding the quick editor
    		$js  = "<!-- HideQuickEdit Plugin -->\n";
    		$js .= "<script type=\"text/javascript\">\n";
    		if ($hidden[$tvName] == 1 || $hidden[$tvName] == 3)
    		{
    			$js .= "document.getElementById('QE_Toolbar').style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
    		}
    		if ($hidden[$tvName] > 1)
    		{
    			$js .= "// Using Prototype function\n";
    			$js .= "hideNodes = document.getElementsByClassName('QE_Link');\n";
    			$js .= "hideNodes[0].style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
    		}
    		$js .= '</script>';
    
    		$o = &$modx->documentOutput;  // Pass the output string by reference
    
    		// Append script to the end of the rendered html (just before body close)
    		$o = str_replace("</body>", "$js\n</body>", $o);
    	}
    }
    ?>


    Since QuickEdit’s scripts and code will still be added to the html, this plugin will not solve any namespace conflicts.

    Let me know how it works, if you find it useful, or if there is some better way to achieve this.
      • 22303 MODX Staff
      • 10,725 Posts
      Why not just use the richtext field value for each document to determine this, rather than requiring a TV?
        • 1932
        • 137 Posts
        Good point, the one benefit of a template var is that it can allow for more control over hiding the edit link, toolbar, or both. Below is a mod that does work with the rich text field and lets you set your hiding preferences near the top of the plugin.

        Reading the rich text field is actually a better system for me, thanks for suggesting it. Both versions could be integrated if there is any interest..

        Rich Text Version:

        <?php
        /**
         * @name     Hide QuickEdit
         * @author   Brian Stanback <www.stanback.net>
         *
         * @license  GNU General Public License
         * @version  0.0.2 (01/12/07)
         *
         * @purpose  Hides the quick editor plugin based on Rich Text checkbox
         *
         * @install  - Copy and paste the plugin code (without the beginning and ending PHP tags)
         *           - Select the "OnWebPagePrerender" event
         *           - Control QuickEdit visibility by checking/unchecking rich text
         */
        
        $hideEditToolbar = 0;  // Set to 1 to hide toolbar, 0 to show
        $hideEditLink = 1;  // Set to 1 to hide edit link, 0 to show
        
        /**
        * Begin plugin code
        */
        
        // Don't do anything if we aren't logged in
        if(!isset($_SESSION['mgrValidated']) || !$_SESSION['mgrValidated']) return;
        
        $e = &$modx->Event;  // Get the MODx event
        
        // Check for the correct event
        if ($e->name == 'OnWebPagePrerender')
        {
        	// Get the current document ID or the error_document ID if document is not found
        	$documentIdentifier = ($modx->documentIdentifier) ? $modx->documentIdentifier : $modx->config['error_page'];
        
        	// Get the rich text value by querying the DB and check for result
        	$results = $modx->db->select("richtext", $modx->getFullTableName('site_content'), "id = " . intval($documentIdentifier));
        	if ($modx->db->getRecordCount($results) > 0)
        	{
        		$row = $modx->fetchRow($results);  // Fetch the row from result set
        
                        // Check if richtext is disabled
                        if (!$row['richtext'])
        	        {
                       		// JS code for hiding the quick editor
        	        	$js  = "<!-- HideQuickEdit Plugin -->\n";
                		$js .= "<script type=\"text/javascript\">\n";
                		if ($hideEditToolbar)
                		{
                			$js .= "document.getElementById('QE_Toolbar').style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
                		}
                		if ($hideEditLink)
        	        	{
                			$js .= "// Using Prototype function\n";
        	        		$js .= "hideNodes = document.getElementsByClassName('QE_Link');\n";
        		        	$js .= "hideNodes[0].style.cssText = 'height:1px;overflow:hidden;visibility:hidden;display:none;';\n";
                		}
        	        	$js .= '</script>';
        
                		$o = &$modx->documentOutput;  // Pass the output string by reference
        
        	        	// Append script to the end of the rendered html (just before body close)
                		$o = str_replace("</body>", "$js\n</body>", $o);
                        }
        	}
        }
        ?>
        


          • 25663 MODX Staff
          • 12,272 Posts
          Actually, this would be a great argument for an extra checkbox/radio option in the metadata section along the lines of richtext and log hits. I can think of instances where you’d want no RTEs but also still want QE on a page, like on any personal site I do, or sites with lots of custom javascript-driven effects, etc.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: rthrash at Jan 13, 2007, 01:47 PM

            Actually, this would be a great argument for an extra checkbox/radio option in the metadata section along the lines of richtext and log hits. I can think of instances where you’d want no RTEs but also still want QE on a page, like on any personal site I do, or sites with lots of custom javascript-driven effects, etc.
            Good point Ryan...one cup of coffee is not enough before I start replying... tongue

            Looking over this again, I agree the TV now makes the most sense, and will work moving forward (1.0+) when these kinds of things can simply be custom metadata fields attached to all documents (without need for a relation through the template), and that will work in essentially the same way as the TV does now.
              • 25547
              • 61 Posts
              Is it possible to do this just for certain users?
                • 7231
                • 4,205 Posts
                Quote from: Ross1234 at Apr 04, 2008, 11:24 AM

                Is it possible to do this just for certain users?
                Disable the ability to run modules for the user in question.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 25547
                  • 61 Posts
                  Quote from: dev_cw at Apr 04, 2008, 01:25 PM

                  Quote from: Ross1234 at Apr 04, 2008, 11:24 AM

                  Is it possible to do this just for certain users?
                  Disable the ability to run modules for the user in question.

                  Unfortunately, they need to be able to use FDM the frontend document manager