Last active
December 25, 2015 17:49
-
-
Save Greg-Boggs/7016434 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Implements hook_menu() | |
*/ | |
function hoverslider_menu(){ | |
$items = array(); | |
$items['admin/config/content/hoverslider'] = array( | |
'title' => 'Hover slider settings page', | |
'description' => 'This settings page is to set how many rows you want, images to each box etc...', | |
'page callback' => 'hoverslider_admin_callback', | |
'access arguements' => array('access administration pages'), | |
'type' => MENU_NORMAL_ITEM, | |
'access callback' => TRUE, | |
); | |
return $items; | |
} | |
/** | |
* Implements hook_form(); | |
*/ | |
function hoverslider_form($form, &$form_state) { | |
$form['hoverslider_maxrows'] = array( | |
'#type' => 'select', | |
'#title' => t('Select how many rows you want.'), | |
'#options' => array( | |
1=> t('One Column'), | |
2 => t('Two Column'), | |
3 => t('Three Column') | |
), | |
'#default_value' => variable_get('hoverslider_maxrows', 0), | |
'#required' => true, | |
); | |
return system_settings_form($form); | |
} | |
/** | |
* Custom function to assemble the form to be able to configure the module. | |
* Returns a rednered drupal form. | |
* @return | |
* returns a rendered form to display | |
*/ | |
function hoverslider_admin_callback(){ | |
$admin_form = drupal_get_form('hoverslider_form'); | |
return drupal_render($admin_form); | |
} | |
/** | |
* Implements hook_block_info() | |
*/ | |
function hoverslider_block_info() { | |
$blocks = array(); | |
$blocks['HoverSlider'] = array( | |
'info' => t('PDX Research Hover-Slider'), | |
); | |
return $blocks; | |
} | |
/** | |
* Implements hook_block_configure(). | |
*/ | |
function hoverslider_block_configure($delta = '') { | |
$form = array(); | |
switch($delta){ | |
case "HoverSlider": | |
$rowCount = variable_get('hoverslider_maxrows', 1); | |
while($rowCount > 0){ | |
$column = 3; | |
$form['column'.$rowCount] = array(); | |
while($column > 0){ | |
$form['column'.$rowCount]['row'.$rowCount.'text'.$column] = array( | |
'#type' => "textfield", | |
'#title' => t("Enter your title for row:". $rowCount . "Column: ". $column), | |
'#default_value' => variable_get('c'.$column.'r'.$rowCount, ""), | |
); | |
$column--; | |
} | |
$form['column'.$rowCount]['imager'.$rowCount] = array( | |
'#name' => 'row_image'.$rowCount, | |
'#type' => 'managed_file', | |
'#title' => t('please upload a image for the background image.'), | |
'#description' => t('Select an Image for the background image of this row. Only *.gif, *.png, *.jpg, and *.jpeg images allowed'), | |
'#default_value' => variable_get('block_image_'.$rowCount.'_fid', ""), | |
'#upload_location' => 'public://hover_slider/', | |
'#upload_validators' => array( | |
'file_validate_extensions' => array('gif png jpg jpeg'), | |
), | |
); | |
$rowCount--; | |
} | |
break; | |
} | |
return $form; | |
} | |
/** | |
* Implements hook_block_save(). | |
*/ | |
function hoverslider_block_save($delta = '', $edit = array()){ | |
switch($delta){ | |
case "HoverSlider": | |
$rowCount = variable_get('hoverslider_maxrow', 1); | |
while($rowCount > 0){ | |
variable_set('c1r'.$rowCount, $edit['row'.$rowCount.'text1']); | |
variable_set('c2r'.$rowCount, $edit['row'.$rowCount.'text2']); | |
variable_set('c3r'.$rowCount, $edit['row'.$rowCount.'text3']); | |
//save file perm state using the fid | |
$file = file_load($edit['imager'.$rowCount]); | |
$file->status = FILE_STATUS_PERMANENT; | |
file_save($file); | |
$block = block_load('HoverSlider', $delta); | |
file_usage_add($file, 'HoverSlider', 'block', $block->bid); | |
variable_set('block_image_'.$rowCount.'_fid', $file->fid); | |
} | |
break; | |
} | |
} | |
/** | |
* Implements hook_block_view(). | |
*/ | |
function hoverslider_block_view($delta = ""){ | |
$block = array(); | |
switch($delta){ | |
case 'HoverSlider': | |
$block['content'] = HoverSlider(); | |
break; | |
} | |
return $block; | |
} | |
/** | |
* Custom function to assemble renderable array for block content. | |
* Returns a renderable array with the block content. | |
* @params int $r | |
* A integer that indicates how many rows to build; | |
* @params array $images | |
* A array that stores each row background image that will be used to implement | |
* a html attribute for use by JavaScript | |
* @params array $innerhtml | |
* A sub render array to be pushed into parent container from block. | |
* @return | |
* returns a renderable array of block content. | |
*/ | |
function HoverSlider_view() { | |
$block = array(); | |
//image[] will be used for storing the rows bg images. | |
$images = array(); | |
$matrixCells = array(); | |
//get row count | |
$r = variable_get('hoverslider_maxrow', 1); | |
//set the container | |
$block['container'] = array( | |
'#prefix' => '<div class="block-hs-container">', | |
'#markup' => array(), | |
'#suffix' => '</div>' | |
); | |
while($r > 0){ | |
for($c = 1; $c < 3; $c++){ | |
$matrixCells['r'.$r.'c'.$c] = array( | |
'#prefix' => '<div class="matrix-cell">', | |
'#markup' => '<p>'.variable_get('c'.$c.'r'.$r, "").'</p>', | |
'#suffix' => '</div>' | |
); | |
} | |
$innerhtml = array( | |
'#prefix' => '<div class="matrix-row">', | |
'#markup' => $matrixCells, | |
'#suffix' => '</div>', | |
); | |
$block['container']["#markup"][] = $innerhtml; | |
$r--; | |
} | |
dpm($block); | |
//load image path. this will be used later. | |
return $block; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment