Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-19 12:49:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Callback quagmire with pluggable_ui

Say I want to add an input field beneath the Upload box on the File tab. pluggable_ui() to the rescue!

function pluggable_upload($event, $step, $def) {
   $def = str_replace(
      '</p>',
      '</p>'
         . graf(
            fInput('text', 'my_extra_box', '', 'edit', '', '', '32').sp
            . fInput('submit', '', my_gTxt('extra_upload'), 'smallerbox')
         ),
      $def);
   return $def;
}

Now I want to distinguish between the two boxes. Problems:

  • if someone uses this 2nd box and hits ‘upload’ the file_insert callback fires and I see the error that no file was specified in the (1st) box
  • if I set my own callback to fire ‘pre’ file_insert in the hope of intercepting the call (perhaps detecting if ‘extra_upload’ is set in the $_POST array) :
    • txp_file.php is not loaded so I don’t have access to all the nice functions like file_edit() or file_db_add()
    • if I include_once txp_file.php in my callback, I see the file list duplicated because I can’t stop TXP’s callback from firing after my custom one. I tried faking the step by setting $_POST['step'] = '' to no avail. I also tried exit and got a blank page. In addition I still see the “no file specified” error message in one of the instances of pagetop() on the screen
  • if I add an sInput('my_step') to the additional content in the code above, my callback runs but TXP’s file_insert callback never fires, even if you put a file in the 1st box and hit the 1st upload button (because my step has overridden the original)

So, in short, how the heck do I add a 2nd, independent form element using pluggable_ui() and cleanly distinguish between the actions such that if the 2nd input box is used, my own callback fires where I can acess all the goodness in txp_file.php and can prevent TXP’s file_insert from running, but if the 1st box is used TXP’s file_insert callback runs as normal (perhaps after my callback has decided it’s not interested in the step or has done a little bit of jiggery pokery)?

The only way I can see of doing this is to not use pluggable_ui(). Instead, I could create a self-contained form input (at the expense of a validation error due to nested forms) with its own event+step, and inject that block via javascript after the existing upload box. That’s very pre-4.0.9 :-|

Clearly I’m missing something obvious. Anyone got any ideas that might help a stuck fellow? Thanks.

Last edited by Bloke (2009-05-19 12:50:31)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB