Submitted by webel on Tue, 2014-01-21 20:33
REFACTOR: this software engineering content is flagged as under consideration for refactoring.
UML Diagram Click on the UML diagram to view it in a lightbox image viewer. You may then zoom in (or just open the image in a new web browser tab using the Download Original link to view large diagrams).
Code examples From OoeBridge:
/**
* Delegate for hook_block_info();
*
* IMPORTANT: this version uses an OOE IBlockSet with multiple
* IBlock implementations to encapsulate the block info arrays !
*
* Adapted from @link https://drupal.org/node/1104464 Declaring the block @endlink
*
* 'You can use a given hook exactly once in any module,
* so this hook must declare all blocks the module needs.'
*
*/
public function block_info( ) {
$blockSet = $this -> factory ( ) -> newBlockSet ( ) ;
$blockSet -> addBlock ( $this -> block_current_posts ( ) ) ;
$blockSet -> addBlock ( $this -> block_demo ( ) ) ;
return $blockSet -> get ( ) ;
}
/**
*
* @var \Drupal\ooe\Block\IBlock
*/
private $block_current_posts ;
/**
*
* @return \Drupal\ooe\Block\IBlock
* Lazily creates the current posts block.
*/
protected function block_current_posts( ) {
if ( empty ( $this -> block_current_posts ) ) {
$this -> block_current_posts = $this -> factory ( ) -> newBlock (
$this -> getModule ( ) . "_block_current_posts" , $this -> getModuleDisplayName ( ) . ': Current posts' ) ;
$this -> block_current_posts
-> setCache ( BlockCacheKind:: CACHE_PER_ROLE )
-> setStatus ( BlockStatusKind:: ENABLED ) ;
}
return $this -> block_current_posts ;
}
/**
*
* @var \Drupal\ooe\Block\IBlock
*/
private $block_demo ;
/**
*
* @return \Drupal\ooe\Block\IBlock
* Lazily creates a demo block.
*/
protected function block_demo( ) {
if ( empty ( $this -> block_demo ) ) {
$this -> block_demo = $this -> factory ( ) -> newBlock (
$this -> getModule ( ) . "_block_demo" , $this -> getModuleDisplayName ( ) . ': Demo block' ) ;
$this -> block_demo
-> setCache ( BlockCacheKind:: CACHE_PER_ROLE )
-> setRegion ( $this -> region_sidebar_1st ( ) )
-> setStatus ( BlockStatusKind:: ENABLED ) ;
}
return $this -> block_demo ;
}
/**
*
* @return \Drupal\ooe\Layout\IRegion
* A sidebar region.
*/
private $region_sidebar_1st ;
/**
*
* @return \Drupal\ooe\Layout\IRegion
* Lazily creates a Bartik sidebar region.
*/
protected function region_sidebar_1st( ) {
if ( empty ( $this -> region_sidebar_1st ) ) {
$this -> region_sidebar_1st = $this -> factory ( ) -> newRegion ( BartikRegions:: SIDEBAR_FIRST ) ;
}
return $this -> region_sidebar_1st ;
}
/**
* Implements hook_block_view().
*
* Delegates to OOE IBlockView implementations
* for construction of the block view arrays !
*
* @param type $delta
*/
public function block_view( $delta = '' ) {
switch ( $delta ) {
case $this -> block_current_posts ( ) -> getDelta ( ) :
return $this -> blockViewCurrentPosts ( ) -> get ( ) ;
case $this -> block_demo ( ) -> getDelta ( ) :
return $this -> blockViewDemo ( ) -> get ( ) ;
}
}
/**
*
* @var \Drupal\ooe\Block\IBlockView
*/
private $blockViewCurrentPosts ;
/**
*
* @return \Drupal\ooe\Block\IBlockView
* Lazily creates a block view for the current posts.
*/
protected function blockViewCurrentPosts( ) {
if ( empty ( $this -> blockViewCurrentPosts ) ) {
$this -> blockViewCurrentPosts = new CurrentPostsBlockView(
$this -> block_current_posts ( ) ,
$this -> getModuleDisplayName ( ) . ': Current posts'
) ;
}
return $this -> blockViewCurrentPosts ;
}
/**
*
* @var \Drupal\ooe\Block\IBlockView
*/
private $blockViewDemo ;
/**
*
* @return \Drupal\ooe\Block\IBlockView
* Lazily creates a demo block view.
*/
protected function blockViewDemo( ) {
if ( empty ( $this -> blockViewDemo ) ) {
$this -> blockViewDemo = new DemoBlockView(
$this -> block_demo ( ) ,
$this -> getModuleDisplayName ( ) . ': Demo block'
) ;
}
return $this -> blockViewDemo ;
}
Visit also