summaryrefslogtreecommitdiff
path: root/modules/field/field.api.php
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-23 18:23:24 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-23 18:23:24 +0000
commitecf913b37f71b55ba19c0cf3a65861b6f3879d60 (patch)
tree34bcf5e0ecbdba9c35994776de00a260c25beebd /modules/field/field.api.php
parent1d2e7683abf643bb04856d5a58e8d2bb7dc4e860 (diff)
downloadbrdo-ecf913b37f71b55ba19c0cf3a65861b6f3879d60.tar.gz
brdo-ecf913b37f71b55ba19c0cf3a65861b6f3879d60.tar.bz2
#806830 by Amitaibu, yched: Add Dynamic (i.e. not cached) alter hook to instance definitions.
Diffstat (limited to 'modules/field/field.api.php')
-rw-r--r--modules/field/field.api.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php
index 9b3ebf0f5..415e8935c 100644
--- a/modules/field/field.api.php
+++ b/modules/field/field.api.php
@@ -2178,6 +2178,71 @@ function hook_field_extra_fields_display_alter(&$displays, $context) {
$displays['description']['visibility'] = FALSE;
}
}
+
+/**
+ * Alters the widget properties of a field instance before it gets displayed.
+ *
+ * Note that instead of hook_field_widget_properties_alter(), which is called
+ * for all fields on all entity types,
+ * hook_field_widget_properties_ENTITY_TYPE_alter() may be used to alter widget
+ * properties for fields on a specific entity type only.
+ *
+ * This hook is called once per field per added or edit entity. If the result
+ * of the hook involves reading from the database, it is highly recommended to
+ * statically cache the information.
+ *
+ * @param $widget
+ * The instance's widget properties.
+ * @param $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 hook_field_widget_properties_ENTITY_TYPE_alter()
+ */
+function hook_field_widget_properties_alter(&$widget, $context) {
+ // Change a widget's type according to the time of day.
+ $field = $context['field'];
+ if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_foo') {
+ $time = date('H');
+ $widget['type'] = $time < 12 ? 'widget_am' : 'widget_pm';
+ }
+}
+
+/**
+ * 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.
+ *
+ * @param $widget
+ * The instance's widget properties.
+ * @param $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 hook_field_widget_properties_alter()
+ */
+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';
+ }
+}
+
/**
* @} End of "ingroup field_storage"
*/