'parapheur_portlet_page', 'access callback' => TRUE, 'title' => 'Block Example', ); return $items; } */ /** * Simple page function to explain what the block example is about. */ function parapheur_portlet_page() { $page = array( '#type' => 'markup', '#markup' => t('Provides a block that fetch data from the iParapheur Go to the block admin page.', array('@url' => url('admin/structure/block'))), ); return $page; } /** * Implements hook_block_info(). * * This hook declares what blocks are provided by the module. */ function parapheur_portlet_block_info() { // This hook returns an array, each component of which is an array of block // information. The array keys are the 'delta' values used in other block // hooks. // The required block information is a block description, which is shown // to the site administrator in the list of possible blocks. You can also // provide initial settings for block weight, status, etc. // Many options are defined in hook_block_info(): $blocks['parapheur_portlet_block'] = array( // info: The name of the block. 'info' => t('Parapheur Portlet'), // Block caching options (per role, per user, etc.) 'cache' => DRUPAL_CACHE_PER_ROLE, // default ); return $blocks; } /** * Implements hook_block_configure(). * * This hook declares configuration options for blocks provided by this module. */ function parapheur_portlet_block_configure($delta = '') { // The $delta parameter tells us which block is being configured. // In this example, we'll allow the administrator to customize // the text of the 'configurable text string' block defined in this module. $form = array(); if ($delta == 'parapheur_portlet_block') { // All we need to provide is the specific configuration options for our // block. Drupal will take care of the standard block configuration options // (block title, page visibility, etc.) and the save button. $form['parapheur_portlet_host'] = array( '#type' => 'textfield', '#title' => t('i-Parapheur Host'), '#size' => 60, '#description' => t('This text will appear in the example block.'), '#default_value' => variable_get('parapheur_portlet_host', 'dev-parapheur.local'), ); $form['parapheur_portlet_port'] = array( '#type' => 'textfield', '#title' => t('i-Parapheur port'), '#size' => 60, '#description' => t('This text will appear in the example block.'), '#default_value' => variable_get('parapheur_portlet_port', '80'), ); } return $form; } /** * Implements hook_block_save(). * * This hook declares how the configured options for a block * provided by this module are saved. */ function parapheur_portlet_block_save($delta = '', $edit = array()) { // We need to save settings from the configuration form. // We need to check $delta to make sure we are saving the right block. if ($delta == 'parapheur_portlet_host') { // Have Drupal save the string to the database. variable_set('parapheur_portlet_host', $edit['parapheur_portlet_host']); } else if ($delta == 'parpaheur_portlet_port') { variable_set('parapheur_portlet_port', $edit['parapheur_portlet_port']); } return; } function _ph_get($host, $port) { global $user; if ($user->uid && array_key_exists('phpCAS', $_SESSION)) { return ''; } else { return ""; } } /** * Implements hook_block_view(). * * This hook generates the contents of the blocks themselves. */ function parapheur_portlet_block_view($delta = '') { //The $delta parameter tells us which block is being requested. switch ($delta) { case 'parapheur_portlet_block': // The subject is displayed at the top of the block. Note that it // should be passed through t() for translation. The title configured // for the block using Drupal UI supercedes this one. $block['subject'] = t('Title of first block (example_configurable_text)'); // The content of the block is typically generated by calling a custom // function. $block['content'] = _ph_get(variable_get("parapheur_portlet_host", "dev-parapheur.local"), variable_get("parapheur_portlet_port", "80")); break; default: $block = array(); } return $block; } /* * The following hooks can be used to alter blocks * provided by your own or other modules. */ /** * Implements hook_block_list_alter(). * * This hook allows you to add, remove or modify blocks in the block list. The * block list contains the block definitions. This example requires * search module and the search block enabled * to see how this hook implementation works. * * You may also be interested in hook_block_info_alter(), which allows changes * to the behavior of blocks. */ function parapheur_portlet_block_list_alter(&$blocks) { // We are going to make the search block sticky on bottom of regions. For // this example, we will modify the block list and append the search block at // the end of the list, so even if the administrator configures the block to // be on the top of the region, it will demote to bottom again. foreach ($blocks as $bid => $block) { if (($block->module == 'search') && ($block->delta == 'form')) { // Remove the block from the list and append to the end. unset($blocks[$bid]); $blocks[$bid] = $block; break; } } } /** * Implements hook_block_view_alter(). * * This hook allows you to modify the output of any block in the system. * * In addition, instead of hook_block_view_alter(), which is called for all * blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a * specific block. * * We are going to uppercase the title of any block if the string "magic string" * is encountered in the content. If we were changing only our block using * hook_block_view_MODULE_DELTA_alter to do this, we would have used the * function: * parapheur_portlet_block_view_parapheur_portlet_example_configurable_text_alter() * * To demonstrate the effect of this hook, you can use the * 'configurable_text_string' block created by this module and add the * text 'magic string' into the configuration. */ function parapheur_portlet_block_view_alter(&$data, $block) { // Verify the we have raw text content if (!isset($data['content']) || !is_string($data['content'])) { return; } // If the content contains the string: 'magic string', uppercase the title. if (strstr($data['content'], 'magic string')) { $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : ''; } } /** * @} End of "defgroup parapheur_portlet". */