In Drupal 7, if we need to define multiple instances of blocks from a database table, we use a foreach loop to return the array key, and then we we get all the multiple instances of our block using hook_block_info()
.
function mymodule_block_info() {
$blocks = array();
$add = db_select('mymodule_blocks_data', 'n')
->fields('n', array('delta', 'title', 'content_type'))
->condition('n.form_type', 'Add', '=')
->execute();
foreach ($add as $row) {
$blocks[$row->delta] = array(
'info' => t('@name (Add Form Block) Type: @type', array('@name' => $row->title, '@type' => $row->content_type)),
'cache' => DRUPAL_NO_CACHE,
);
}
$edit = db_select('mymodule_blocks_data', 'n')
->fields('n', array('delta', 'title', 'content_type', 'nid'))
->condition('n.form_type', 'Edit', '=')
->execute();
foreach ($edit as $row) {
$blocks[$row->delta] = array(
'info' => t('@name (Edit Form Block) Nid: @nid', array('@name' => $row->title, '@nid' => $row->nid)),
'cache' => DRUPAL_NO_CACHE,
);
}
return $blocks;
}
In Drupal 8, I suppose hook_block_info()
is replaced by plugin derivatives.
Though I found a way here where they display nodes by using the entity manager, I have still to understand what I need to do when I am using my custom database table, and not an entity.
What is the equivalent code in Drupal 8 for hook_block_info()
?