Created
April 26, 2013 13:48
-
-
Save GoZOo/5467497 to your computer and use it in GitHub Desktop.
Example for make blocks easily configurable for webmaster without 'administer blocks' access (and without huge permissive module). This fully use formapi (http://api.drupal.org/node/15320) and custom code.
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 | |
| function blockadmin_example_admin() { | |
| $text = variable_get('blockadmin_example_page_text', array('format'=> 'filtered_html', 'value'=> "")); | |
| $form['blockadmin_example_page_text'] = array( | |
| '#type' => 'text_format', | |
| '#format' => $text['format'], | |
| '#title' => t('Texte'), | |
| '#default_value' => $text['value'], | |
| '#size' => 20, | |
| '#required' => FALSE, | |
| ); | |
| return system_settings_form($form); | |
| } |
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_block_info(). | |
| */ | |
| function blockadmin_example_block_info() { | |
| $blocks['myblock'] = array( | |
| 'info' => t('Block with admin content'), | |
| 'cache' => DRUPAL_CACHE_PER_PAGE | |
| ); | |
| return $blocks; | |
| } | |
| /** | |
| * Implements hook_block_view(). | |
| */ | |
| function blockadmin_example_block_view($delta = '') { | |
| $block = array(); | |
| switch ($delta) { | |
| case 'myblock': | |
| $block['subject'] = ''; | |
| $block['content'] = _blockadmin_example_block_myblock(); | |
| $block['class'] = array('blockadmin-example-myblock'); | |
| break; | |
| } | |
| return $block; | |
| } | |
| /** | |
| * Generate content for myblock block | |
| */ | |
| function _blockadmin_example_block_myblock() { | |
| $content = variable_get('blockadmin_example_page_text', array('format'=> 'filtered_html', 'value'=> "")); | |
| return array( | |
| '#markup' => check_markup($content['value'], $content['format']) | |
| ); | |
| } |
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 | |
| module_load_include('inc', 'blockadmin_example', 'blockadmin_example.blocks'); | |
| /** | |
| * Implements hook_menu(). | |
| */ | |
| function blockadmin_example_menu() { | |
| /* | |
| * ** | |
| * Administration | |
| * ** | |
| */ | |
| $items['admin/blockadmin'] = array( | |
| 'title' => '[Name site] administration', | |
| 'page callback' => 'drupal_get_form', | |
| 'page arguments' => array('blockadmin_example_admin'), | |
| 'file' => 'blockadmin_example.admin.inc', | |
| 'access arguments' => array('administer blockadmin_example page'), | |
| 'type' => MENU_NORMAL_ITEM, | |
| 'weight' => -1 | |
| ); | |
| $items['admin/bn/blockadmin_example'] = array( | |
| 'title' => 'Example block', | |
| 'type' => MENU_DEFAULT_LOCAL_TASK, | |
| 'weight' => -1, | |
| 'access arguments' => array('administer blockadmin_example page') | |
| ); | |
| return $items; | |
| } | |
| /** | |
| * Implements hook_permission(). | |
| */ | |
| function blockadmin_example_permission() { | |
| return array( | |
| 'administer blockadmin_example page' => array( | |
| 'title' => "Administrer Blockadmin Example Admin Page", | |
| ), | |
| ); | |
| } // blockadmin_example_permission |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment