Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
375a7081
Commit
375a7081
authored
Aug 20, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2067127
by yched: Reorganize the contents of field.* files.
parent
9ef3a52f
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1300 additions
and
1308 deletions
+1300
-1308
core/modules/field/field.attach.inc
core/modules/field/field.attach.inc
+0
-778
core/modules/field/field.deprecated.inc
core/modules/field/field.deprecated.inc
+1190
-0
core/modules/field/field.form.inc
core/modules/field/field.form.inc
+11
-0
core/modules/field/field.info.inc
core/modules/field/field.info.inc
+0
-312
core/modules/field/field.module
core/modules/field/field.module
+54
-73
core/modules/field/field.multilingual.inc
core/modules/field/field.multilingual.inc
+45
-2
core/modules/field/field.purge.inc
core/modules/field/field.purge.inc
+0
-143
No files found.
core/modules/field/field.attach.inc
View file @
375a7081
This diff is collapsed.
Click to expand it.
core/modules/field/field.deprecated.inc
0 → 100644
View file @
375a7081
This diff is collapsed.
Click to expand it.
core/modules/field/field.form.inc
View file @
375a7081
...
...
@@ -94,6 +94,17 @@ function theme_field_multiple_value_form($variables) {
return
$output
;
}
/**
* Callback for usort() within theme_field_multiple_value_form().
*
* Sorts using ['_weight']['#value']
*/
function
_field_sort_items_value_helper
(
$a
,
$b
)
{
$a_weight
=
(
is_array
(
$a
)
&&
isset
(
$a
[
'_weight'
][
'#value'
])
?
$a
[
'_weight'
][
'#value'
]
:
0
);
$b_weight
=
(
is_array
(
$b
)
&&
isset
(
$b
[
'_weight'
][
'#value'
])
?
$b
[
'_weight'
][
'#value'
]
:
0
);
return
$a_weight
-
$b_weight
;
}
/**
* After-build callback for field elements in a form.
*
...
...
core/modules/field/field.info.inc
View file @
375a7081
...
...
@@ -7,7 +7,6 @@
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Language\Language
;
use
Drupal\field\Entity\FieldInstance
;
use
Drupal\field\Field
;
/**
...
...
@@ -135,110 +134,6 @@ function field_behaviors_widget($op, $instance) {
return
isset
(
$info
[
$op
])
?
$info
[
$op
]
:
FIELD_BEHAVIOR_DEFAULT
;
}
/**
* Returns a lightweight map of fields across bundles.
*
* The function only returns active, non deleted fields.
*
* @return
* An array keyed by field name. Each value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears, as an array with entity
* types as keys and the array of bundle names as values.
* Example:
* @code
* array(
* 'body' => array(
* 'bundles' => array(
* 'node' => array('page', 'article'),
* ),
* 'type' => 'text_with_summary',
* ),
* );
* @endcode
*
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getFieldMap().
*/
function
field_info_field_map
()
{
return
Field
::
fieldInfo
()
->
getFieldMap
();
}
/**
* Returns information about field types.
*
* @param $field_type
* (optional) A field type name. If omitted, all field types will be returned.
*
* @return
* Either a field type definition, or an array of all existing field types,
* keyed by field type name.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.entity.field.field_type')->getDefinition()
* or
* Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions()
*/
function
field_info_field_types
(
$field_type
=
NULL
)
{
if
(
$field_type
)
{
return
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefinition
(
$field_type
);
}
else
{
return
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefinitions
();
}
}
/**
* Returns information about field widgets from AnnotatedClassDiscovery.
*
* @param string $widget_type
* (optional) A widget type name. If omitted, all widget types will be
* returned.
*
* @return array
* Either a single widget type description, as provided by class annotations,
* or an array of all existing widget types, keyed by widget type name.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.widget')->getDefinition()
* or
* Drupal::service('plugin.manager.field.widget')->getDefinitions()
*/
function
field_info_widget_types
(
$widget_type
=
NULL
)
{
if
(
$widget_type
)
{
return
drupal_container
()
->
get
(
'plugin.manager.field.widget'
)
->
getDefinition
(
$widget_type
);
}
else
{
return
drupal_container
()
->
get
(
'plugin.manager.field.widget'
)
->
getDefinitions
();
}
}
/**
* Returns information about field formatters from hook_field_formatter_info().
*
* @param string $formatter_type
* (optional) A formatter type name. If omitted, all formatter types will be
* returned.
*
* @return array
* Either a single formatter type description, as provided by class
* annotations, or an array of all existing formatter types, keyed by
* formatter type name.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.formatter')->getDefinition()
* or
* Drupal::service('plugin.manager.field.formatter')->getDefinitions()
*/
function
field_info_formatter_types
(
$formatter_type
=
NULL
)
{
if
(
$formatter_type
)
{
return
drupal_container
()
->
get
(
'plugin.manager.field.formatter'
)
->
getDefinition
(
$formatter_type
);
}
else
{
return
drupal_container
()
->
get
(
'plugin.manager.field.formatter'
)
->
getDefinitions
();
}
}
/**
* Returns information about field storage from hook_field_storage_info().
*
...
...
@@ -295,144 +190,7 @@ function field_info_fields() {
return
$fields
;
}
/**
* Returns data about an individual field, given a field name.
*
* @param $field_name
* The name of the field to retrieve. $field_name can only refer to a
* non-deleted, active field. For deleted fields, use
* field_info_field_by_id(). To retrieve information about inactive fields,
* use field_read_fields().
*
* @return
* The field array, as returned by field_read_fields(), with an
* additional element 'bundles', whose value is an array of all the bundles
* this field belongs to keyed by entity type. NULL if the field was not
* found.
*
* @see field_info_field_by_id()
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getField($field_name).
*/
function
field_info_field
(
$field_name
)
{
return
Field
::
fieldInfo
()
->
getField
(
$field_name
);
}
/**
* Returns data about an individual field, given a field ID.
*
* @param $field_id
* The ID of the field to retrieve. $field_id can refer to a deleted field,
* but not an inactive one.
*
* @return
* The field array, as returned by field_read_fields(), with an additional
* element 'bundles', whose value is an array of all the bundles this field
* belongs to.
*
* @see field_info_field()
*
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getFieldById($field_id).
*/
function
field_info_field_by_id
(
$field_id
)
{
return
Field
::
fieldInfo
()
->
getFieldById
(
$field_id
);
}
/**
* Returns the same data as field_info_field_by_id() for every field.
*
* Use of this function should be avoided when possible, since it loads and
* statically caches a potentially large array of information.
*
* When iterating over the fields present in a given bundle after a call to
* field_info_instances($entity_type, $bundle), it is recommended to use
* field_info_field() on each individual field instead.
*
* @return
* An array, each key is a field ID and the values are field arrays as
* returned by field_read_fields(), with an additional element 'bundles',
* whose value is an array of all the bundle this field belongs to.
*
* @see field_info_field()
* @see field_info_field_by_id()
*
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getFields().
*/
function
field_info_field_by_ids
()
{
return
Field
::
fieldInfo
()
->
getFields
();
}
/**
* Retrieves information about field instances.
*
* Use of this function to retrieve instances across separate bundles (i.e.
* when the $bundle parameter is NULL) should be avoided when possible, since
* it loads and statically caches a potentially large array of information.
* Use field_info_field_map() instead.
*
* When retrieving the instances of a specific bundle (i.e. when both
* $entity_type and $bundle_name are provided), the function also populates a
* static cache with the corresponding field definitions, allowing fast
* retrieval of field_info_field() later in the request.
*
* @param $entity_type
* (optional) The entity type for which to return instances.
* @param $bundle_name
* (optional) The bundle name for which to return instances. If $entity_type
* is NULL, the $bundle_name parameter is ignored.
*
* @return
* If $entity_type is not set, return all instances keyed by entity type and
* bundle name. If $entity_type is set, return all instances for that entity
* type, keyed by bundle name. If $entity_type and $bundle_name are set,
* return all instances for that bundle.
*
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getInstances(),
* Field::fieldInfo()->getInstances($entity_type) or
* Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name).
*/
function
field_info_instances
(
$entity_type
=
NULL
,
$bundle_name
=
NULL
)
{
$cache
=
Field
::
fieldInfo
();
if
(
!
isset
(
$entity_type
))
{
return
$cache
->
getInstances
();
}
if
(
!
isset
(
$bundle_name
))
{
return
$cache
->
getInstances
(
$entity_type
);
}
return
$cache
->
getBundleInstances
(
$entity_type
,
$bundle_name
);
}
/**
* Returns an array of instance data for a specific field and bundle.
*
* The function populates a static cache with all fields and instances used in
* the bundle, allowing fast retrieval of field_info_field() or
* field_info_instance() later in the request.
*
* @param $entity_type
* The entity type for the instance.
* @param $field_name
* The field name for the instance.
* @param $bundle_name
* The bundle name for the instance.
*
* @return
* An associative array of instance data for the specific field and bundle;
* NULL if the instance does not exist.
*
* @deprecated as of Drupal 8.0. Use
* Field::fieldInfo()->getBundleInstance($entity_type, $bundle, $field_name).
*/
function
field_info_instance
(
$entity_type
,
$field_name
,
$bundle_name
)
{
return
Field
::
fieldInfo
()
->
getInstance
(
$entity_type
,
$bundle_name
,
$field_name
);
}
/**
* Returns a list and settings of pseudo-field elements in a given bundle.
...
...
@@ -493,76 +251,6 @@ function field_info_extra_fields($entity_type, $bundle, $context) {
return
isset
(
$info
[
$context
])
?
$info
[
$context
]
:
array
();
}
/**
* Returns a field type's default settings.
*
* @param $type
* A field type name.
*
* @return
* The field type's default settings, or an empty array if type or settings
* are not defined.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings()
*/
function
field_info_field_settings
(
$type
)
{
return
\
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefaultSettings
(
$type
);
}
/**
* Returns a field type's default instance settings.
*
* @param $type
* A field type name.
*
* @return
* The field type's default instance settings, or an empty array if type or
* settings are not defined.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.entity.field.field_type')->getDefaultInstanceSettings()
*/
function
field_info_instance_settings
(
$type
)
{
return
\
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefaultInstanceSettings
(
$type
);
}
/**
* Returns a field widget's default settings.
*
* @param $type
* A widget type name.
*
* @return
* The widget type's default settings, as provided by
* hook_field_widget_info(), or an empty array if type or settings are
* undefined.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.widget')->getDefaultSettings()
*/
function
field_info_widget_settings
(
$type
)
{
return
\
Drupal
::
service
(
'plugin.manager.field.widget'
)
->
getDefaultSettings
(
$type
);
}
/**
* Returns a field formatter's default settings.
*
* @param $type
* A field formatter type name.
*
* @return
* The formatter type's default settings, as provided by
* hook_field_formatter_info(), or an empty array if type or settings are
* undefined.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.formatter')->getDefaultSettings()
*/
function
field_info_formatter_settings
(
$type
)
{
return
\
Drupal
::
service
(
'plugin.manager.field.formatter'
)
->
getDefaultSettings
(
$type
);
}
/**
* Returns a field storage type's default settings.
*
...
...
core/modules/field/field.module
View file @
375a7081
...
...
@@ -9,18 +9,18 @@
use
Drupal\Core\Template\Attribute
;
use
Drupal\field\FieldInterface
;
use
Drupal\field\FieldInstanceInterface
;
use
Drupal\Core\Entity\EntityNG
;
/*
* Load all public Field API functions. Drupal currently has no
* mechanism for auto-loading core APIs, so we have to load them on
* every page request.
*/
require_once
__DIR__
.
'/field.crud.inc'
;
require_once
__DIR__
.
'/field.info.inc'
;
require_once
__DIR__
.
'/field.multilingual.inc'
;
require_once
__DIR__
.
'/field.attach.inc'
;
require_once
__DIR__
.
'/field.form.inc'
;
require_once
__DIR__
.
'/field.purge.inc'
;
require_once
__DIR__
.
'/field.deprecated.inc'
;
/**
* @defgroup field Field API
...
...
@@ -332,46 +332,61 @@ function field_field_widget_info_alter(&$info) {
}
/**
* Applies language fallback rules to the fields attached to the given entity.
*
* Core language fallback rules simply check if fields have a field translation
* for the requested language code. If so, the requested language is returned,
* otherwise all the fallback candidates are inspected to see if there is a
* field translation available in another language.
* By default this is called by field_field_language_alter(), but this
* behavior can be disabled by setting the 'field.settings.language_fallback'
* variable to FALSE.
*
* @param $field_langcodes
* A reference to an array of language codes keyed by field name.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be displayed.
* @param $langcode
* The language code $entity has to be displayed in.
* Implements hook_entity_bundle_create().
*/
function
field_language_fallback
(
&
$field_langcodes
,
EntityInterface
$entity
,
$langcode
)
{
// Lazily init fallback candidates to avoid unnecessary calls.
$fallback_candidates
=
NULL
;
foreach
(
$field_langcodes
as
$field_name
=>
$field_langcode
)
{
// If the requested language is defined for the current field use it,
// otherwise search for a fallback value among the fallback candidates.
if
(
isset
(
$entity
->
{
$field_name
}[
$langcode
]))
{
$field_langcodes
[
$field_name
]
=
$langcode
;
}
elseif
(
!
empty
(
$entity
->
{
$field_name
}))
{
if
(
!
isset
(
$fallback_candidates
))
{
require_once
DRUPAL_ROOT
.
'/core/includes/language.inc'
;
$fallback_candidates
=
language_fallback_get_candidates
();
}
foreach
(
$fallback_candidates
as
$fallback_langcode
)
{
if
(
isset
(
$entity
->
{
$field_name
}[
$fallback_langcode
]))
{
$field_langcodes
[
$field_name
]
=
$fallback_langcode
;
break
;
}
function
field_entity_bundle_create
(
$entity_type
,
$bundle
)
{
// Clear the cache.
field_cache_clear
();
}
/**
* Implements hook_entity_bundle_rename().
*/
function
field_entity_bundle_rename
(
$entity_type
,
$bundle_old
,
$bundle_new
)
{
$instances
=
field_read_instances
();
foreach
(
$instances
as
$instance
)
{
if
(
$instance
->
entity_type
==
$entity_type
&&
$instance
->
bundle
==
$bundle_old
)
{
$id_new
=
$instance
[
'entity_type'
]
.
'.'
.
$bundle_new
.
'.'
.
$instance
[
'field_name'
];
$instance
->
id
=
$id_new
;
$instance
->
bundle
=
$bundle_new
;
$instance
->
allowBundleRename
();
$instance
->
save
();
}
}
// Clear the field cache.
field_cache_clear
();
// Update bundle settings.
$settings
=
variable_get
(
'field_bundle_settings_'
.
$entity_type
.
'__'
.
$bundle_old
,
array
());
variable_set
(
'field_bundle_settings_'
.
$entity_type
.
'__'
.
$bundle_new
,
$settings
);
variable_del
(
'field_bundle_settings_'
.
$entity_type
.
'__'
.
$bundle_old
);
}
/**
* Implements hook_entity_bundle_delete().
*
* This deletes the data for the field instances as well as the field instances
* themselves. This function actually just marks the data and field instances as
* deleted, leaving the garbage collection for a separate process, because it is
* not always possible to delete this much data in a single page request
* (particularly since for some field types, the deletion is more than just a
* simple DELETE query).
*/
function
field_entity_bundle_delete
(
$entity_type
,
$bundle
)
{
// Get the instances on the bundle. field_read_instances() must be used
// here since field_info_instances() does not return instances for disabled
// entity types or bundles.
$instances
=
field_read_instances
(
array
(
'entity_type'
=>
$entity_type
,
'bundle'
=>
$bundle
),
array
(
'include_inactive'
=>
TRUE
));
foreach
(
$instances
as
$instance
)
{
$instance
->
delete
();
}
// Clear the cache.
field_cache_clear
();
// Clear bundle display settings.
variable_del
(
'field_bundle_settings_'
.
$entity_type
.
'__'
.
$bundle
);
}
/**
...
...
@@ -501,17 +516,6 @@ function field_get_default_value(EntityInterface $entity, $field, $instance, $la
return
$items
;
}
/**
* Callback for usort() within theme_field_multiple_value_form().
*
* Sorts using ['_weight']['#value']
*/
function
_field_sort_items_value_helper
(
$a
,
$b
)
{
$a_weight
=
(
is_array
(
$a
)
&&
isset
(
$a
[
'_weight'
][
'#value'
])
?
$a
[
'_weight'
][
'#value'
]
:
0
);
$b_weight
=
(
is_array
(
$b
)
&&
isset
(
$b
[
'_weight'
][
'#value'
])
?
$b
[
'_weight'
][
'#value'
]
:
0
);
return
$a_weight
-
$b_weight
;
}
/**
* Gets or sets administratively defined bundle settings.
*
...
...
@@ -827,29 +831,6 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
return
$output
;
}
/**
* Returns the field items in the language they currently would be displayed.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the data to be displayed.
* @param $field_name
* The field to be displayed.
* @param $langcode
* (optional) The language code $entity->{$field_name} has to be displayed in.
* Defaults to the current language.
*
* @return
* An array with available field items keyed by delta.
*
* @deprecated as of Drupal 8.0. Use
* $entity->getTranslation($langcode)->{$field_name}
*/
function
field_get_items
(
EntityInterface
$entity
,
$field_name
,
$langcode
=
NULL
)
{
$entity
=
$entity
->
getBCEntity
();
$langcode
=
field_language
(
$entity
,
$field_name
,
$langcode
);
return
isset
(
$entity
->
{
$field_name
}[
$langcode
])
?
$entity
->
{
$field_name
}[
$langcode
]
:
array
();
}
/**
* Determines whether the user has access to a given field.
*
...
...
core/modules/field/field.multilingual.inc
View file @
375a7081
<?php
use
Drupal\Core\Entity\EntityInterface
;
/**
* @file
* Functions implementing Field API multilingual support.
*/
use
Drupal\Core\Language\Language
;
use
Drupal\Core\Entity\EntityInterface
;
/**
* @defgroup field_language Field Language API
...
...
@@ -64,6 +63,50 @@
* the Field API.
*/
/**
* Applies language fallback rules to the fields attached to the given entity.
*
* Core language fallback rules simply check if fields have a field translation
* for the requested language code. If so, the requested language is returned,
* otherwise all the fallback candidates are inspected to see if there is a
* field translation available in another language.
* By default this is called by field_field_language_alter(), but this
* behavior can be disabled by setting the 'field.settings.language_fallback'
* variable to FALSE.
*
* @param $field_langcodes
* A reference to an array of language codes keyed by field name.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be displayed.
* @param $langcode
* The language code $entity has to be displayed in.
*/
function
field_language_fallback
(
&
$field_langcodes
,
EntityInterface
$entity
,
$langcode
)
{
// Lazily init fallback candidates to avoid unnecessary calls.
$fallback_candidates
=
NULL
;
foreach
(
$field_langcodes
as
$field_name
=>
$field_langcode
)
{
// If the requested language is defined for the current field use it,
// otherwise search for a fallback value among the fallback candidates.
if
(
isset
(
$entity
->
{
$field_name
}[
$langcode
]))
{
$field_langcodes
[
$field_name
]
=
$langcode
;
}
elseif
(
!
empty
(
$entity
->
{
$field_name
}))
{
if
(
!
isset
(
$fallback_candidates
))
{
require_once
DRUPAL_ROOT
.
'/core/includes/language.inc'
;
$fallback_candidates
=
language_fallback_get_candidates
();
}
foreach
(
$fallback_candidates
as
$fallback_langcode
)
{
if
(
isset
(
$entity
->
{
$field_name
}[
$fallback_langcode
]))
{
$field_langcodes
[
$field_name
]
=
$fallback_langcode
;
break
;
}
}
}
}
}
/**
* Collects the available language codes for the given entity type and field.
*
...
...
core/modules/field/field.
crud
.inc
→
core/modules/field/field.
purge
.inc
View file @
375a7081
...
...
@@ -7,151 +7,8 @@
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\field\Entity\Field
;
use
Drupal\field\Entity\FieldInstance
;
use
Drupal\field\FieldException
;
/**
* @defgroup field_crud Field CRUD API
* @{
* Creates, updates, and deletes Field API fields, bundles, and instances.
*
* Modules use this API, often in hook_install(), to create custom data
* structures. UI modules will use it to create a user interface.
*
* The Field CRUD API uses @link field Field API data structures @endlink.
*
* See @link field Field API @endlink for information about the other parts of
* the Field API.
*/
/**
* Reads a single field record directly from the database.
*
* Generally, you should use the field_info_field() instead.
*
* This function will not return deleted fields. Use field_read_fields() instead
* for this purpose.
*
* @param $field_name
* The field name to read.
* @param array $include_additional
* The default behavior of this function is to not return a field that is
* inactive. Setting $include_additional['include_inactive'] to TRUE will