function block_token_blocks in Block Token 8
Same name and namespace in other branches
- 7 block_token.module \block_token_blocks()
Blocks with tokens.
Parameters
string $token: Token name.
Return value
array|bool If token name provided boolean indicating whether it is on or not otherwise the list of blocks with tokens.
2 calls to block_token_blocks()
- block_token_tokens in ./
block_token.module - Implements hook_tokens().
- block_token_token_info in ./
block_token.module - Implements hook_token_info().
File
- ./
block_token.module, line 74 - Defines necessary hooks and functions for block_token form.
Code
function block_token_blocks($token = NULL) {
static $block_token;
if (is_null($block_token)) {
$block_token = array();
// Select all the name fields from the config table starting with block.block.
$blocks = \Drupal::database()
->select('config', 'b')
->fields('b', array(
'name',
'data',
))
->condition('name', \Drupal::database()
->escapeLike("block.block") . '%', 'LIKE')
->execute();
foreach ($blocks as $block) {
if (isset(unserialize($block->data)['third_party_settings']['block_token']['token_value'])) {
$bid = explode('.', $block->name)[2];
$block = Block::load($bid);
$module = end($block
->getDependencies()['module']);
$block_token[block_token_token_name($module, $bid)] = $block;
}
}
if (!is_null($token)) {
return !empty($block_token[$token]);
}
}
return $block_token;
}