Community

how creating a Views of node teaser inside the modal with Ctools and Views

with this code:
happy.module

<?php

/**
*  Implements of hook_menu()
*/
function happy_menu() {
   
$items['happy/%ctools_js/%'] = array(
           
'title' => 'The Happy Modal',
           
'page arguments' => array(1, 2),
           
'page callback' => 'happy_modal_page',
           
'access callback' => TRUE,
           
'type' => MENU_NORMAL_ITEM,
    );
    return
$items;
}
/**
* A modal static page callback.
* @param $js
*   boolean CTools determination whether the user's browser is javascript enabled.
* @param $nid
*   string The node ID of passed as an argument from the hook_menu() path
* @return
*   string The contents of the node, that will fill the modal window.
*/
function happy_modal_page($js = NULL, $nid = NULL) {
  if (
$nid == NULL) {
   
// You can customize the string below, or use a drupal_goto() to
    // send the user to a custom error page.
   
return 'No node id was sent. Error.';
  }
  if (
$js) {
   
// Required includes for ctools to work:
   
ctools_include('modal');
   
ctools_include('ajax');
  } else return
'Your browser does not support javascript';
 
// Load the node obkect
 
$node = node_load($nid);
 
// Drupal 7 requires a render of the node object in order to obtain a string.
  // Note that I am able to customize the fields by using the "Teaser" display mode
  // under admin/structure/types.
 
$contents = render(node_view($node, 'teaser', NULL));
  return
ctools_modal_render($node->title, $contents) ;
}
/**
* inside happy.module
* Implements hook_views_pre_render()
*/
function happy_views_pre_render(&$views) {
 
// The View name I set up prior is "Happy Titles"
 
if ($views->name == 'happy_titles') {
     
// Include the CTools tools that we need.
     
ctools_include('ajax');
     
ctools_include('modal');
// Add CTools' javascript to the page.
     
ctools_modal_add_js();
// Create our own javascript that will be used to theme a modal.
     
$happy_style = array(
       
'happy-modal-style' => array(
         
'modalSize' => array(
           
'type' => 'fixed',
           
'width' => 300,
           
'height' => 240,
           
'addWidth' => 10,
           
'addHeight' => 10,
           
'contentRight' => 0,
           
'contentBottom' => 0,
          ),
         
'modalOptions' => array(
           
'opacity' => .6,
           
'background-color' => '#684C31',
          ),
         
'animation' => 'fadeIn',
         
'modalTheme' => 'happy_modal',
         
// Customize the AJAX throbber like so:
          // This function assumes the images are inside the module directory's "images"
          // directory:
          // ctools_image_path($image, $module = 'ctools', $dir = 'images')
         
'throbber' => theme('image', array('path' => ctools_image_path('ajax-loader.gif', 'happy'), 'alt' => t('Loading...'), 'title' => t('Loading'))),
         
'closeImage' => theme('image', array('path' => ctools_image_path('modal-close.png', 'happy'), 'alt' => t('Close window'), 'title' => t('Close window'))),
        ),
      );
   
// Add the settings array defined above to Drupal 7's JS settings:
   
drupal_add_js($happy_style, 'setting');
   
// The function below assumes the happy.js file resides in [module_dir]/js
   
ctools_add_js('happy', 'happy');
   
// The function below assumes the happy.css file resides in [module_dir]/css
   
ctools_add_css('happy', 'happy');
  }
}

/**
* Implements hook_theme().
*/
function happy_theme() {
    return array(
           
'views_view_fields__happy' => array(
                   
'variables' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
                   
'template' => 'views-view-fields--happy',
                   
'base hook' => 'views_view_fields',
                   
// I am defining another directory inside the happy module dir called 'theme'
                   
'path' => drupal_get_path('module', 'happy') . '/theme',
            ),
    );
}

/*
* Implements hook_preprocess_view()
*/
function happy_preprocess_views_view_fields(&$vars) {
    if (
$vars['view']->name == 'happy_titles') {
       
// Include the CTools tools that we need.
       
ctools_include('ajax');
       
ctools_include('modal');
       
// The view has two fields, title (not linked and no styles added), and NID (again,
        // no style added. They are available here as $vars['fields']->title and
        // $vars['fields']->nid.
       
$name = $vars['fields']['title']->content;
       
// Create a path for the url that is like our hook_menu() declaration above.
       
$href = 'happy/nojs/' . $vars['fields']['nid']->content;
       
       
$vars['ctools_link'] = ctools_modal_text_button($name, $href, t('View node content for @name', array('@name' => $name)), 'ctools-modal-happy-modal-style');
    }
}
?>

happy.js
<?php
(function ($) {
   
Drupal.theme.prototype.happy_modal = function () {
      var
html = '';
     
html += '<div id="ctools-modal" class="popups-box">';
     
html += '  <div class="ctools-modal-content ctools-modal-happy-modal-content">';
     
html += '    <span class="popups-close"><a class="close" href="#">' + Drupal.CTools.Modal.currentSettings.closeImage + '</a></span>';
     
html += '    <div class="modal-scroll"><div id="modal-content" class="modal-content popups-body"></div></div>';
     
html += '  </div>';
     
html += '</div>';
      return
html;
    }
})(
jQuery);
?>

and views-view-fields--happy.tpl.php
<?php
<h1>custom happy theme</h1>
print
$ctools_link;
?>

in page.tpl.php
i inserted this:
<?php
print ctools_modal_text_button(t('modal happy'),'/happy/nojs/1',t('AAAAAAAAAAAA'));
?>

no error message display but the template does not take any effects.

p/s: my english is not good, forgive this

Comments

No one can solve this? any

No one can solve this?
any comments will help me a lot.

OK. maybe the question is so

OK. maybe the question is so stupid for understand it >.<
the main problems is in this function:

<?php
function happy_theme() {
    return array(
           
'views_view_fields__happy' => array(
                   
'variables' => array('view' => NULL, 'options' => NULL, 'row' => NULL),
                   
'template' => 'views-view-fields--happy',
                   
'base hook' => 'views_view_fields',
                   
// I am defining another directory inside the happy module dir called 'theme'
                   
'path' => drupal_get_path('module', 'happy') . '/theme',
            ),
    );
}
?>

in template i display this line:
<h1>custom happy theme</h1>
but it didn't show up.
any one know the way to display node content by Views module via code?
HELP PLZ...

is problem in 'base hook'

is problem in 'base hook' properties?
why documentation of this property is so rare?
and why there are'nt any comments =.=!

nobody click here