When importing into collection, create a draft instead of a published item

  • We are trying to import content (from a research database) to a collection in a Runway site, then redirect to the edit page for that item so a few fields can be manually filled in / edited by an Editor.


    This works great following these steps: https://docs.grabaperch.com/api/import/collections/


    The only problem is that when the content is imported into the collection, it is immediately published to the site, before the editor has had a chance to fill in / edit fields. Is there a way to set the item to be a draft, and then allow the editor to publish it when they are finished?


    Thanks!

  • drewm

    Approved the thread.
  • Hello jonmires

    The only problem is that when the content is imported into the collection, it is immediately published to the site, before the editor has had a chance to fill in / edit fields. Is there a way to set the item to be a draft, and then allow the editor to publish it when they are finished?


    You can add your own status field to the template:


    HTML
    1. <perch:content id="status" type="select" options="Active|active,Inactive|inactive" label="Status">


    When you initially import the items, you can set the status to something like inactive or pending.


    And only display the items with an active status on your pages:


    PHP
    1. perch_collection('Articles', [
    2. 'filter' => 'status',
    3. 'match' => 'eq',
    4. 'value' => 'active'
    5. ]);
  • Thanks for the responses!


    Clive Walker That's a clever idea, but too much overhead for end users to need to switch back and forth between staging and prod, and give them a workflow for migrating content from staging to prod after they've imported and edited it on staging.


    hus_hmd This is the way I was leaning, though I'm hesitant to do it because it could create confusion for end users. They can have a collection item that is in (Perch) draft mode, but has the status field set to active, and vice versa. It's also an extra step for end users - they need to remember to change the Status field from inactive to active on each item they process. I was really hoping to take advantage of the native Perch draft setup.


    In looking at the DB tables, from what I can tell the only difference between a collection item in draft & published states is that in the [PERCH_DB_PREFIX]_collection_items table, a draft item has the values for itemJSON and itemSearch blank, while a published item has them filled in. Doesn't look like I can do much with this without editing something like the PerchCollectionImporter class in Perch core.


    I suppose one option is to import the item normally, then immediately delete the itemJSON and itemSearch values from the database. That feels pretty hacky, and like it might lead to unintended consequences, but if that's really the only difference between a draft and published item it might do the trick. I will do some testing.

  • I think the problem is that draft doesn't mean unpublished in Perch. It's more a versioning system. Setting an entry to draft removes the current version from the live page (unless previewing is enabled). The previous version of the entry (if there is one) will still be live. That's why many people use their own publish status field to show/hide things (pages, collections etc) as hus_hmd suggested.


    I agree with you that it's potentially confusing to the end user but I don't think that's going to change. IMHO users are confused by EVERYTHING!

  • Ah, good point. For this particular case, the initial item is new, so the draft is always the first revision and it's equivalent to unpublished. But that could lead to even more confusion down the road.


    I ended up going with the separate field as hus_hmd had suggested. Manipulating the db tables directly ended up being sub-optimal, as expected.


    Thanks everyone for the input!