Submitted by Jan on
/** * store default variables in code */ function modulename_block_content ($delta) { $data = array ( 'nodeblock_en_title' => 'xxxxxxxx', 'nodeblock_en_link' => 'xxxxxxxx', 'nodeblock_en_image' => 'xxxx.png', 'nodeblock_en_content' => 'xxxxxxxx', 'nodeblock_en_more' => 'xxxxxxxx', 'nodeblock_zh-hans_title' => 'xxxxxxxx', 'nodeblock_zh-hans_link' => 'xxxxxxxx', 'nodeblock_zh-hans_image' => 'xxxxxxxx', 'nodeblock_zh-hans_content' => 'xxxxxxxx', 'nodeblock_zh-hans_more' => 'xxxxxxxx', ); } /** * define your blocks */ function modulename_block_info() { foreach ($i=0; $i <= 10 ; $i++ ) { $blocks['nodeblock' . $i] = array( 'info' => t('nodeblock' . $i), 'cache' => DRUPAL_NO_CACHE, ); } } /** * block content output here */ function modulename_block_view($delta = '') { $block = array(); global $language; $lang_id = $language->language; foreach ($i=0; $i < 10 ; $i++ ) { if ($delta == 'nodeblock' .$i) { $image = variable_get("nodeblock_image_" . $lang_id, ''); if (!empty($image)) { $file = file_load($image); $presetname = 'thumbnail'; $src = $file->uri; $dst = image_style_path($presetname, $src); if(!file_exists($dst)) { image_style_create_derivative(image_style_load($presetname), $src, $dst); } $background = file_create_url ($dst); } else { $background = modulename_block_content('nodeblock_image_' . $lang_id); } $output = '<div class="banner" style="background:url(\'' . $background . '\')"></div><div class="content">'; $output .= '<h3 class="bannertitle"><a href="' . variable_get("nodeblock' . $i . '_link_" . $lang_id, modulename_block_content('nodeblock' . $i . '_link_' . $lang_id)) . '">' . variable_get("nodeblock' . $i . '_title_" . $lang_id, modulename_block_content('nodeblock' . $i . '_title_' . $lang_id)) . '</a></h3> <div class="bannerbody">' . variable_get("nodeblock_content_" . $lang_id, modulename_block_content('nodeblock_content_' . $lang_id)) . '</div>'; $output .= l(t('SEE MORE'), variable_get("nodeblock' . $i . '_more_" . $lang_id, modulename_block_content('nodeblock_more_' . $lang_id))); $output .= '</div>'; $block['content'] = $output; } } /** * save variables */ function modulename_block_save ($delta, $edit) { global $language; $lang_id = $language->language; for($i=1; $i < 10; $i++) { if ($delta == 'nodeblock' . $i) { if ($edit['nodeblock' . $i . '_revert']) { variable_del('nodeblock' . $i . '_title_' . $lang_id); variable_del('nodeblock' . $i . '_image_' . $lang_id); variable_del('nodeblock' . $i . '_content_' . $lang_id); variable_del('nodeblock' . $i . '_link_' . $lang_id); variable_del('nodeblock' . $i . '_more_' . $lang_id); } else { variable_set('nodeblock' . $i . '_title_' . $lang_id, $edit['nodeblock' . $i . '_title']); variable_set('nodeblock' . $i . '_image_' . $lang_id, $edit['nodeblock' . $i . '_image']); variable_set('nodeblock' . $i . '_content_' . $lang_id, $edit['nodeblock' . $i . '_content']['value']); variable_set('nodeblock' . $i . '_link_' . $lang_id, $edit['nodeblock' . $i . '_link']['value']); variable_set('nodeblock' . $i . '_more_' . $lang_id, $edit['nodeblock' . $i . '_more']['value']); } } } } function ediamonds_block_configure($delta) { global $language; $lang_id = $language->language; $form = array(); $block_arr = array ( 'nodeblock1' => array('dimension' => '283 x 141px','nomore' => 1), 'nodeblock2' => array('dimension' => '283 x 141px'), 'nodeblock3' => array('dimension' => '283 x 141px'), 'nodeblock4' => array('dimension' => '283 x 141px'), 'nodeblock5' => array('dimension' => '283 x 141px'), 'nodeblock6' => array('dimension' => '283 x 141px'), 'nodeblock7' => array('dimension' => '237 x 264px', 'notitle' => 1, 'nocontent' =>1 , 'nomore' => 1), 'nodeblock8' => array('dimension' => '237 x 264px', 'notitle' => 1, 'nocontent' =>1 , 'nomore' => 1), ); if ( !empty($block_arr[$delta])) { if (empty($block_arr[$delta]['notitle'])) { $form[$delta . '_title'] = array( '#type' => 'textfield', '#title' => 'Title', '#default_value' => variable_get($delta . '_title_' . $lang_id, ediamonds_block_content($delta . '_title_' . $lang_id)), ); } if (empty($block_arr[$delta]['nolink'])) { $form[$delta . '_link'] = array( '#type' => 'textfield', '#title' => t('title link'), '#default_value' => variable_get($delta . '_link_' . $lang_id, ediamonds_block_content($delta . '_link_' . $lang_id)), ); } if (empty($block_arr[$delta]['nocontent'])) { $form[$delta . '_content'] = array( '#type' => 'text_format', '#title' => 'Content', '#default_value' => variable_get($delta . '_content_' . $lang_id, ediamonds_block_content($delta . '_content_' . $lang_id)), ); } if (empty($block_arr[$delta]['noimage'])) { $form[$delta . '_image'] = array( '#type' => 'managed_file', '#title' => 'Image', '#description' => t('dimension w x h:') . $block_arr[$delta]['dimension'], '#default_value' => variable_get($delta . '_image_' . $lang_id, ''), '#upload_location' => 'public://' ); } if (empty($block_arr[$delta]['nomore'])) { $form[$delta . '_more'] = array( '#type' => 'textfield', '#title' => 'More link', '#default_value' => variable_get($delta . '_more_' . $lang_id, ediamonds_block_content($delta . '_more_' . $lang_id)), ); } $form[$delta . '_revert'] = array ( '#type' => 'checkbox', '#title' => t('REVERT TO DEFAULT VALUE') ); }; } /** * print your block */ $nodeblock1 = block_load('modulename', 'nodeblock1'); $nodeblock1 = _block_get_renderable_array(_block_render_blocks(array($nodeblock1))); $nodeblock1 = drupal_render($nodeblock1); print $nodeblock1;
- Log in to post comments