I'm building a custom POS modal similar to the POS_Button_Modal_View -based ones that present a view. I wrote a modal that presents a page from a given callback:

class POS_Button_Modal_Page extends POS_Button_Modal {

  public function modalPage(CommercePOS $pos, $js) {
    $form_state = array(
      'title' => drupal_get_title(),
      'build_info' => array('args' => array($pos->getState()->getOrder())),
      'ajax' => $js,
      'pos' => $pos

    if (!$js) {
      return drupal_build_form($this->config['page callback'], $form_state);

    $output = ctools_modal_form_wrapper($this->config['page callback'], $form_state);

    return $output && !$form_state['executed'] ? $output : FALSE;


The modal displays my page as intended, but I don't know how to build a submit button that works like the buttons in the POS-provided views.

The view in, eg. the SetUser POS modal uses the commerce_pos handler to render a button that executes the command:

class commerce_pos_handler_field_pos_command extends views_handler_field { ...

How can I build a submit button in my custom modal that executes my new command?

My command extends POS_Command with my custom implementation of execute()

class POSCommand_MyCommand extends POS_Command {

  function execute(CommercePOS $pos, $input = '') { ...

It seems like a POS_Button_Command should be created and rendered in the modal. But how does that get connected to my command?


Instead of a regular "page" callback, implement the page as a form with an action (submit) button. When the form is submitted and validates, the modal will be released courtesy of the way ctools_modal_form_wrapper() works.

POS_Command was not the right way to think about the problem in this case. POS_Button_Command is better suited to a simple, pre-defined operation as in setting the order user from a list of users. I was trying to do a more complex operation in the modal, gather some data from form inputs, then run some commerce commands on the order.

Short answer: The POS_Button_Modal_Page class works for loading a custom modal page. Implement the page as a form, and do the execution code in the form_submit handler instead of using POS_Command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.