#529756 by yched: Allow fields to be weighted per context.
parent
7a36d6a03c
commit
00ad7e8e03
|
@ -97,11 +97,6 @@
|
|||
* A human-readable description for the field when used with this
|
||||
* bundle. For example, the description will be the help text of
|
||||
* Form API elements for this instance.
|
||||
* - weight (float)
|
||||
* The order in which the field should be sorted relative
|
||||
* to other fields when used with this bundle. The weight affects
|
||||
* ordering in both forms (see field_attach_form()) and rendered output
|
||||
* (see field_attach_view()).
|
||||
* - required (integer)
|
||||
* TRUE if a value for this field is required when used with this
|
||||
* bundle, FALSE otherwise. Currently, required-ness is only enforced
|
||||
|
@ -124,15 +119,18 @@
|
|||
* - type (string)
|
||||
* The type of the widget, such as text_textfield. Widget types
|
||||
* are defined by modules that implement hook_field_widget_info().
|
||||
* - settings (array)
|
||||
* A sub-array of key/value pairs of widget-type-specific settings.
|
||||
* Each field widget type module defines and documents its own
|
||||
* widget settings.
|
||||
* - weight (float)
|
||||
* The weight of the widget relative to the other elements in object
|
||||
* edit forms.
|
||||
* - module (string, read-only)
|
||||
* The name of the module that implements the widget type.
|
||||
* - active (integer, read-only)
|
||||
* TRUE if the module that implements the widget type is currently
|
||||
* enabled, FALSE otherwise.
|
||||
* - settings (array)
|
||||
* A sub-array of key/value pairs of widget-type-specific settings.
|
||||
* Each field widget type module defines and documents its own
|
||||
* widget settings.
|
||||
* - display (array)
|
||||
* A sub-array of key/value pairs identifying build modes and the way the
|
||||
* field values should be displayed in each build mode.
|
||||
|
@ -147,6 +145,9 @@
|
|||
* - settings (array)
|
||||
* A sub-array of key/value pairs of display options specific to
|
||||
* the formatter.
|
||||
* - weight (float)
|
||||
* The weight of the field relative to the other object components
|
||||
* displayed in this build mode.
|
||||
* - module (string, read-only)
|
||||
* The name of the module which implements the display formatter.
|
||||
* - teaser
|
||||
|
@ -530,6 +531,7 @@ function _field_write_instance($instance, $update = FALSE) {
|
|||
// TODO: what if no 'default_widget' specified ?
|
||||
'type' => $field_type['default_widget'],
|
||||
'settings' => array(),
|
||||
'weight' => 0,
|
||||
);
|
||||
// Check widget module.
|
||||
$widget_type = field_info_widget_types($instance['widget']['type']);
|
||||
|
@ -550,6 +552,7 @@ function _field_write_instance($instance, $update = FALSE) {
|
|||
// TODO: what if no 'default_formatter' specified ?
|
||||
'type' => $field_type['default_formatter'],
|
||||
'settings' => array(),
|
||||
'weight' => 0,
|
||||
);
|
||||
$formatter_type = field_info_formatter_types($instance['display'][$build_mode]['type']);
|
||||
// TODO : 'hidden' will raise PHP warnings.
|
||||
|
@ -561,7 +564,7 @@ function _field_write_instance($instance, $update = FALSE) {
|
|||
// not have its own column and is not automatically populated when the
|
||||
// instance is read.
|
||||
$data = $instance;
|
||||
unset($data['id'], $data['field_id'], $data['field_name'], $data['bundle'], $data['widget']['type'], $data['weight'], $data['deleted']);
|
||||
unset($data['id'], $data['field_id'], $data['field_name'], $data['bundle'], $data['widget']['type'], $data['deleted']);
|
||||
|
||||
$record = array(
|
||||
'field_id' => $instance['field_id'],
|
||||
|
@ -570,7 +573,6 @@ function _field_write_instance($instance, $update = FALSE) {
|
|||
'widget_type' => $instance['widget']['type'],
|
||||
'widget_module' => $widget_module,
|
||||
'widget_active' => $widget_active,
|
||||
'weight' => $instance['weight'],
|
||||
'data' => $data,
|
||||
'deleted' => $instance['deleted'],
|
||||
);
|
||||
|
@ -653,7 +655,6 @@ function field_read_instances($params = array(), $include_additional = array())
|
|||
$instance['field_id'] = $record['field_id'];
|
||||
$instance['field_name'] = $record['field_name'];
|
||||
$instance['bundle'] = $record['bundle'];
|
||||
$instance['weight'] = $record['weight'];
|
||||
$instance['deleted'] = $record['deleted'];
|
||||
$instance['widget']['type'] = $record['widget_type'];
|
||||
$instance['widget']['module'] = $record['widget_module'];
|
||||
|
|
|
@ -79,7 +79,7 @@ function field_default_view($obj_type, $object, $field, $instance, $items, $buil
|
|||
|
||||
$element = $info + array(
|
||||
'#theme' => 'field',
|
||||
'#weight' => $instance['weight'],
|
||||
'#weight' => $display['weight'],
|
||||
'#title' => check_plain(t($instance['label'])),
|
||||
'#access' => field_access('view', $field),
|
||||
'#label_display' => $label_display,
|
||||
|
|
|
@ -90,7 +90,7 @@ function field_default_form($obj_type, $object, $field, $instance, $items, &$for
|
|||
$defaults = array(
|
||||
'#field_name' => $field['field_name'],
|
||||
'#tree' => TRUE,
|
||||
'#weight' => $instance['weight'],
|
||||
'#weight' => $instance['widget']['weight'],
|
||||
);
|
||||
|
||||
$addition[$field['field_name']] = array_merge($form_element, $defaults);
|
||||
|
@ -188,7 +188,6 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
|
|||
'#type' => 'submit',
|
||||
'#name' => $field_name . '_add_more',
|
||||
'#value' => t('Add another item'),
|
||||
'#weight' => $instance['weight'] + $max + 1,
|
||||
// Submit callback for disabled JavaScript.
|
||||
'#submit' => array('field_add_more_submit'),
|
||||
'#ahah' => array(
|
||||
|
|
|
@ -116,11 +116,6 @@ function field_schema() {
|
|||
'not null' => TRUE,
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
'weight' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'deleted' => array(
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
|
|
|
@ -1709,21 +1709,23 @@ class FieldInstanceCrudTestCase extends DrupalWebTestCase {
|
|||
// Check that basic changes are saved.
|
||||
$instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
|
||||
$instance['required'] = !$instance['required'];
|
||||
$instance['weight']++;
|
||||
$instance['label'] = $this->randomName();
|
||||
$instance['description'] = $this->randomName();
|
||||
$instance['settings']['test_instance_setting'] = $this->randomName();
|
||||
$instance['widget']['settings']['test_widget_setting'] =$this->randomName();
|
||||
$instance['widget']['weight']++;
|
||||
$instance['display']['full']['settings']['test_formatter_setting'] = $this->randomName();
|
||||
$instance['display']['full']['weight']++;
|
||||
field_update_instance($instance);
|
||||
|
||||
$instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
|
||||
$this->assertEqual($instance['required'], $instance_new['required'], t('"required" change is saved'));
|
||||
$this->assertEqual($instance['weight'], $instance_new['weight'], t('"weight" change is saved'));
|
||||
$this->assertEqual($instance['label'], $instance_new['label'], t('"label" change is saved'));
|
||||
$this->assertEqual($instance['description'], $instance_new['description'], t('"description" change is saved'));
|
||||
$this->assertEqual($instance['widget']['settings']['test_widget_setting'], $instance_new['widget']['settings']['test_widget_setting'], t('Widget setting change is saved'));
|
||||
$this->assertEqual($instance['widget']['weight'], $instance_new['widget']['weight'], t('Widget weight change is saved'));
|
||||
$this->assertEqual($instance['display']['full']['settings']['test_formatter_setting'], $instance_new['display']['full']['settings']['test_formatter_setting'], t('Formatter setting change is saved'));
|
||||
$this->assertEqual($instance['display']['full']['weight'], $instance_new['display']['full']['weight'], t('Widget weight change is saved'));
|
||||
|
||||
// Check that changing widget and formatter types updates the default settings.
|
||||
$instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
|
||||
|
|
Loading…
Reference in New Issue