且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改用户/密码登录框的大小

更新时间:2023-09-10 15:19:58

好吧,你即将进入最激动人心的Drupal的复杂功能:形式API或简化的FAPI。一些理论先行,然后解决! :)

Ok... you are about to enter one of the most exciting and complex features of Drupal: the form API or - for brevity - FAPI. Some theory first, and then the solution! :)

Drupal中的所有表单都由 drupal_get_form()函数构建,该函数接受一个数组作为参数。数组中的每个字段基本上都是您的表单的一个字段,每个字段都有多个属性,每个字段都定义了该字段的附加特征,例如其默认值(如果是必需或可选),并且 - 是 - 在textfields的情况下...他们必须有多大!您可以在这里找到表单数组结构的详细说明。在drupal网站上

All forms in Drupal are built by the drupal_get_form() function, that accepts an array as parameter. Each field in the array is basically a field of your form, and each field has a number of proprieties, each of them define additional characteristics of the the field, like for example its default value, if it is required or optional and - yes - in the case of textfields... how large they have to be! You can find a detailed explanation of the structure of form arrays here on the drupal site.

表单API的优点是,呈现该窗体的函数在其构建过程中的各个时刻调用多个钩子过程,所以你可以实现这些钩子,以便在更改表单之前,先将其转换为浏览器。

The beauty of the form API is that the function that renders the form invokes a number of hooks at various moments during its building process, so you can implement these hooks in order to "alter" a form before it is finalised and sent to the browser.

表单更改最常见的钩子是 hook_form_alter() hook_form_FORM_ID_alter() 。第一个执行为由drupal引擎处理的任何表单,后者仅适用于名为FORM_ID的特定格式。我不会详细介绍表单API的内部工作,但在这里你可以阅读更多

The most commonly hooks for form alteration are hook_form_alter() and hook_form_FORM_ID_alter(). The first is executed for any form processed by the drupal engine, the latter only for the specific form named "FORM_ID". I will not get into any more details on the internal working of the form API, but here you can read more.

至于你的具体情况,我假设你正在使用标准的用户块 Drupal的。在这种情况下,我建议您以类似于以下形式实现 hook_form_FORM_ID_alter()

As for your specific case, I assume you are using the standard "user block" shipping with Drupal. In this case I suggest you implement hook_form_FORM_ID_alter() in a form similar to this one:

mymodule_form_user_login_block_alter(&$form, $form_state) {
  $form['pass']['#size'] = 43;
}

希望这有帮助! :)