Last active
September 8, 2015 21:30
-
-
Save nickgs/d831f597074812db4516 to your computer and use it in GitHub Desktop.
Quick and dirty example of how one may split the block implementation to multiple files
This file contains 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 myblock1() { | |
$blocks = array(); | |
$blocks['myblock1'] = array( | |
'info' => t("Block 1"), | |
); | |
//... | |
return $blocks; | |
} | |
function myblock1_render() { | |
return array('subject' => "Block 1", | |
'content' => t("Should be a render array")); | |
} |
This file contains 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 myblock2() { | |
$blocks = array(); | |
$blocks['myblock2'] = array( | |
'info' => t("Block 2"), | |
); | |
//... | |
return $blocks; | |
} | |
function myblock2_render() { | |
return array('subject' => "Block 2", | |
'content' => t("Should be a render array")); | |
} |
This file contains 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 mymodule_block_info() { | |
$blocks = array(); | |
//include the files that have block functions. | |
module_load_include("php", "mymodule","blocks1"); | |
module_load_include("php", "mymodule","blocks2"); | |
//first section of blocks | |
$blocks = myblock1(); | |
$blocks = array_merge($blocks, myblock2()); | |
//$blocks = array_merge($blocks, myblock3()); | |
//... | |
return $blocks; | |
} | |
function mymodule_block_view($delta = '') { | |
$block = array(); | |
//include the files that have block functions. | |
module_load_include("php", "mymodule","includes/blocks1"); | |
module_load_include("php", "mymodule","includes/blocks2"); | |
//this would require all render functions to contain myblock and end with _render | |
if(strstr($delta, "myblock")) { | |
$block = call_user_func($delta . "_render"); | |
} | |
return $block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment