开发者

drupal 7 alternative for hook_widget

开发者 https://www.devze.com 2023-04-13 04:28 出处:网络
I am working on a project where i need to port a custom field created in d6 to d7. This field was implementing a hook_widget.

I am working on a project where i need to port a custom field created in d6 to d7. This field was implementing a hook_widget.

Can anyone tell me开发者_运维问答 the replacement for this in drupal 7?

Thanks


hook_widget() has been renamed to hook_field_widget_form() in Drupal 7. There's also some new arguments for it.

http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_widget_form/7

<?php
/**
* Implements hook_field_widget_form().
*/
function number_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  // use += to avoid overwriting incoming $element
  $element['value'] += array(
    // Fill in $element.
  );

  return $element;
}

/**
* Implements hook_field_widget_error().
*/
function number_field_widget_error($element, $error, $form, &$form_state) {
  form_error($element['value'], $error['message']);
}
?>

@See http://drupal.org/node/728792

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号