繁体   English   中英

Drupal 7:如何保存模块设置?

[英]Drupal 7: how do I save module settings?

我正在尝试为模块创建一些设置,并遵循Drupal.org上的指南。 我还在将我的工作与现有模块进行比较。

配置菜单会出现在具有正确字段的正确位置,但是当我点击保存时,不会保存任何输入。 (我已运行缓存清除和注册表重建。)

有人知道我在做什么错吗? 我看不出我的东西有什么不同。

在我的.admin.inc文件中,我将表单设置为:

function contact_page_settings() {
  $form = array();

  $config = contact_page_default_settings();

  $form['#tree'] = TRUE;

  $form['contact_page_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Top Section'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    'top-title' => array(
      '#type' => 'textfield',
      '#title' => t('Top title'),
      '#default_value' => !empty($config['top-title']) ? $config['top-title'] : '',
    ),
    'top-left' => array(
      '#type' => 'text_format',
      '#title' => t('Top left'),
      '#default_value' => !empty($config['top-left']) ? $config['top-left'] : '',
    ),
    'top-right' => array(
      '#type' => 'text_format',
      '#title' => t('Top right'),
      '#default_value' => !empty($config['top-right']) ? $config['top-right'] : '',
    ),
  );

  return system_settings_form($form);
}

在我的.module文件中,我有:

function contact_page_menu() {
  $items = array();
  $items['admin/settings/contact-page'] = array(
    'title' => 'Contact Page content',
    'page callback' => 'drupal_get_form',
    'access arguments' => array('administer site configuration'),
    'page arguments' => array('contact_page_settings'),
    'type' => MENU_NORMAL_ITEM,
    'file' => '/admin/contact_page.admin.inc',
  );
  return $items;
}

function contact_page_default_settings() {
  $defaults = array(
    'top-tile' => 'Top title',
    'top-left' => 'Top left',
    'top-right' => 'Top right',
  );
  $config = variable_get('contact_page_settings', array());
  return array_merge($defaults, $config);
}

好的,所以我发现这些值正在保存-当我重新加载配置页面时,它们没有出现在我的文本区域中。

问题是我正在使用text_format字段将数据另存为数组。 我需要获取该数组的value属性作为默认值。

因此,我刚刚将['value']添加到default_value三元表达式中:

'#default_value' => !empty($config['top-right']['value']) ? $config['top-right']['value'] : '',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM