Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Im adding custom block programatically through my custom module. Everything is working fine except when i select PHP code in Text format dropdown it doesn't render php and doesn't show anything when i display block in the website. I wrap whatever content return by php code in a div with a class "custom-block-clss", and when i view page HTML using inspect it does show that div but no content inside. HTML text format is working fine though. When i enter html and select text format as full HTML its showing that html.

Here' the code:

function MYBLOCK_block_info() {
$blocks = array();
$blocks['my_block'] = array(
    'info' => t('My Custom Block'),
);

return $blocks;
}

function MYBLOCK_block_configure($delta='') {
$form = array();

switch($delta) {
    case 'my_block' :
        // Text field form element
        $form['text_body'] = array(
            '#type' => 'text_format',
            '#title' => t('Enter your text here in WYSIWYG format'),
            '#default_value' => variable_get('text_variable', ''),
        );

        break;
}
return $form;
}

function MYBLOCK_block_save($delta = '', $edit = array()) {
switch($delta) {
    case 'my_block' :
        // Saving the WYSIWYG text
        variable_set('text_variable', $edit['text_body']['value']);

        break;
}
}


function MYBLOCK_block_view($delta='') {
$block = array();

switch($delta) {
    case 'my_block' :
        $block['content'] = my_block_view();
        break;
}

return $block;
}


function my_block_view() {
$block = array();

// Capture WYSIWYG text from the variable
$text = variable_get('text_variable', '');

// Block output in HTML with div wrapper
$block = array(
    'message' => array(
        '#prefix' => '<div class="custom-block-clss">',
        '#type' => 'markup',
        '#markup' => $text,
        '#suffix' => '</div>',
    ),
);

return $block;

}

Any help is highly appreciated. Thanks!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.