Drupal 7:数据在 hook_block_view() 发送后未出现在块的 .tpl 文件中

Drupal 7: Data not appearing on block's .tpl file after being sent by hook_block_view()

我正在从配置表单中获取数据并将其传递到 .tpl 文件以进行显示。

我正在使用 hook_block_view() 获取数据,将其放入数组并将其发送到 .tpl 文件。

我的代码(在 .module 上)是这样的:

/**
 * Implements hook_block_info().
 */
function message_block_info() {
  return [
    'message_block' => [
      'info' => t('Message'),
      'cache' => DRUPAL_CACHE_GLOBAL,
    ],
  ];
}

/**
 * Implements hook_theme().
 */
function message_theme() {
  return [
    'message_block' => [
      'template' => 'templates/message-block',
      'variables' => [
        'settings' => NULL,
        'attributes' => [],
      ],
    ],
  ];
}

/**
 * Implements hook_block_view().
 */
function message_block_view($delta = '') {
  if ($delta !== 'message_block') {
    return;
  }

  $config = message_default_settings();

  dpm($config); // <- this shows correct data

  $block['content'] = array(
    '#theme' => 'message_block',
    '#config' => array(
      'message_text' => filter_xss($config['message_text']),
      'message_link' => filter_xss($config['message_link']),
      'message_button_text' => filter_xss($config['message_button_text']),
    ),
  );

  return $block;
}

在 .tpl 文件上:

   <?php dpm('test'); //<- This works ?>
   <?php dpm($config); //<- This does not work?>

   <div class="message">
    <?php print $config['message_text']; ?>
    <?php if (!empty($config['message_link']) && !empty($config['alert_button_text'])): ?>
      <a href="<?php print $config['message_link']; ?>" class="button">
        <?php print $config['message_button_text']; ?>
      </a>
    <?php endif; ?>
  </div>

我可以在 .tpl 文件上放置一个 dpm('test');,它会出现,所以我知道 HTML 正在渲染。显然,我也尝试过清除缓存。

有人知道我是否错过了显示此数据的步骤吗?

我发现我缺少 hook_theme 中的配置数组初始化:

function message_theme() {
  return [
    'message_block' => [
      'template' => 'templates/message-block',
      'variables' => [
        'config' => NULL, //<- Was missing
      ],
    ],
  ];
}