Jump to content

Editing via Modals


Pete
 Share

Recommended Posts

Hi all,

I've got a custom backend page add/edit modal and can hide the tabs I don't want on the page that opens in the modal easily enough, but is there an easy way to hide the "Save and Keep Unpublished" button and perhaps rename "Publish" as "Save"?

I'm pretty sure I'll need a hook but not sure where to look.

Link to comment
Share on other sites

Haven't tested this in a modal. One way to do it.

<?php

namespace ProcessWire;


$this->addHookAfter("ProcessPageEdit::buildForm", null, "hookModifyEditFormGUI");

function hookModifyEditFormGUI(HookEvent $event) {

    if ($event->method == 'buildForm') {
        $page = $event->process->getPage();
        // here you can use $page to skip changes based on a condition
        // ------------
        // get ProcessPageEdit Form
        $form = $event->return;
       // not needed just for debugging
       //  $children = $form->children;

        // get save + keep unpublished button
        $saveAndKeepUnpublished = $form->children->get("id=submit_save_unpublished");
        // if we found it, remove save + keep unpublished
        if ($saveAndKeepUnpublished) {
            $form->remove($saveAndKeepUnpublished);
        }

        // -------

        // get publish button
        $publish = $form->children->get("id=submit_publish");
        // if we found it, change its value
        if ($publish) {
            $publish->value = "For Pete's Sake";
        }

        // <<<<<<<<<<<<<<<<
        // @debug
        bd($event, __METHOD__ . ': $event at line #' . __LINE__);
        bd($event->method, __METHOD__ . ': $event->method at line #' . __LINE__);
        bd($page, __METHOD__ . ': $page at line #' . __LINE__);
        bd($form, __METHOD__ . ': $form buildForm - at line #' . __LINE__);
        // bdb($children, __METHOD__ . ': $children buildForm - at line #' . __LINE__);
        bdb($saveAndKeepUnpublished, __METHOD__ . ': $saveAndKeepUnpublished buildForm - at line #' . __LINE__);
        bdb($publish, __METHOD__ . ': $publish buildForm - at line #' . __LINE__);
        // >>>>>>>>>>>>>>>>>>
    }
}

 

  • Like 1
Link to comment
Share on other sites

Alternatively to hiding/renaming the publish button you can auto-publish the page when it is created:

<?php
$wire->addHookAfter("Pages::saveReady(template=xyz,id=0)", function($event) {
  $page = $event->arguments(0);
  $page->status = 1; // auto-publish
});

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, bernhard said:

you can auto-publish the page when it is created:

Maybe then..

<?php
$wire->addHookAfter("Pages::added(template=xyz,id=0)", function($event) {
  $page = $event->arguments(0);
  $page->status = 1; // auto-publish
});

?

  • Like 1
Link to comment
Share on other sites

38 minutes ago, bernhard said:

@kongondo I don't understand. Is added anything better than saveReady? Wouldn't you have to do a save() or setAndSave() in your example? And isn't the id=0 obsolete (or even wrong) if you are using the added hook?

My point was that saveReady will be called everytime you save but added will be called only when you create the page. However, I totally missed the id=0 bit. So, yes, my point itself is somewhat obsolete in this case ?.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...