Created
August 30, 2012 12:06
-
-
Save pvmchau/3527287 to your computer and use it in GitHub Desktop.
Show image to Node queue Adminstrator page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Ssqueue | |
description = Add node image to Node queue list. | |
core = 6.x | |
package = Vietcoop | |
dependencies[] = nodequeue | |
dependencies[] = imagecache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implement to hook_theme() | |
*/ | |
function ssqueue_theme() { | |
return array( | |
'ssqueue_nodequeue_arrange_subqueue_form' => array( | |
'arguments' => array('form'), | |
), | |
); | |
} | |
/** | |
* Implement to hook_form_alter() | |
*/ | |
function ssqueue_form_alter(&$form, &$form_state, $form_id){ | |
if( strpos($form_id, 'nodequeue_arrange_subqueue_form_')=== 0 ){ | |
$image_style = variable_get('squeue_nodequeue_admin_image_'.$form['#queue']['qid'], 0); | |
if( $image_style ){ | |
$form['#theme'] = 'ssqueue_nodequeue_arrange_subqueue_form'; | |
foreach (element_children($form) as $key) { | |
if( isset($form[$key]['title']) ) { | |
$form[$key]['image'] = array('#value' => theme('imagecache', $image_style, $form[$key]['#node']['field_image'][0]['filepath'])); | |
} | |
} | |
} | |
} | |
if( $form_id == 'nodequeue_edit_queue_form' ){ | |
$persets[0] = t('No Image'); | |
$imagecache_presets = imagecache_presets(); | |
foreach ($imagecache_presets as $preset){ | |
$persets[$preset['presetname']] = $preset['presetname']; | |
} | |
$image_style = variable_get('squeue_nodequeue_admin_image_'.$form['qid']['#value'], 0); | |
$form['imagetype'] = array( | |
'#type' => 'select', | |
'#title' => t('Image stype'), | |
'#options' => $persets, | |
'#default_value' => ($image_style) ? $image_style : $persets[0], | |
'#description' => t('Select one image style to display in Node queue listing page, default has not image.'), | |
'#weight' => 1, | |
); | |
$form['submit']['#weight'] = $form['0']['#weight'] = 100; | |
$form['#submit'][] = 'ssqueue_nodequeue_edit_queue_form_submit'; | |
} | |
if( $form_id == 'nodequeue_admin_delete' ){ | |
$form['#submit'][] = 'ssqueue_nodequeue_edit_queue_form_delete_submit'; | |
} | |
} | |
/** | |
* Theme the subqueue overview as a sortable list. | |
* see @theme_nodequeue_arrange_subqueue_form() | |
*/ | |
function theme_ssqueue_nodequeue_arrange_subqueue_form($form) { | |
$output = ''; | |
$subqueue = $form['#subqueue']; | |
// Get css to hide some of the help text if javascript is disabled. | |
drupal_add_css(drupal_get_path('module', 'nodequeue') .'/nodequeue.css'); | |
$table_id = 'nodequeue-dragdrop-' . $subqueue['sqid']; | |
$table_classes = array( | |
'nodequeue-dragdrop', | |
'nodequeue-dragdrop-qid-' . $subqueue['qid'], | |
'nodequeue-dragdrop-sqid-' . $subqueue['sqid'], | |
'nodequeue-dragdrop-reference-' . $subqueue['reference'], | |
); | |
drupal_add_tabledrag($table_id, 'order', 'sibling', 'node-position'); | |
drupal_add_js(drupal_get_path('module', 'nodequeue') .'/nodequeue_dragdrop.js'); | |
$reverse[str_replace('-', '_', $table_id)] = (bool) $form['#queue']['reverse']; | |
drupal_add_js(array('nodequeue' => array('reverse' => $reverse)), 'setting'); | |
// Render form as table rows. | |
$rows = array(); | |
$counter = 1; | |
foreach (element_children($form) as $key) { | |
if( isset($form[$key]['title']) ) { | |
$row = array(); | |
$row[] = drupal_render($form[$key]['title']); | |
$row[] = drupal_render($form[$key]['image']); | |
$row[] = drupal_render($form[$key]['author']); | |
$row[] = drupal_render($form[$key]['date']); | |
$row[] = drupal_render($form[$key]['position']); | |
$row[] = (!empty($form[$key]['edit'])) ? drupal_render($form[$key]['edit']) : ' '; | |
$row[] = drupal_render($form[$key]['remove']); | |
$row[] = array( | |
'data' => $counter, | |
'class' => 'position' | |
); | |
$rows[] = array( | |
'data' => $row, | |
'class' => 'draggable', | |
); | |
} | |
$counter++; | |
} | |
if( empty($rows) ) { | |
$rows[] = array(array('data' => t('No nodes in this queue.'), 'colspan' => 7)); | |
} | |
// Render the main nodequeue table. | |
$header = array(t('Title'), t('Image'), t('Author'), t('Post Date'), t('Position'), array('data' => t('Operations'), 'colspan' => 2), t('Position')); | |
$output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => implode(' ', $table_classes))); | |
// Render the autocomplete field for adding a node to the table. | |
$output .= '<div class="container-inline">'; | |
$output .= drupal_render($form['add']['nid']); | |
$output .= drupal_render($form['add']['submit']); | |
$output .= '</div>'; | |
// Render the remaining form elements. | |
$output .= drupal_render($form); | |
return $output; | |
} | |
function ssqueue_nodequeue_edit_queue_form_submit($form, &$form_state) { | |
variable_set('squeue_nodequeue_admin_image_'.$form['qid']['#value'], $form['#parameters']['1']['post']['imagetype']); | |
} | |
function ssqueue_nodequeue_edit_queue_form_delete_submit($form, &$form_state) { | |
variable_del('squeue_nodequeue_admin_image_'.$form['#parameters']['2']->qid); | |
} | |
/** | |
* Implement to hook_uninstall() | |
*/ | |
function ssqueue_unistall(){ | |
$qids = db_select('nodequeue_queue', 'nq'); | |
$qids = $qids->fields('nq', array('qid')) ->execute() ->fetchCol(); | |
if( $qids ){ | |
foreach ($qids as $qid) { | |
variable_del('squeue_nodequeue_admin_image_'.$qid); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment