3

I'm new to drupal stackexchange and drupal too.

I have made an example module that creates a block called "example". I added a textfield form control to the "example" block's configuration page using the hook_block_configuration hook function. Now I'm trying to get the value from the block configuration's form control in my hook_block_view hook function.

Here is what I have so far:

function example_block_info() {

    $blocks = array();

    $blocks['example'] = array(
        'info' => t('example'),
    );

    return $blocks;

}// end function

function example_block_configuration($delta = '') {

    $form = array();

    switch($delta) {

        case 'example' :

        $form['text'] = array(
          '#type' => 'textfield',
          '#title' => t('Text'),
          '#default_value' => '',
          '#size' => 50,
          '#maxlength' => 100,
          '#required' => true,
        );

    }// end function

    return $form;

}// end function

function example_block_view($delta) {

    $block = array();

    switch($delta) {

        case 'example' :
            $block['content'] = get_block_content(),
            break;

    }// end switch

    return $block;


}// end function

function get_block_content() {

    return /* textfield form control value */

}// end function

I figured I have to use the hook_block_save hook function to get the value from the '$edit' argument and store it somehow, but I'm not show how, or if that's the correct way to go about it.

function example_block_save($delta = '', $edit = array()) {

    switch($delta) {

        case 'example' :

            $edit['text'];

            break;

    }// end switch

}// end function
1

What you need is completely covered in example module: block_example.module

Have a look at following hooks:

  1. block_example_block_configure
  2. block_example_block_save
  3. block_example_block_view
2
  • Can you give an example using my example code?
    – Taurayi
    Sep 23 '12 at 20:42
  • Oh wait, nevermind, I get it, I have to use variable_set() in my hook_block_save() hook function, and variable_get() in my hook_block_view() hook function. Thanks, I mark your answer as correct and I'll update my question to show the solution later. Thanks.
    – Taurayi
    Sep 23 '12 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.