【问题标题】:How to override default user profile fields in drupal 7 ising form API?如何覆盖 drupal 7 ising form API 中的默认用户配置文件字段?
【发布时间】:2011-08-11 16:15:17
【问题描述】:

我想知道如何覆盖/更改用户配置文件中的默认字段,例如:按钮保存、名称、时区等。 我想更改、删除(因为我不需要它们)其中一些。 要更改用户配置文件,我使用挂钩:hook_form_alter 使用它我设法将自己的字段添加到用户配置文件中。但现在我想更改默认字段。我该怎么做?

【问题讨论】:

    标签: forms overriding drupal-7 user-profile


    【解决方案1】:

    可以使用hook_form_alter,但最好使用hook_form_FORM_ID_alter

    为了能够更改您需要了解数组结构的形式,了解这一点的最简单方法是安装 Devel 模块。然后你可以通过在你的alter函数中放置dpm($form);来查看结构。

    您可以在您的自定义模块或您的主题(在template.php文件中)使用此功能。

    通常用户配置文件 form_id 是 user_profile_form。一个简单的例子是:

        function mymodule_form_user_profile_form_alter(&$form,$form_state,$form_id){
          $form['timezone']['#access'] = FALSE; //remove the "timezone" field from the form (default value is still saved)
          $form['field_somefield']['#weight'] = -50; //move the field up
          $form['actions']['submit']['#value'] = t('Add this content now'); //change the submit button text
        }
    

    有关好的教程,请参阅 Lullabot 教程 here(适用于 drupal 6,但适用于 d7!)。

    API:hook_form_FORM_ID_alter

    【讨论】:

      猜你喜欢
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2012-04-29
      • 2019-03-12
      相关资源
      最近更新 更多