嗨,我想使用Drupal 8中变量表呈现的数据创建多个块。
我能够在Drupal 7中实现它,但找不到在 Drupal 8 中实现相同功能的方法。
任何人都可以建议我实现这一目标的方法。
Drupal 7 的代码如下:
<?php
/**
* Create a block that will display the calendar feed
* Implements hook_block_info
*/
function my_module_block_info() {
$blocks = array();
$block_urls = variable_get('my_module_content');
$block_regions = variable_get('my_module_content_block_region');
$number_of_blocks = count($block_urls);
if ( $number_of_blocks > 0 ) {
foreach ( $block_urls as $key => $block_url ) {
$blocks['eventblock-' . $key] = array(
'info' => t('my_module_widget_block_' . $key),
'status' => TRUE,
'region' => $block_regions[$key],
'cache' => DRUPAL_NO_CACHE,
);
}
}
return $blocks;
}
/**
* Render the my_module block
* Implements hook_block_view
*/
function my_module_block_view($delta = '') {
$block = array();
$block_urls = variable_get('my_module_content' , array());
foreach ( $block_urls as $key => $block_url ) {
switch ($delta) {
case 'eventblock-' . $key:
$widgetURL= $block_urls[$key];
$block['content'] = my_module_content_generate($widgetURL); // Some function to generate block content.
break;
}
}
return $block;
}