0

Once again, I am stuck asking questions on CTools that people have asked a million times before. I have a view that displays a list of custom-developed entities (built with ECK) and each one has a link that should show a Ctools-driven modal.

I looked at a few approaches (namely this) to explore any method to get Drupal to display said modal. I figured that I didn't need all this extra views hook logic to fire the modal -- ideally, if a hook_menu() click is fired, it should open the modal and any contents I send to it (which will be done through additional methods). Right now, it treats the logic as a static route, and returns the results as a page. I also explored using the Ctools Auto Modal module (seen in the example, which reflects current code), which also returns the same results when used as documented.

I'm completely lost here, mostly because of the reach of Ctools and the various conflicting forms of documentation on its use for something simple as a tie in for hook_menu(). The long hours i've been pouring into this project are clearly having a toll on my ability to implement this, does anyone have any insight?

The actual logic is below:

/**
 * Implements hook_menu()
 *
 * The sole item call in hook_menu is driven from a URL that is built
 * Within a view, from rewrite rules. When activated, it should render
 * the new modal window.
 */
function example_menu() {
  $items['selectbook/%'] = array(
    'title' => "Perk Modal",
    'page arguments' => array(1),
    'page callback' => 'example_modal_page',
    'access arguments' => array('view content'),
    'access callback' => TRUE,
    'modal' => TRUE,
  );

  return $items;
}

/**
 * Returns a test modal
 */
function example_modal_page($js = null, $attribute = null) {
  return "Test Modal"; //Right now returns as new page call not as a modal
}
0

You mentioned you tried ctools_automodal which is a quick way to accomplish creating a link in a view to open in a modal. With the module, you can use hook_menu_alter to add 'modal' => TRUE to the link menu router item. Nothing else is involved. Ctools_automodal handles all the rest. That means you don't need your own example_modal_page page callback, and you don't need to call ctools_modal_render. Let the Ctool_automodal module do that for you.

If your path has a wildcard, then ctools_automodal will need an actual wildcard variable defined and a "_load" function. In your example above, your path is selectbook/%. If you change it to "selectbook/%selectbook" and defined a selectbook_load function then ctools_automodal should recognize it as a modal path. Here's an example:

/**
 * Implements hook_menu().
 *
 * The sole item call in hook_menu is driven from a URL that is built
 * from rewrite rules within a view. When activated, it should render
 * the new modal window.
 */
function example_menu() {
  $items['selectbook/%selectbook'] = array(
    'title' => "Perk Modal",
    'page arguments' => array(1),
    'page callback' => 'example_modal_page',
    'access arguments' => array('view content'),
    'modal' => TRUE,
  );

  return $items;
}

function selectbook_load($selectbook) {
  // Todo: Do something with selectbook, like load an entity.
  // For this proof of concept, just return it.
  return $selectbook;
}

function example_modal_page($selectbook) {
  // If you loaded an entity in selectbook_load, then you have that
  // fully loaded entity in $selectbook.
  return "Test Modal";
}
  • Well, I tried the call as you suggested, w/o the ctools_modal_render, and instead have it return a string. Instead, all it does is treat it like a standard page routing rule, directing it to a page that returns said string. The module is enabled, and the modal setting is set to true. I'm increasingly running out of options to use Ctools. I've updated the code above to better reflect what i'm aiming to do. – Cameron Kilgore Dec 22 '14 at 15:01
  • Thanks for the update, Cameron. I think the problem might be that ctools_automodal is seeing the modal path is "selectbook/%" instead of what the actual path might be like "selectbook/1". I updated my answer to include how to use wildcards with ctools_automodal. – Evil E Dec 23 '14 at 5:46

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.