We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49499
    • 48 Posts
    I am building a blog using Articles, but I need category support, so I created a resource under the Articles container named "Categories", and then a few resources under "Categories" for each respective category. This gives me pages where I can list specific articles for each category on the front end. I have a TV that uses the children of the resource "Categories" as options in a dropdown.

    The problem is that I could not see nor edit the children resources that are not articles in the resource tree, as Articles hides them by default. I followed the following tutorial, MIGXdb.Manage Child-Resources in a grid-TV with help of MIGXdb to set up a grid view of child resources, per sottwell's suggestion. However, only the top-level resources are pulled, so I only see the "Categories" resource, but not its children resources, which are the actual categories I'll want the ability to edit.

    I would like to do 2 things if possible:

    • Filter out "Articles" posts, so I only see resources created outside of Articles in the migxdb child resource grid.
      (Right now all article posts are visible in addition to the manual resources I created.)
    • View all "grandchildren" instead of just top-level resources.

    Does anyone have any suggestions or ideas?
      • 4172
      • 5,888 Posts
      you will need a custom getlist-processor, which filters your resources as you need them.

      To get all children and grandchildren to a specific depth you can make use of the
      $modx->getChildIds - API - method and use the result within a query-condition

      $c->where(array('id:IN'=>$child_ids));
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 49499
        • 48 Posts
        Quote from: Bruno17 at Dec 09, 2014, 02:54 PM
        you will need a custom getlist-processor, which filters your resources as you need them.

        To get all children and grandchildren to a specific depth you can make use of the
        $modx->getChildIds - API - method and use the result within a query-condition

        $c->where(array('id:IN'=>$child_ids));

        I'm unclear on where I need to make this edit. I'm looking under core/components/migx/processors/mgr/default/ and I see

        • getlist.php
        • getlist_showselector.php
        • getlist_selectfromgrid.php

        Are any of these where I need to make the edit, or do I need to create a new file like getlist_childids.php? And if I create the new file, how do I tie that in on the backend?
          • 4172
          • 5,888 Posts
          currently, I think, you are using this getlist-processor:

          https://github.com/Bruno17/migxchildresources/blob/master/core/components/migxchildresources/processors/mgr/default/getlist.php

          you can create a copy of that processor for example under

          https://github.com/Bruno17/migxchildresources/blob/master/core/components/migxchildresources/processors/mgr/custom/getlist.php

          and set in your MIGXdb - Settings the field 'processors path' to 'custom'
          This would use your custom processor, if there is any.

          then you would change this lines to your needs:

          if ($resource_id) {
              $c->where(array($classname . '.parent' => $resource_id));
          }
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 49499
            • 48 Posts
            That worked beautifully! Thank you!
              • 49499
              • 48 Posts
              Just wanted to share in case anyone needed it. I modified the code above to render all child resources of 'Articles' that are not blog posts. I did this by filtering out all child items that used the articles post template.

              if ($resource_id) {
                  $levels = 6;
                  $articles_template = 7;
                  $child_ids = $modx->getChildIds(149,$levels,array('context' => 'web'));
                  $c->where(array(
                      'id:IN'=>$child_ids,
                      'template:!=' => $articles_template,
                      ));
              }
              


              • $levels is the number of levels of children you want to go to.
              • $articles_template is the ID of the template for articles posts.

              There may be a better way to do this, but this worked great for me.
                • 49499
                • 48 Posts
                Sorry to open this back up, but there is one issue I'm having with the current configuration. The resource listing is working perfectly. However, when I go to create a new child resource, the default parent is the "Articles" container, rather than the "Categories" container. I do have the following configured in FormTabs, where I am setting the default parent for new categories to the "Categories" resource with the ID of 62:

                {
                    "MIGX_id":76,
                    "field":"parent",
                    "caption":"Parent",
                    "description":"",
                    "description_is_code":"0",
                    "inputTV":"",
                    "inputTVtype":"",
                    "validation":"",
                    "configs":"",
                    "restrictive_condition":"",
                    "display":"none",
                    "sourceFrom":"config",
                    "sources":"",
                    "inputOptionValues":"",
                    "default":62,
                    "pos":7
                }
                


                Any suggestions for how to create resources via CMP using MIGXdb where the parent ID can be configured through FormTabs?
                  • 49499
                  • 48 Posts
                  I copied and created a custom update.php processor under 'core/components/migxchildresources/processors/mgr/custom/update.php' and commented out lines 106-108:

                  if (!empty($parent)) {
                      $data['parent'] = $parent;
                  }
                  


                  Now the new resources take the parent ID assigned in FormTabs. Great!

                  There is one issue that I did not notice before (even using the default update.php processor). Resources created through the CMP generated from the MIGXdb config are "incomplete", for lack of a better word...

                  • New resources created through the CMP are not initially available in the Resource Grid, although they do indeed exist.
                  • I have to search for them using the modx search field in order to find them to make any edits.
                  • Once open, the new resource must be 're-saved' in order for the 'View' button to work and to show up in the grid.

                  I'm thinking this may have something to do with the alias field, but I'm not quite sure... Any thoughts?
                    • 4172
                    • 5,888 Posts
                    when they are not shown in the tree, this has todo with the field 'show_in_tree'
                    http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.manage-child-resources-in-a-grid-tv-with-help-of-migxdb#MIGXdb.ManageChild-Resourcesinagrid-TVwithhelpofMIGXdb-Hidingchildrenfromtree

                    you will need to set the value for this field to '1'
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!