hook_field_widget_properties_ENTITY_TYPE_alter

function hook_field_widget_properties_ENTITY_TYPE_alter

hook_field_widget_properties_ENTITY_TYPE_alter(&$widget, $context)

Alters the widget properties of a field instance on a given entity type before it gets displayed.

Modules can implement hook_field_widget_properties_ENTITY_TYPE_alter() to alter the widget properties for fields on a specific entity type, rather than implementing hook_field_widget_properties_alter().

This hook is called once per field per displayed widget entity. If the result of the hook involves reading from the database, it is highly recommended to statically cache the information.

Parameters

$widget: The instance's widget properties.

$context: An associative array containing:

  • entity_type: The entity type; e.g., 'node' or 'user'.
  • entity: The entity object.
  • field: The field that the widget belongs to.
  • instance: The instance of the field.

See also

hook_field_widget_properties_alter()

Related topics

File

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

Code

function hook_field_widget_properties_ENTITY_TYPE_alter(&$widget, $context) {
  // Change a widget's type according to the time of day.
  $field = $context['field'];
  if ($field['field_name'] == 'field_foo') {
    $time = date('H');
    $widget['type'] = $time < 12 ? 'widget_am' : 'widget_pm';
  }
}

© 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_properties_ENTITY_TYPE_alter/7.x

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部