We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42562
    • 1,145 Posts
    Quote from: Bob's-Guides
    If you would like to have different NewsPublisher pages with different fields and settings, create a separate page for each one with a different snippet tag on each page. The NpEditThisButton, by default launches the page specified in its &np_id property. If you use the following snippet tag for the button, you can have it launch the appropriate NewsPublisher page by creating a TV for each page called NpId and setting the correct NewsPublisher page ID in it:
    [[!NpEditThisButton? &np_id=`[[*NpId]]
    `

    I have many resources under different parent resources. All children resources have same fields/settings - except their parent id
    I use only one NP to publish - this is made perfectly possible with the awesome &parents=`78,89,74`
    Science(78)
       ----child1
       -----child2
       ----child3
    Religion(89)
       ----child1
       ----child2
       ----child3
    Phiosophy(74)
       ----child1
       ----child2
       ----child3
    NewsPublisher(12)
    I also want to use ONLY ONE NP to edit all the children resources.
    How can I pass the parent id from a resource to the NP resource with the NP edit button, something like np_edit_id_parent?
    In this way this value is received by the NP resource in its &parent=`[[+np_edit_id_parent]]` and the parent is then selected in the &parents=`78,89,74` dropdown list.

    I believe this will maximize the new and powerful NP &parent(s) properties.

    I guess the snippet holding the Np button form can be modified to save the parent id of the resource to a SESSION,
    then the SESSION value is collected in the NP resource and inserted in the &parent=`[[!getParentId]]`

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

    [ed. note: donshakespeare last edited this post 11 years, 9 months ago.]
      TinymceWrapper: Complete back/frontend content solution.
      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • 42562
      • 1,145 Posts
      Okay, I was able to send the parentid through a session and get it at the NP resource.
      It displays as expected but when put in the &parent field, it does not affect the &parents drop down list when EDITING a resource.
      It seems NP cleans out any kind of selection so as not to interfere with the existing values of the resource being edited.

      Since NP obeys the existing values of the parent fields of the resources it edits, there is no need to have a selection in the &parents drop down list (I guess).

      So I could let NP do its thing.
      I am now able to, without tweaking anything, edit several children of different resources with only one NP resource.

      Only problem is that if this is set: &required=`parent`, an exception message will pop when posting an edited resource although the existing parent value is still in place.

      So what I am doing now is:
      [[!NewsPublisher? &parents=`78,89,74`
      &parent=`78` //default destination for new NP-created resources
      &show=`parent` //show the drop down list
      &required=`pagetitle` //not making a parent choice necessary -goes to default 78
      ]]

        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 3749
        • 24,544 Posts
        I'm not quite following you. Wouldn't this work in the button tag?

        &parent=`[[*parent]]`
          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
          • 42562
          • 1,145 Posts
          The NP button tag does not have a &parent property, does it? It's not listed on your site. Anyway, I just tried it, no change!
          I already tried &parent=`[[*parent]]` in the NP resource, but of course it won't work because it returns the parent of the NP resource.

          What I was hoping to achieve is:

          When I click the NP edit button found on a child resource(100),
          when the NP resource then comes up
          that the parent(say 89) of the resource(100) being edited will be selected in the drop down list of parents specified by [[!NewsPublisher? &parents=`78,89,74`]]

          This is purely cosmetic! NP knows the parent ID but only needs to make it highlighted.

          I wonder if I have explained myself suitably.
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • discuss.answer
            • 3749
            • 24,544 Posts
            Yes, I get you now. Sorry for being so slow on the uptake.

            You might try changing the code around line 364 of the NewsPublisher class file

            from this:

            $ph = $this->resource->toArray();
            if ($ph['parent'] == 0) {
              $ph['parent'] = $ph['context_key'];
            }
            

            to this:

            $ph = $this->resource->toArray();
            if ($ph['parent'] == 0) {
              $ph['parent'] = $ph['context_key'];
            } else {
              $this->parentId = $this->resource->get('parent');
            }


            Let me know if it works.
              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
              • 42562
              • 1,145 Posts
              @BobRay Very excellent business indeed!
              Thank you a tonne for NP, and for posting that code. I have been staring at those lines for hours trying to see where not to dig my grave.

              This code now works as expected for editing resources with different parents and for publishing to different parents.
              [[!NewsPublisher? &parents=`78,89,74`
              &parent=`78` //default for brand new resources. Dropdown list is highlighted
              &show=`parent` //show the drop down list
              &required=`pagetitle,parent` //since there is always a selection on the dropdown list, no qualm will arise
              ]]
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                • 3749
                • 24,544 Posts
                Yes, looking at the NP code will drive you completely nuts in a very short time. I made the mistake of trying to adapt the Evo version for Revo rather than starting from scratch.

                Thanks for pointing out the problem and for testing the code. smiley
                  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