簡體   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