We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    I may be wrong, but it is my impression that the publish date is only set when using the publish date field. Is there a way to get the pub date to be filled when a document is put in the published state? Can this be done with a plug-in?
      [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
      You’re not wrong, that’s something which could be improved indeed if the published date could be set by default as the createdon date... I am not qualified but I’d say it could be done with a plugin listening to "OnDocPublished" or "OnDocFormSave"
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 3749
        • 24,544 Posts
        I’m not sure what purpose it would serve (though maybe there’s a good reason you want this that I’m not thinking of). If you want all documents published when created, you can set the default for new docs to published.

        Once the "published" checkbox is checked, the doc is published regardless of the "published" date.

        IOW, the "published" date is only relevant if you want a document to remain unpublished after you create it. If you want to refer to the date the doc was created, you have the "created on" date.

        On second thought, I guess if it worked as DavidM has suggested, we wouldn’t have to explain to users that they didn’t have to fill in the published date when creating documents.
          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
          • 7231
          • 4,205 Posts
          On second thought, I guess if it worked as DavidM has suggested, we wouldn’t have to explain to users that they didn’t have to fill in the published date when creating documents.
          That would be the main point. However, also since it is a document variable it is a good choice to use for anything that needs a simple date associated to it. Using created date and edited date is only valid if you are working chronologically, does not help with adding past archives. Of course we could always use a date TV, but it seems inefficient if there is the pub_date field available (and most of the time not doing anything). I understand that it is intended for scheduling, but it seems like it would make logical sense to be set when a document is published. If it is only to be used for scheduling then it should be renamed to "schedule publish date" rolleyes
            [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]
            • 1978
            • 131 Posts
            my problem is the following - i have news published at a sertain time in the future and then autoticaly emailed

            in ditto listing i have pub_date date source and it uses createdon if no pub_date is set - that’s OK.

            But in the news itself i have date show via [*pub_date*] and if no pub_date set it writes 01.01.1970 (using FormatDate snippet)

            I realy need it to be inherited because i’m tired of writing pub_date manualy each and every time even when i dont’t have it to be published in the future.

            may be some of the gurus can help me?

            the only way i see is to write a snippet which will look for pub_date if there’s none it will use createdon but i hope there is better and simplier way.
              Как русифировать Modx 0.9.6.1(QuickEdit, TinyMCE)
              QuickEdit под win-1251 без mb_-функций
              • 3749
              • 24,544 Posts
              One way would be to create a plugin that listens to the OnBeforeDocFormSave event and fills the current date (or duplicates the "created on" date) in the pub date field only if there’s nothing there already, although then the only way to save a document without it being published immediately would be to enter a future date the field. I guess you might be able to have the plugin act only if "now" were in the field -- that would be easier than entering a date at least.

              Maybe someone else has a better idea.
                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
                • 5727
                • 160 Posts
                Quote from: BobRay at Sep 24, 2008, 04:12 PM

                One way would be to create a plugin that listens to the OnBeforeDocFormSave event and fills the current date (or duplicates the "created on" date) in the pub date field only if there’s nothing there already, although then the only way to save a document without it being published immediately would be to enter a future date the field. I guess you might be able to have the plugin act only if "now" were in the field -- that would be easier than entering a date at least.

                Maybe someone else has a better idea.


                I think the plugin should check for a change of state on the published field. If the document was unpublished and is now going to be published, set the pub_date to now. In any other case, don’t do anything.

                My 2 cents.
                  Olivier Deland
                  Montreal, Canada - Web Developer
                  • 7231
                  • 4,205 Posts
                  Ideally it would check the change in the published check box. But how to do this? The plug in would need to know the original state of the checkbox and compare with the new state.
                    [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]