We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9122
    • 27 Posts
    Setting the "Published" flag is not working when using NewsPublisher snippet after I upgraded. We had been using NewsPublisher to allow users to update various resources that populate sections on a page. After upgrading from MODX Revo 2.2.14 with NewsPublisher 1.4.2 to MODX Revo 2.3.5 with NewsPublisher 2.1.0-pl I can no longer set a resource to "published" using NewsPublisher. Here is my NewsPublisher setup:

    NewsPublisher Button to launch edit screen.
    [[!NpEditThisButton? 
        &np_id=`304`
        &np_edit_id=`316` 
        &buttonCaption=`Edit Enterprise News` 
    ]]


    Resource id: 304 NewsPublisher configuration:
    [[!NewsPublisher?
    	&show=`content,pub_date,unpub_date,published`
    	&required=`content`
    	&initrte=`0`
    	&initdatepicker=`1`
    	&rtcontent=`0`
    	&rtsummary=`0`
    	&parentid=`12`
    	&published=`1`
    ]]


    Using the default NewsPublisher template chuck "npBoolTpl"

    <fieldset id="np-[[+npx.fieldName]]-container" class="np-checkbox" title="[[+npx.help]]"><legend>[[+npx.caption]]</legend>
    	<input type="hidden" name="[[+npx.fieldName]]" value = "" />
    	<span class="option"><input class="checkbox" type="checkbox" name="[[+npx.fieldName]]" id="np-[[+npx.fieldName]]" value="1" [[+npx.checked]]/></span>
    </fieldset>


    I noticed in the post request when saving changes to a resource that there were two POST parameters for "published": "published=" and "published=1". I tried removing the hidden input from the "npBoolTpl" which resulted in one "published" parameter being sent in the POST request (published=1) when submitting changes. Content changes get saved, but for some reason the "published" status does not seem to save.

    I can't upgrade until I get this working. Any help is greatly appreciated.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      Are you sure the user is logged in and has the proper permissions to publish resources?
        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
        • 9122
        • 27 Posts
        Yep, the users have rights to publish. Setting the publish flag isn't working for me either and I'm the default Admin. This was working prior to the upgrade, I'm not sure what's going on with this one.
          • 3749
          • 24,544 Posts
          Me too. I was able to reproduce this. You can unpublish but you can't publish.

          It looks like a bug in MODX, but so far I haven't been able to find it. In the MODX update processor, the permission test passes, and the published field is set at the point where the resource is saved, but there's no change in the DB. All the other fields are updated.

          You can publish in the Manager, which uses the same processor. Very weird.

          I'll look at it some more tomorrow.
            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
            • 9122
            • 27 Posts
            Thank you so much for looking into this problem Bob. My results are exactly the same as yours where I can unpublish a resource but cannot publish. That's why I originally thought it might be related to seeing two "published" parameters in the Submit POST request where the first published parameter was empty and the second published parameter had a value of 1.

            • discuss.answer
              • 3749
              • 24,544 Posts
              I found it. It's a bug in NP, not MODX (as usual). If you include the pub_date field in the form and don't set it. It gets set to ' '. strtotime(' ') returns the current time, so MODX thinks there's a pub_date set and refuses to publish the resource.

              A workaround might be to leave the Publish Date date field blank but put a 0 in the time field.

              The more elegant fix would be to use this code around line 1755 of the core\components\newspublisher\model\newspublisher\newspublisher.class.php file:

                      /* correct timestamp resource fields */
                      foreach ($_POST as $field => $val) {
                          if (isset($this->resource->_fieldMeta[$field]) &&
                              $this->resource->_fieldMeta[$field]['phptype'] == 'timestamp') {
                                  $postTime = isset($_POST[$field . '_time'])? $_POST[$field . '_time'] : '';
                              $_POST[$field] = $val . ' ' . $postTime;
                              if (empty($_POST[$field]) || $_POST[$field] == ' ') {
                                  $_POST[$field] = 0;
                              }
                          }
                      }


              I hope to release a new version soon. Sorry for the trouble.

                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
                • 9122
                • 27 Posts
                Cool thanks Bob. I'll give it a shot on Monday when I get back into the office. Thanks so much for your help. BTW I bought an early hardcover copy of your book, it's a great resource. Thanks so much for the quick help.
                  • 3749
                  • 24,544 Posts
                  Thanks for buying my book. wink

                  The Digital Edition is more current and more correct, BTW.
                    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
                    • 9122
                    • 27 Posts
                    I saw that there is a digital copy now too. I was thinking of buying that this weekend so I have a more portable and search friendly version. Thanks again.
                      • 9122
                      • 27 Posts
                      Hey Bob, good news. I replaced the foreach loop at line 1755 of the core\components\newspublisher\model\newspublisher\newspublisher.class.php file with the foreach loop you provided in the post and it works like a charm.

                      Thanks so much for the help and quick fix.