- Patch #914792 by sun, moshe weitzman, effulgentsia: custom element properties entirely override default element info properties.

merge-requests/26/head
Dries Buytaert 2010-11-12 02:59:30 +00:00
parent fd37414f45
commit 566c39e7a3
2 changed files with 23 additions and 9 deletions

View File

@ -5754,6 +5754,9 @@ function element_sort_by_title($a, $b) {
/** /**
* Retrieve the default properties for the defined element type. * Retrieve the default properties for the defined element type.
*
* @param $type
* An element type as defined by hook_element_info().
*/ */
function element_info($type) { function element_info($type) {
// Use the advanced drupal_static() pattern, since this is called very often. // Use the advanced drupal_static() pattern, since this is called very often.
@ -5775,6 +5778,21 @@ function element_info($type) {
return isset($cache[$type]) ? $cache[$type] : array(); return isset($cache[$type]) ? $cache[$type] : array();
} }
/**
* Retrieve a single property for the defined element type.
*
* @param $type
* An element type as defined by hook_element_info().
* @param $property_name
* The property within the element type that should be returned.
* @param $default
* (Optional) The value to return if the element type does not specify a
* value for the property. Defaults to NULL.
*/
function element_info_property($type, $property_name, $default = NULL) {
return (($info = element_info($type)) && array_key_exists($property_name, $info)) ? $info[$property_name] : $default;
}
/** /**
* Function used by uasort to sort structured arrays by weight, without the property weight prefix. * Function used by uasort to sort structured arrays by weight, without the property weight prefix.
*/ */

View File

@ -1745,13 +1745,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) {
$bundles = field_info_bundles(); $bundles = field_info_bundles();
// Create a form structure for the instance values. // Create a form structure for the instance values.
// @todo Fieldset element info needs to be merged in order to not skip the $form['instance'] = array(
// default element definition for #pre_render. While the current default
// value could simply be hard-coded, we'd possibly forget this location
// when system_element_info() is updated. See also form_builder(). This
// particular #pre_render, field_ui_field_edit_instance_pre_render(), might
// as well be entirely needless though.
$form['instance'] = array_merge(element_info('fieldset'), array(
'#tree' => TRUE, '#tree' => TRUE,
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('%type settings', array('%type' => $bundles[$entity_type][$bundle]['label'])), '#title' => t('%type settings', array('%type' => $bundles[$entity_type][$bundle]['label'])),
@ -1759,8 +1753,10 @@ function field_ui_field_edit_form($form, &$form_state, $instance) {
'%field' => $instance['label'], '%field' => $instance['label'],
'%type' => $bundles[$entity_type][$bundle]['label'], '%type' => $bundles[$entity_type][$bundle]['label'],
)), )),
'#pre_render' => array('field_ui_field_edit_instance_pre_render'), // Ensure field_ui_field_edit_instance_pre_render() gets called in addition
)); // to, not instead of, the #pre_render function(s) needed by all fieldsets.
'#pre_render' => array_merge(array('field_ui_field_edit_instance_pre_render'), element_info_property('fieldset', '#pre_render', array())),
);
// Build the non-configurable instance values. // Build the non-configurable instance values.
$form['instance']['field_name'] = array( $form['instance']['field_name'] = array(