<![CDATA[ How to add a tab for the document resource using a Plugin or Snippet (without ManagerManager)? - My Forums]]> https://forums.modx.com/thread/?thread=100580 <![CDATA[How to add a tab for the document resource using a Plugin or Snippet (without ManagerManager)?]]> https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543491 1. create 3 tabs for the top hierarchy documents (which are language docs: en, de, ru)
2. Add those as tabs to each document edit.
3. Result should be:

General | Settings | EN | DE | RU

4. We use the same alias for each language, so we can link the langauges directly to each other. E.g. en/news and ru/news

How to achieve this goal in Modx Evolution?]]>
kajus99 Jul 22, 2016, 03:51 AM https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543491
<![CDATA[Re: How to add a tab for the document resource using a Plugin or Snippet (without ManagerManager)? (Best Answer)]]> https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543513
// if including a file
include MODX_BASE_PATH.'assets/plugins/tabs/tab.plugin.php';


<?php
/*  tabs.plugin.php

*/

/*
Copy / paste the following into the SQL tab in phpMyAdmin
to create the sample table
Change the {PREFIX} part to match your setup

CREATE TABLE IF NOT EXISTS `{PREFIX}tabs_demo` (
  `id` int(10) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `docid` integer NOT NULL DEFAULT '0' COMMENT '',
  `content` mediumtext,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM COMMENT='';
*/

// name of the table which holds your data, without any prefix
$table_name ='tabs_demo';


$tab_tpl ='
<!-- tab create -->
        <div class="tab-page" id="tab[+tab_title+]">
<!-- tab title -->
            <h2 class="tab">[+tab_title+]</h2>
            <script type="text/javascript">tpSettings.addTabPage( document.getElementById( "tab[+tab_title+]" ) );</script>
<!-- tab content -->
            <div class="sectionHeader" id="[+tab_title+]_header">[+tab_heading+]</div>
            <div class="sectionBody">
                [+tab_content+]
           </div>
<!-- end tab content -->
        </div>
<!-- close tab -->
';


$e = &$modx->Event;
$output ='';
switch ($e->name) {

    case 'OnDocFormRender':
        
        /*====== copy this entire block to add a new tab  ======*/
        // modify the settings below for each tab
        $item_name ='EXAMPLE';
        $tab_title ='Tab Title';
        $tab_heading ='Tab Heading';
        $tab_content ='
            <div style="width:100%">
                <textarea id="[+item_name+]" name="[+item_name+]" style="width:100%; height:200px;" onchange="documentDirty=true;">[+field_content+]</textarea>
                <input type="hidden" name="[+item_name+]_NAME" value="[+hidden_item_name+]">
                <input type="hidden" name="[+item_name+]_ID" value="[+hidden_item_id+]">
            </div>';
        // end modify settings

        // we are editing an existing document
        if( $_REQUEST['a'] == '27' ){

            // $id is populated with the current modx document id
            $tab_details = $modx->db->getRow( $modx->db->select( '*', $modx->getFullTablename( $table_name ), 'docid="'.$id.'" AND name="'.$item_name.'"'));

        }

        $replace = array(
                '[+tab_title+]'         => $tab_title,
                '[+tab_heading+]'       => $tab_heading,
                '[+tab_content+]'       => $tab_content,
                '[+hidden_item_name+]'  => $item_name,
                '[+hidden_item_id+]'    => $_REQUEST['a'] == '27' ? $tab_details['id'] : '',
                '[+item_name+]'         => $item_name,
                '[+field_content+]'     => $_REQUEST['a'] == '27' ? $modx->htmlspecialchars($tab_details['content']) : ''
                );

        $output .=str_replace( array_keys( $replace ), array_values( $replace ), $tab_tpl );

        /*======  end tab block ======*/


        // send the tabs output
        echo $output;
        
    break;
    
    case 'OnDocFormSave':
        
        /*====== copy this block and modify for each of the form fields ======*/
        if( isset ( $_POST['EXAMPLE'] ) ){

            $post_value = $modx->db->escape( trim( $_POST['EXAMPLE'] ) );
            $post_id =$_POST['EXAMPLE_ID'];
            $post_name =$_POST['EXAMPLE_NAME'];

            $status ='';
            if( $post_id !='' ){

                // we are editing an existing item
                $fields = array(
                    'content' => $post_value
                );
                $update = $modx->db->update( $fields, $modx->getFullTablename( $table_name ), 'docid="'.$id.'" AND id="'.$post_id.'"' );
                $status .= $update ? 'update success' : 'update failed';
                
            }else{

                // creating a new item
                $fields = array(
                    //'id'      => '',
                    'name'    => $post_name,
                    'docid'   => $id,
                    'content' => $post_value
                );
                $insert = $modx->db->insert( $fields, $modx->getFullTablename( $table_name ) );
                $status .= $insert ? 'insert success' : 'insert failed';
            }

            // log this event - Reports / System Events
            // comment this out after testing
            $modx->logEvent( 0, 1, 'status: '.$status.' - name: '.$post_name.' - id: '.$post_id.'<br>'.$post_value , 'Tabs plugin' );
        }
        /*====== end of copy block ======*/
        
    break;

    default: '';
    
    return;
}
?>


On the System Events tab check the following events:
OnDocFormRender
OnDocFormSave
]]>
breezer Jul 23, 2016, 02:19 AM https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543513
<![CDATA[Re: How to add a tab for the document resource using a Plugin or Snippet (without ManagerManager)?]]> https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543492 breezer Jul 22, 2016, 07:38 AM https://forums.modx.com/thread/100580/how-to-add-a-tab-for-the-document-resource-using-a-plugin-or-snippet-without-managermanager#dis-post-543492