Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
221
Merge Requests
221
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
5ff0c0d3
Commit
5ff0c0d3
authored
May 23, 2010
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Patch
#553298
by yched, te-brian, chx, sun: redesign the 'Manage Display' screen.
parent
5d4fa6f7
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
1154 additions
and
480 deletions
+1154
-480
includes/common.inc
includes/common.inc
+5
-0
modules/blog/blog.module
modules/blog/blog.module
+1
-1
modules/book/book.module
modules/book/book.module
+1
-0
modules/comment/comment.install
modules/comment/comment.install
+4
-2
modules/comment/comment.module
modules/comment/comment.module
+15
-11
modules/field/field.api.php
modules/field/field.api.php
+128
-39
modules/field/field.attach.inc
modules/field/field.attach.inc
+23
-6
modules/field/field.crud.inc
modules/field/field.crud.inc
+64
-25
modules/field/field.default.inc
modules/field/field.default.inc
+5
-7
modules/field/field.info.inc
modules/field/field.info.inc
+7
-2
modules/field/field.module
modules/field/field.module
+266
-42
modules/field/modules/text/text.test
modules/field/modules/text/text.test
+16
-6
modules/field/tests/field.test
modules/field/tests/field.test
+43
-39
modules/field/tests/field_test.entity.inc
modules/field/tests/field_test.entity.inc
+2
-0
modules/field_ui/field_ui.admin.inc
modules/field_ui/field_ui.admin.inc
+186
-81
modules/field_ui/field_ui.css
modules/field_ui/field_ui.css
+7
-0
modules/field_ui/field_ui.js
modules/field_ui/field_ui.js
+139
-0
modules/field_ui/field_ui.module
modules/field_ui/field_ui.module
+74
-126
modules/forum/forum.install
modules/forum/forum.install
+10
-0
modules/image/image.test
modules/image/image.test
+4
-4
modules/locale/locale.test
modules/locale/locale.test
+0
-10
modules/node/node.api.php
modules/node/node.api.php
+1
-1
modules/node/node.module
modules/node/node.module
+22
-7
modules/poll/poll.module
modules/poll/poll.module
+24
-10
modules/rdf/rdf.test
modules/rdf/rdf.test
+19
-10
modules/system/system.api.php
modules/system/system.api.php
+21
-4
modules/taxonomy/taxonomy.install
modules/taxonomy/taxonomy.install
+10
-0
modules/taxonomy/taxonomy.module
modules/taxonomy/taxonomy.module
+19
-9
modules/taxonomy/taxonomy.test
modules/taxonomy/taxonomy.test
+9
-4
modules/user/user.module
modules/user/user.module
+18
-13
profiles/standard/standard.install
profiles/standard/standard.install
+11
-21
No files found.
includes/common.inc
View file @
5ff0c0d3
...
...
@@ -6386,6 +6386,11 @@ function entity_get_info($entity_type = NULL) {
'revision'
=>
''
,
'bundle'
=>
''
,
);
foreach
(
$entity_info
[
$name
][
'view modes'
]
as
$view_mode
=>
$view_mode_info
)
{
$entity_info
[
$name
][
'view modes'
][
$view_mode
]
+=
array
(
'custom settings'
=>
FALSE
,
);
}
// If no bundle key is provided, assume a single bundle, named after
// the entity type.
if
(
empty
(
$entity_info
[
$name
][
'entity keys'
][
'bundle'
])
&&
empty
(
$entity_info
[
$name
][
'bundles'
]))
{
...
...
modules/blog/blog.module
View file @
5ff0c0d3
...
...
@@ -77,7 +77,7 @@ function blog_view($node, $view_mode) {
/**
* Implements hook_node_view().
*/
function
blog_node_view
(
$node
,
$view_mode
=
'full'
)
{
function
blog_node_view
(
$node
,
$view_mode
)
{
if
(
$view_mode
!=
'rss'
)
{
if
(
$node
->
type
==
'blog'
&&
(
arg
(
0
)
!=
'blog'
||
arg
(
1
)
!=
$node
->
uid
))
{
$links
[
'blog_usernames_blog'
]
=
array
(
...
...
modules/book/book.module
View file @
5ff0c0d3
...
...
@@ -240,6 +240,7 @@ function book_entity_info_alter(&$info) {
$info
[
'node'
][
'view modes'
]
+=
array
(
'print'
=>
array
(
'label'
=>
t
(
'Print'
),
'custom settings'
=>
FALSE
,
),
);
}
...
...
modules/comment/comment.install
View file @
5ff0c0d3
...
...
@@ -279,10 +279,12 @@ function comment_update_7012() {
'label'
=>
'Comment'
,
'entity_type'
=>
'comment'
,
'settings'
=>
array
(
'text_processing'
=>
1
),
// Hide field label by default.
'required'
=>
TRUE
,
'display'
=>
array
(
'
full
'
=>
array
(
'
default
'
=>
array
(
'label'
=>
'hidden'
,
'type'
=>
'text_default'
,
'weight'
=>
0
,
),
),
);
...
...
modules/comment/comment.module
View file @
5ff0c0d3
...
...
@@ -108,6 +108,7 @@ function comment_entity_info() {
'view modes'
=>
array
(
'full'
=>
array
(
'label'
=>
t
(
'Full comment'
),
'custom settings'
=>
FALSE
,
),
),
'static cache'
=>
FALSE
,
...
...
@@ -165,15 +166,17 @@ function comment_field_extra_fields() {
foreach
(
node_type_get_types
()
as
$type
)
{
if
(
variable_get
(
'comment_subject_field_'
.
$type
->
type
,
1
)
==
1
)
{
$return
[
'comment'
][
'comment_node_'
.
$type
->
type
]
=
array
(
'author'
=>
array
(
'label'
=>
t
(
'Author'
),
'description'
=>
t
(
'Author textfield'
),
'weight'
=>
-
2
,
),
'title'
=>
array
(
'label'
=>
t
(
'Subject'
),
'description'
=>
t
(
'Subject textfield'
),
'weight'
=>
-
1
,
'form'
=>
array
(
'author'
=>
array
(
'label'
=>
t
(
'Author'
),
'description'
=>
t
(
'Author textfield'
),
'weight'
=>
-
2
,
),
'title'
=>
array
(
'label'
=>
t
(
'Subject'
),
'description'
=>
t
(
'Subject textfield'
),
'weight'
=>
-
1
,
),
),
);
}
...
...
@@ -362,10 +365,11 @@ function _comment_body_field_instance_create($info) {
'bundle'
=>
'comment_node_'
.
$info
->
type
,
'settings'
=>
array
(
'text_processing'
=>
1
),
'required'
=>
TRUE
,
// Hides field label by default.
'display'
=>
array
(
'
full
'
=>
array
(
'
default
'
=>
array
(
'label'
=>
'hidden'
,
'type'
=>
'text_default'
,
'weight'
=>
0
,
),
),
);
...
...
modules/field/field.api.php
View file @
5ff0c0d3
...
...
@@ -7,55 +7,59 @@
*/
/**
* Expose "pseudo-field" components on fieldable entities.
* Expose
s
"pseudo-field" components on fieldable entities.
*
* Field UI's
'Manage fields' page lets users re-order fields, but also
*
non-field components. For nodes, these include the title, menu settings, and
*
other elements exposed by contributed modules through hook_form() and
* Field UI's
"Manage fields" and "Manage display" pages let users re-order
*
fields, but also non-field components. For nodes, these include the title,
*
poll choices, and other elements exposed by modules through hook_form() or
* hook_form_alter().
*
* Fieldable entities or contributed modules that want to have their components
* supported should expose them using this hook, and use
* field_attach_extra_weight() to retrieve the user-defined weight when
* inserting the component.
* Fieldable entities or modules that want to have their components supported
* should expose them using this hook. The user-defined settings (weight,
* visibility) are automatically applied on rendered forms and displayed
* entities in a #pre_render callback added by field_attach_form() and
* field_attach_view().
*
* @see _field_extra_fields_pre_render()
* @see hook_field_extra_fields_alter()
*
* @return
* A nested array of 'pseudo-field' components. Each list is nested within the
* field bundle to which those components apply. The keys are the name of the
* element as it appears in the form structure. The values are arrays with the
* following key/value pairs:
* A nested array of 'pseudo-field' components. Each list is nested within
* the following keys: entity type, bundle name, context (either 'form' or
* 'display'). The keys are the name of the elements as appearing in the
* renderable array (either the entity form or the displayed entity). The
* value is an associative array:
* - label: The human readable name of the component.
* - description: A short description of the component contents.
* - weight: The default weight of the element.
* - view: (optional) The name of the element as it appears in the rendered
* structure, if different from the name in the form.
*
* @see hook_field_extra_fields_alter()
*/
function
hook_field_extra_fields
()
{
$extra
=
array
();
foreach
(
node_type_get_types
()
as
$bundle
)
{
if
(
$type
->
has_title
)
{
$extra
[
'node'
][
$bundle
][
'title'
]
=
array
(
'label'
=>
$type
->
title_label
,
'description'
=>
t
(
'Node module element.'
),
'weight'
=>
-
5
,
);
}
}
if
(
module_exists
(
'poll'
))
{
$extra
[
'node'
][
'poll'
][
'choice_wrapper'
]
=
array
(
'label'
=>
t
(
'Poll choices'
),
'description'
=>
t
(
'Poll module choices.'
),
'weight'
=>
-
4
,
);
$extra
[
'node'
][
'poll'
][
'settings'
]
=
array
(
'label'
=>
t
(
'Poll settings'
),
'description'
=>
t
(
'Poll module settings.'
),
'weight'
=>
-
3
,
);
}
$extra
[
'node'
][
'poll'
]
=
array
(
'form'
=>
array
(
'choice_wrapper'
=>
array
(
'label'
=>
t
(
'Poll choices'
),
'description'
=>
t
(
'Poll choices'
),
'weight'
=>
-
4
,
),
'settings'
=>
array
(
'label'
=>
t
(
'Poll settings'
),
'description'
=>
t
(
'Poll module settings'
),
'weight'
=>
-
3
,
),
),
'display'
=>
array
(
'poll_view_voting'
=>
array
(
'label'
=>
t
(
'Poll vote'
),
'description'
=>
t
(
'Poll vote'
),
'weight'
=>
0
,
),
'poll_view_results'
=>
array
(
'label'
=>
t
(
'Poll results'
),
'description'
=>
t
(
'Poll results'
),
'weight'
=>
0
,
),
)
);
return
$extra
;
}
...
...
@@ -1651,6 +1655,91 @@ function hook_field_storage_pre_query($field_name, $conditions, $options, &$skip
// @todo Needs function body.
}
/**
* Alters the display settings of a field before it gets displayed.
*
* Note that instead of hook_field_display_alter(), which is called for all
* fields on all entity types, hook_field_display_ENTITY_TYPE_alter() may be
* used to alter display settings for fields on a specific entity type only.
*
* This hook is called once per field per displayed entity. If the result of the
* hook involves reading from the database, it is highly recommended to
* statically cache the information.
*
* @param $display
* The display settings that will be used to display the field values, as
* found in the 'display' key of $instance definitions.
* @param $context
* An associative array containing:
* - entity_type: The entity type; e.g. 'node' or 'user'.
* - field: The field being rendered.
* - instance: The instance being rendered.
* - view_mode: The view mode, e.g. 'full', 'teaser'...
*
* @see hook_field_display_ENTITY_TYPE_alter()
*/
function
hook_field_display_alter
(
&
$display
,
$context
)
{
// Leave field labels out of the search index.
// Note: The check against $context['entity_type'] == 'node' could be avoided
// by using hook_field_display_node_alter() instead of
// hook_field_display_alter(), resulting in less function calls when
// rendering non-node entities.
if
(
$context
[
'entity_type'
]
==
'node'
&&
$context
[
'view_mode'
]
==
'search_index'
)
{
$display
[
'label'
]
=
'hidden'
;
}
}
/**
* Alters the display settings of a field on a given entity type before it gets displayed.
*
* Modules can implement hook_field_display_ENTITY_TYPE_alter() to alter display
* settings for fields on a specific entity type, rather than implementing
* hook_field_display_alter().
*
* This hook is called once per field per displayed entity. If the result of the
* hook involves reading from the database, it is highly recommended to
* statically cache the information.
*
* @param $display
* The display settings that will be used to display the field values, as
* found in the 'display' key of $instance definitions.
* @param $context
* An associative array containing:
* - entity_type: The entity type; e.g. 'node' or 'user'.
* - field: The field being rendered.
* - instance: The instance being rendered.
* - view_mode: The view mode, e.g. 'full', 'teaser'...
*
* @see hook_field_display_alter()
*/
function
hook_field_display_ENTITY_TYPE_alter
(
&
$display
,
$context
)
{
// Leave field labels out of the search index.
if
(
$context
[
'view_mode'
]
==
'search_index'
)
{
$display
[
'label'
]
=
'hidden'
;
}
}
/**
* Alters the display settings of pseudo-fields before an entity is displayed.
*
* This hook is called once per displayed entity. If the result of the hook
* involves reading from the database, it is highly recommended to statically
* cache the information.
*
* @param $displays
* An array of display settings for the pseudo-fields in the entity, keyed
* by pseudo-field names.
* @param $context
* An associative array containing:
* - entity_type: The entity type; e.g. 'node' or 'user'.
* - bundle: The bundle name.
* - view_mode: The view mode, e.g. 'full', 'teaser'...
*/
function
hook_field_extra_fields_display_alter
(
&
$displays
,
$context
)
{
if
(
$context
[
'entity_type'
]
==
'taxonomy_term'
&&
$context
[
'view_mode'
]
==
'full'
)
{
$displays
[
'description'
][
'visibility'
]
=
FALSE
;
}
}
/**
* @} End of "ingroup field_storage"
*/
...
...
modules/field/field.attach.inc
View file @
5ff0c0d3
...
...
@@ -552,8 +552,9 @@ function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcod
// Add custom weight handling.
list
(
$id
,
$vid
,
$bundle
)
=
entity_extract_ids
(
$entity_type
,
$entity
);
$form
[
'#attached'
][
'css'
][]
=
drupal_get_path
(
'module'
,
'field'
)
.
'/theme/field.css'
;
$form
[
'#pre_render'
][]
=
'_field_extra_weights_pre_render'
;
$form
[
'#extra_fields'
]
=
field_extra_fields
(
$entity_type
,
$bundle
);
$form
[
'#pre_render'
][]
=
'_field_extra_fields_pre_render'
;
$form
[
'#entity_type'
]
=
$entity_type
;
$form
[
'#bundle'
]
=
$bundle
;
// Save the original entity to allow later re-use.
$form_state
[
'entity'
]
=
$entity
;
...
...
@@ -1185,7 +1186,7 @@ function field_attach_query_revisions($field_id, $conditions, $options = array()
* @param $view_mode
* View mode, e.g. 'full', 'teaser'...
*/
function
field_attach_prepare_view
(
$entity_type
,
$entities
,
$view_mode
=
'full'
)
{
function
field_attach_prepare_view
(
$entity_type
,
$entities
,
$view_mode
)
{
// To ensure hooks are only run once per entity, only process items without
// the _field_view_prepared flag.
// @todo: resolve this more generally for both entity and field level hooks.
...
...
@@ -1250,7 +1251,7 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode = 'full')
* @return
* A renderable array for the field values.
*/
function
field_attach_view
(
$entity_type
,
$entity
,
$view_mode
=
'full'
,
$langcode
=
NULL
)
{
function
field_attach_view
(
$entity_type
,
$entity
,
$view_mode
,
$langcode
=
NULL
)
{
// Determine the actual language to display for each field, given the
// languages available in the field data.
$display_language
=
field_language
(
$entity_type
,
$entity
,
NULL
,
$langcode
);
...
...
@@ -1262,8 +1263,9 @@ function field_attach_view($entity_type, $entity, $view_mode = 'full', $langcode
// Add custom weight handling.
list
(
$id
,
$vid
,
$bundle
)
=
entity_extract_ids
(
$entity_type
,
$entity
);
$output
[
'#pre_render'
][]
=
'_field_extra_weights_pre_render'
;
$output
[
'#extra_fields'
]
=
field_extra_fields
(
$entity_type
,
$bundle
);
$output
[
'#pre_render'
][]
=
'_field_extra_fields_pre_render'
;
$output
[
'#entity_type'
]
=
$entity_type
;
$output
[
'#bundle'
]
=
$bundle
;
// Include CSS styles.
$output
[
'#attached'
][
'css'
][]
=
drupal_get_path
(
'module'
,
'field'
)
.
'/theme/field.css'
;
...
...
@@ -1381,6 +1383,14 @@ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
// Clear the cache.
field_cache_clear
();
// Update bundle settings.
$settings
=
variable_get
(
'field_bundle_settings'
,
array
());
if
(
isset
(
$settings
[
$entity_type
][
$bundle_old
]))
{
$settings
[
$entity_type
][
$bundle_new
]
=
$settings
[
$entity_type
][
$bundle_old
];
unset
(
$settings
[
$entity_type
][
$bundle_old
]);
variable_set
(
'field_bundle_settings'
,
$settings
);
}
// Let other modules act on renaming the bundle.
module_invoke_all
(
'field_attach_rename_bundle'
,
$entity_type
,
$bundle_old
,
$bundle_new
);
}
...
...
@@ -1410,6 +1420,13 @@ function field_attach_delete_bundle($entity_type, $bundle) {
// Clear the cache.
field_cache_clear
();
// Clear bundle display settings.
$settings
=
variable_get
(
'field_bundle_settings'
,
array
());
if
(
isset
(
$settings
[
$entity_type
][
$bundle
]))
{
unset
(
$settings
[
$entity_type
][
$bundle
]);
variable_set
(
'field_bundle_settings'
,
$settings
);
}
// Let other modules act on deleting the bundle.
module_invoke_all
(
'field_attach_delete_bundle'
,
$entity_type
,
$bundle
,
$instances
);
}
...
...
modules/field/field.crud.inc
View file @
5ff0c0d3
...
...
@@ -31,8 +31,7 @@
* field_attach_load() then loads the 'subtitle' and 'photo' fields
* because they are both attached to the 'node' bundle 'article'.
*
* Field definitions are (currently) represented as an array of key/value
* pairs. The array properties are:
* Field definitions are represented as an array of key/value pairs.
*
* @param array $field:
* - id (integer, read-only)
...
...
@@ -96,8 +95,7 @@
* A sub-array of key/value pairs of settings. Each storage backend
* defines and documents its own settings.
*
* Field Instance definitions are (currently) represented as an array of
* key/value pairs. The array properties are:
* Field instance definitions are represented as an array of key/value pairs.
*
* @param array $instance:
* - id (integer, read-only)
...
...
@@ -154,11 +152,20 @@
* - module (string, read-only)
* The name of the module that implements the widget type.
* - display (array)
* A sub-array of key/value pairs identifying view modes and the way the
* field values should be displayed in each mode.
* - full (array)
* A sub-array of key/value pairs of the display options to be used
* when the field is being displayed in the "full" view mode.
* A sub-array of key/value pairs identifying the way field values should
* be displayed in each of the entity type's view modes, plus the 'default'
* mode. For each view mode, Field UI lets site administrators define
* whether they want to use a dedicated set of display options or the
* 'default' options to reduce the number of displays to maintain as they
* add new fields. For nodes, on a fresh install, only the 'teaser' view
* mode is configured to use custom display options, all other view modes
* defined use the 'default' options by default. When programmatically
* adding field instances on nodes, it is therefore recommended to at least
* specify display options for 'default' and 'teaser'.
* - default (array)
* A sub-array of key/value pairs describing the display options to be
* used when the field is being displayed in view modes that are not
* configured to use dedicated display options.
* - label (string)
* Position of the label. 'inline', 'above' and 'hidden' are the
* values recognized by the default 'field' theme implementation.
...
...
@@ -172,7 +179,11 @@
* displayed in this view mode.
* - module (string, read-only)
* The name of the module which implements the display formatter.
* - teaser
* - some_mode
* A sub-array of key/value pairs describing the display options to be
* used when the field is being displayed in the 'some_mode' view mode.
* Those options will only be actually applied at run time if the view
* mode is not configured to use default settings for this bundle.
* - ...
* - other_mode
* - ...
...
...
@@ -607,12 +618,16 @@ function field_delete_field($field_name) {
* - settings: each omitted setting is given the default value specified in
* hook_field_widget_info().
* - display:
* Settings for the 'full' view mode will be added, and each view mode
* will be completed with the following default values:
* Settings for the 'default' view mode will be added if not present, and
* each view mode in the definition will be completed with the following
* default values:
* - label: 'above'
* - type: the default formatter specified in hook_field_info().
* - settings: each omitted setting is given the default value specified in
* hook_field_formatter_info().
* View modes not present in the definition are left empty, and the field
* will not be displayed in this mode.
*
* @return
* The $instance array with the id property filled in.
* @throw
...
...
@@ -730,7 +745,6 @@ function _field_write_instance($instance, $update = FALSE) {
'required'
=>
FALSE
,
'label'
=>
$instance
[
'field_name'
],
'description'
=>
''
,
'weight'
=>
0
,
'deleted'
=>
0
,
);
...
...
@@ -742,30 +756,55 @@ function _field_write_instance($instance, $update = FALSE) {
// TODO: what if no 'default_widget' specified ?
'type'
=>
$field_type
[
'default_widget'
],
'settings'
=>
array
(),
'weight'
=>
0
,
);
// If no weight specified, make sure the field sinks at the bottom.
if
(
!
isset
(
$instance
[
'widget'
][
'weight'
]))
{
$weights
=
array
();
foreach
(
field_info_instances
(
$instance
[
'entity_type'
],
$instance
[
'bundle'
])
as
$existing_instance
)
{
if
(
$instance
[
'field_name'
]
!=
$existing_instance
[
'field_name'
])
{
$weights
[]
=
$existing_instance
[
'widget'
][
'weight'
];
}
}
foreach
(
field_extra_fields
(
$instance
[
'entity_type'
],
$instance
[
'bundle'
],
'form'
)
as
$extra
)
{
$weights
[]
=
$extra
[
'weight'
];
}
$instance
[
'widget'
][
'weight'
]
=
$weights
?
max
(
$weights
)
+
1
:
0
;
}
// Check widget module.
$widget_type
=
field_info_widget_types
(
$instance
[
'widget'
][
'type'
]);
$instance
[
'widget'
][
'module'
]
=
$widget_type
[
'module'
];
$instance
[
'widget'
][
'settings'
]
+=
field_info_widget_settings
(
$instance
[
'widget'
][
'type'
]);
// Make sure there is at least display info for the 'full' view mode.
// Make sure there are at least display settings for the 'default' view mode,
// and fill in defaults for each view mode specified in the definition.
$instance
[
'display'
]
+=
array
(
'
full
'
=>
array
(),
'
default
'
=>
array
(),
);
// Set default display settings for each view mode.
foreach
(
$instance
[
'display'
]
as
$view_mode
=>
$display
)
{
$
instance
[
'display'
][
$view_mode
]
+=
array
(
$
display
+=
array
(
'label'
=>
'above'
,
// TODO: what if no 'default_formatter' specified ?
'type'
=>
$field_type
[
'default_formatter'
],
'type'
=>
isset
(
$field_type
[
'default_formatter'
])
?
$field_type
[
'default_formatter'
]
:
'hidden'
,
'settings'
=>
array
(),
'weight'
=>
0
,
);
$formatter_type
=
field_info_formatter_types
(
$instance
[
'display'
][
$view_mode
][
'type'
]);
// TODO : 'hidden' will raise PHP warnings.
$instance
[
'display'
][
$view_mode
][
'module'
]
=
$formatter_type
[
'module'
];
$instance
[
'display'
][
$view_mode
][
'settings'
]
+=
field_info_formatter_settings
(
$instance
[
'display'
][
$view_mode
][
'type'
]);
if
(
$display
[
'type'
]
!=
'hidden'
)
{
$formatter_type
=
field_info_formatter_types
(
$display
[
'type'
]);
$display
[
'module'
]
=
$formatter_type
[
'module'
];
$display
[
'settings'
]
+=
field_info_formatter_settings
(
$display
[
'type'
]);
}
// If no weight specified, make sure the field sinks at the bottom.
if
(
!
isset
(
$display
[
'weight'
]))
{
$weights
=
array
();
foreach
(
field_info_instances
(
$instance
[
'entity_type'
],
$instance
[
'bundle'
])
as
$existing_instance
)
{
if
(
$instance
[
'field_name'
]
!=
$existing_instance
[
'field_name'
])
{
$weights
[]
=
$existing_instance
[
'display'
][
$view_mode
][
'weight'
];
}
}
foreach
(
field_extra_fields
(
$instance
[
'entity_type'
],
$instance
[
'bundle'
],
'display'
)
as
$extra
)
{
$weights
[]
=
$extra
[
'display'
][
$view_mode
][
'weight'
];
}
$display
[
'weight'
]
=
$weights
?
max
(
$weights
)
+
1
:
0
;
}
$instance
[
'display'
][
$view_mode
]
=
$display
;
}
// The serialized 'data' column contains everything from $instance that does
...
...
modules/field/field.default.inc
View file @
5ff0c0d3
...
...
@@ -132,7 +132,10 @@ function field_default_prepare_view($entity_type, $entities, $field, $instances,
// Group entities, instances and items by formatter module.
$modules
=
array
();
foreach
(
$instances
as
$id
=>
$instance
)
{
$display
=
is_string
(
$display
)
?
$instance
[
'display'
][
$display
]
:
$display
;
if
(
is_string
(
$display
))
{
$view_mode
=
$display
;
$display
=
field_get_display
(
$instance
,
$view_mode
);
}
if
(
$display
[
'type'
]
!==
'hidden'
)
{
$module
=
$display
[
'module'
];
$modules
[
$module
]
=
$module
;
...
...
@@ -183,18 +186,13 @@ function field_default_view($entity_type, $entity, $field, $instance, $langcode,
// Prepare incoming display specifications.
if
(
is_string
(
$display
))
{
$view_mode
=
$display
;
$display
=
$instance
[
'display'
][
$view_mode
]
;
$display
=
field_get_display
(
$instance
,
$view_mode
)
;
}
else
{
$view_mode
=
'_custom_display'
;
}
if
(
$display
[
'type'
]
!==
'hidden'
)
{
// We never want to index fields labels.
if
(
$view_mode
==
'search_index'
)
{
$display
[
'label'
]
=
'hidden'
;
}
// Calling the formatter function through module_invoke() can have a
// performance impact on pages with many fields and values.
$function
=
$display
[
'module'
]
.
'_field_formatter_view'
;
...
...
modules/field/field.info.inc
View file @
5ff0c0d3
...
...
@@ -290,11 +290,16 @@ function _field_info_prepare_instance($instance, $field) {
$instance
[
'display'
][
$view_mode
]
=
_field_info_prepare_instance_display
(
$field
,
$display
);
}
// Fallback to '
full' display settings
for unspecified view modes.
// Fallback to '
hidden'
for unspecified view modes.
$entity_info
=
entity_get_info
(
$instance
[
'entity_type'
]);
foreach
(
$entity_info
[
'view modes'
]
as
$view_mode
=>
$info
)
{
if
(
!
isset
(
$instance
[
'display'
][
$view_mode
]))
{
$instance
[
'display'
][
$view_mode
]
=
$instance
[
'display'
][
'full'
];
$instance
[
'display'
][
$view_mode
]
=
array
(
'type'
=>
'hidden'
,
'label'
=>
'above'
,
'settings'
=>
array
(),
'weight'
=>
0
,
);
}
}
...
...
modules/field/field.module
View file @
5ff0c0d3
...
...
@@ -365,75 +365,308 @@ function _field_sort_items_value_helper($a, $b) {
}
/**
* Registry of pseudo-field components in a given bundle.
* Gets or sets administratively defined bundle settings.
*
* For each bundle, settings are provided as a nested array with the following
* structure:
* @code
* array(
* 'view_modes' => array(
* // One sub-array per view mode for the entity type:
* 'full' => array(
* 'custom_display' => Whether the view mode uses custom display
* settings or settings of the 'default' mode,
* ),
* 'teaser' => ...
* ),
* 'extra_fields' => array(
* 'form' => array(
* // One sub-array per pseudo-field in displayed entities:
* 'extra_field_1' => array(
* 'weight' => The weight of the pseudo-field,
* ),
* 'extra_field_2' => ...
* ),
* 'display' => array(
* // One sub-array per pseudo-field in displayed entities:
* 'extra_field_1' => array(
* // One sub-array per view mode for the entity type, including
* // the 'default' mode:
* 'default' => array(
* 'weight' => The weight of the pseudo-field,
* 'visibility' => Whether the pseudo-field is visible or hidden,
* ),
* 'full' => ...
* ),
* 'extra_field_2' => ...
* ),
* ),
* ),
* @encode
*
* @param $entity_type
* The type of $entity; e.g. 'node' or 'user'.
* @param $bundle
* The bundle name.
* @param $settings
* (optional) The settings to store.
*
* @return
* If no $settings are passed, the current settings are returned.
*/
function
field_bundle_settings
(
$entity_type
,
$bundle
,
$settings
=
NULL
)
{
$stored_settings
=
variable_get
(
'field_bundle_settings'
,
array
());
if
(
isset
(
$settings
))
{
$stored_settings
[
$entity_type
][
$bundle
]
=
$settings
;
variable_set
(
'field_bundle_settings'
,
$stored_settings
);
drupal_static_reset
(
'field_view_mode_settings'
);
drupal_static_reset
(
'field_extra_fields'
);
}
else
{
$settings
=
isset
(
$stored_settings
[
$entity_type
][
$bundle
])
?
$stored_settings
[
$entity_type
][
$bundle
]
:
array
();
$settings
+=
array
(
'view_modes'
=>
array
(),
'extra_fields'
=>
array
(),
);
return
$settings
;
}
}