hook_field_widget_form_alter

function hook_field_widget_form_alter

hook_field_widget_form_alter(&$element, &$form_state, $context)

Alter forms for field widgets provided by other modules.

Parameters

$element: The field widget form element as constructed by hook_field_widget_form().

$form_state: An associative array containing the current state of the form.

$context: An associative array containing the following key-value pairs, matching the arguments received by hook_field_widget_form():

  • form: The form structure to which widgets are being attached. This may be a full form structure, or a sub-element of a larger form.
  • field: The field structure.
  • instance: The field instance structure.
  • langcode: The language associated with $items.
  • items: Array of default values for this field.
  • delta: The order of this item in the array of subelements (0, 1, 2, etc).

See also

hook_field_widget_form()

hook_field_widget_WIDGET_TYPE_form_alter()

Related topics

File

modules/field/field.api.php, line 922
Hooks provided by the Field module.

Code

function hook_field_widget_form_alter(&$element, &$form_state, $context) {
  // Add a css class to widget form elements for all fields of type mytype.
  if ($context['field']['type'] == 'mytype') {
    // Be sure not to overwrite existing attributes.
    $element['#attributes']['class'][] = 'myclass';
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_widget_form_alter/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部