We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22851
    • 805 Posts
    By default MODx is selecting text/html as the ContentType of newly created documents, even if the parent has something different as its ContentType. Please could someone tell me how I can change the default value of the ContentType TV?

    Thank you,

    Paul
      YAMS: Yet Another Multilingual Solution for MODx
      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • 7231
      • 4,205 Posts
      I think that there may be a configuration (default) for this. Look in the configuration section.
        [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't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 6726
        • 7,075 Posts
        I don’t think there is one actually (or else I missed it), but I have come to enjoy using the ManagerManager plugin a lot (been advertising for it quite a bit lately tongue).

        Here are the rules that could help you there :

        [tt]mm_inherit($fields, $roles, $templates)[/tt]

        (Edit : Oops, "this currently only works for text input fields" undecided )

        or

        [tt]mm_default($field, $value, $roles, $templates, $eval)[/tt]

        (Edit : Ooops, "Currently accepts ’pub_date’ or ’unpub_date’ ")

        I thought it could be used for content-type also but it would seem it does not (yet).
        Might be interresting to dig into the plugin to see how this could be done...
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 22851
          • 805 Posts
          I agree that there doesn’t appear to be an option for setting the default content type in the configuration section. Thanks for your idea about the ManagerManager plug-in. I have figured out how to do it another way though.

          I created a variation on the "Inherit Parent Template" plug-in. This plug-in copies over the template of the parent when a new template is created. I modified it to do the same, but to copy over the contents of the contentType template variable when a new document is created. I don’t fully understand the details of what it does, but it seems to work. Here’s the plug-in:

          /*
           * Inherit contentType from Parent
           * Written By Paul Suckling 26 Sep 2007
           * Based on "Inherit Parent Template by "Raymond Irving - 12 Oct 2006
           *
           * Simply results in new documents inherriting the contentType 
           * of their parent folder upon creating a new document
           *
           * Configuration:
           * check the OnDocFormPrerender event
           *
           * Version 1.0
           *
           */
          
          global $content;
          $e = &$modx->Event;
          
          switch($e->name) {
            case 'OnDocFormPrerender':
              if(($_REQUEST['pid'] > 0) && ($id == 0)) {
                if($parent = $modx->getPageInfo($_REQUEST['pid'],0,'contentType')) {
                  $content['contentType'] = $parent['contentType'];
                }
              }
              break;
          
            default:
              return;
              break;
          }
          
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 6726
            • 7,075 Posts
            Well done that’s a nice little plugin smiley
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l'outil id
              • 7455
              • 2,204 Posts
              and now it would be nice if the extention to the alias is also set to match the ContentType if css is selected would be nice to have .css and if you select xml . xml etc. I am trying to export a page to xls and word and all it realy needs is another doctype for it to work so I added that, but now it sends the file as index.php and not .xls or doc if I rename the file i can load the file into office, but try telling the user that he needs to do that hehe.
              Sorry bit off topic.

              Dimmy
                follow me on twitter: @dimmy01
                • 22851
                • 805 Posts
                Well, I guess that it would probably be best to do that with a separate plug-in that is executed when documents are saved. Is guess that’s the OnDocFormSave event? It would update the extension of the alias field to match the contentType when the document is saved.

                I guess it would look something like the following. WARNING: I still have very little experience with MODx and this is completely untested code. Treat it more like a pseudo-code recipe.

                global $content;
                $e = &$modx->Event;
                
                switch($e->name) {
                  case 'OnDocFormSave':
                    // Get the current alias
                    $alias = $content['alias'];
                
                    // Discard the extension if one exists...
                    $dotPosition = strpos($alias,'.');
                    if (!($dotPosition === false)) $alias = substr($alias,0,$dotPosition);
                
                    // select the appropriate extension
                    switch($content['contentType'])
                    {
                    case 'application/xhtml+xml':
                        $extension = '.html';
                        break;
                    case 'text/html':
                        $extension = '.html';
                        break;
                    case 'text/xml':
                        $extension = '.xml';
                        break;
                   // Other contentTypes here...
                    default:
                        $extension = '.html';
                        break;
                    }
                
                    // Register the modified extension
                    $content['alias'] = $alias . $extension;
                
                    break;
                  default:
                    return;
                    break;
                }
                

                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                  • 6726
                  • 7,075 Posts
                  Quote from: Dimmy at Sep 27, 2007, 02:19 AM
                  and now it would be nice if the extention to the alias is also set to match the ContentType if css is selected would be nice to have .css and if you select xml . xml etc.

                  Sure would but why re-invent the wheel ? To be confirmed, but it seems to me this is already in 0.9.7 wink (ok, ok, it’s not public yet but maybe backport it to 0.9.6 if you can’t wait and if it’s doable)
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l'outil id