Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
34119ba9
Commit
34119ba9
authored
Nov 20, 2009
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#638356
by yched: Reorganize and re-locate field test modules.
parent
b1434988
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1350 additions
and
41 deletions
+1350
-41
modules/field/field.info
modules/field/field.info
+1
-1
modules/field/modules/field_sql_storage/field_sql_storage.test
...es/field/modules/field_sql_storage/field_sql_storage.test
+3
-3
modules/field/modules/list/list.test
modules/field/modules/list/list.test
+6
-6
modules/field/modules/options/options.test
modules/field/modules/options/options.test
+6
-6
modules/field/modules/text/text.test
modules/field/modules/text/text.test
+6
-6
modules/field/tests/field.test
modules/field/tests/field.test
+15
-15
modules/field/tests/field_test.entity.inc
modules/field/tests/field_test.entity.inc
+322
-0
modules/field/tests/field_test.field.inc
modules/field/tests/field_test.field.inc
+311
-0
modules/field/tests/field_test.info
modules/field/tests/field_test.info
+3
-0
modules/field/tests/field_test.install
modules/field/tests/field_test.install
+0
-0
modules/field/tests/field_test.module
modules/field/tests/field_test.module
+198
-0
modules/field/tests/field_test.storage.inc
modules/field/tests/field_test.storage.inc
+475
-0
modules/taxonomy/taxonomy.test
modules/taxonomy/taxonomy.test
+4
-4
No files found.
modules/field/field.info
View file @
34119ba9
...
...
@@ -12,6 +12,6 @@ files[] = field.default.inc
files
[]
=
field
.
multilingual
.
inc
files
[]
=
field
.
attach
.
inc
files
[]
=
field
.
form
.
inc
files
[]
=
field
.
test
files
[]
=
tests
/
field
.
test
dependencies
[]
=
field_sql_storage
required
=
TRUE
modules/field/modules/field_sql_storage/field_sql_storage.test
View file @
34119ba9
...
...
@@ -17,7 +17,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
return
array
(
'name'
=>
'Field SQL storage tests'
,
'description'
=>
"Test field SQL storage module."
,
'group'
=>
'Field'
'group'
=>
'Field
API
'
);
}
...
...
@@ -303,7 +303,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
// Create a decimal 5.2 field and add some data.
$field
=
array
(
'field_name'
=>
'decimal52'
,
'type'
=>
'number_decimal'
,
'settings'
=>
array
(
'precision'
=>
5
,
'scale'
=>
2
));
$field
=
field_create_field
(
$field
);
$instance
=
array
(
'field_name'
=>
'decimal52'
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
);
$instance
=
array
(
'field_name'
=>
'decimal52'
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
'test_bundle'
);
$instance
=
field_create_instance
(
$instance
);
$entity
=
field_test_create_stub_entity
(
0
,
0
,
$instance
[
'bundle'
]);
$entity
->
decimal52
[
FIELD_LANGUAGE_NONE
][
0
][
'value'
]
=
'1.235'
;
...
...
@@ -331,7 +331,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$field_name
=
'testfield'
;
$field
=
array
(
'field_name'
=>
$field_name
,
'type'
=>
'text'
);
$field
=
field_create_field
(
$field
);
$instance
=
array
(
'field_name'
=>
$field_name
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
);
$instance
=
array
(
'field_name'
=>
$field_name
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
'test_bundle'
);
$instance
=
field_create_instance
(
$instance
);
$tables
=
array
(
_field_sql_storage_tablename
(
$field
),
_field_sql_storage_revision_tablename
(
$field
));
...
...
modules/field/modules/list/list.test
View file @
34119ba9
...
...
@@ -6,7 +6,7 @@ class ListFieldTestCase extends DrupalWebTestCase {
return
array
(
'name'
=>
'List field'
,
'description'
=>
"Test the List field type."
,
'group'
=>
'Field'
'group'
=>
'Field
Types
'
);
}
...
...
@@ -26,7 +26,7 @@ class ListFieldTestCase extends DrupalWebTestCase {
$this
->
instance_1
=
array
(
'field_name'
=>
$this
->
card_1
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_buttons'
,
),
...
...
@@ -40,7 +40,7 @@ class ListFieldTestCase extends DrupalWebTestCase {
*/
function
testUpdateAllowedValues
()
{
// All three options appear.
$entity
=
field_test_create_stub_entity
(
0
,
0
,
FIELD_TEST_BUNDLE
);
$entity
=
field_test_create_stub_entity
();
$form
=
drupal_get_form
(
'field_test_entity_form'
,
$entity
);
$this
->
assertTrue
(
!
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
1
]),
t
(
'Option 1 exists'
));
$this
->
assertTrue
(
!
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
2
]),
t
(
'Option 2 exists'
));
...
...
@@ -49,7 +49,7 @@ class ListFieldTestCase extends DrupalWebTestCase {
// Removed options do not appear.
$this
->
card_1
[
'settings'
][
'allowed_values'
]
=
"2|Two"
;
field_update_field
(
$this
->
card_1
);
$entity
=
field_test_create_stub_entity
(
0
,
0
,
FIELD_TEST_BUNDLE
);
$entity
=
field_test_create_stub_entity
();
$form
=
drupal_get_form
(
'field_test_entity_form'
,
$entity
);
$this
->
assertTrue
(
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
1
]),
t
(
'Option 1 does not exist'
));
$this
->
assertTrue
(
!
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
2
]),
t
(
'Option 2 exists'
));
...
...
@@ -73,13 +73,13 @@ class ListFieldTestCase extends DrupalWebTestCase {
$this
->
instance_1
=
array
(
'field_name'
=>
$this
->
card_1
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_buttons'
,
),
);
$this
->
instance_1
=
field_create_instance
(
$this
->
instance_1
);
$entity
=
field_test_create_stub_entity
(
0
,
0
,
FIELD_TEST_BUNDLE
);
$entity
=
field_test_create_stub_entity
();
$form
=
drupal_get_form
(
'field_test_entity_form'
,
$entity
);
$this
->
assertTrue
(
!
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
1
]),
t
(
'Option 1 exists'
));
$this
->
assertTrue
(
!
empty
(
$form
[
'card_1'
][
FIELD_LANGUAGE_NONE
][
2
]),
t
(
'Option 2 exists'
));
...
...
modules/field/modules/options/options.test
View file @
34119ba9
...
...
@@ -6,7 +6,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
return
array
(
'name'
=>
'Options widgets'
,
'description'
=>
"Test the Options widgets."
,
'group'
=>
'Field'
'group'
=>
'Field
Types
'
);
}
...
...
@@ -62,7 +62,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
$instance
=
array
(
'field_name'
=>
$this
->
card_1
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_buttons'
,
),
...
...
@@ -118,7 +118,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
$instance
=
array
(
'field_name'
=>
$this
->
card_2
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_buttons'
,
),
...
...
@@ -204,7 +204,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
$instance
=
array
(
'field_name'
=>
$this
->
card_1
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_select'
,
),
...
...
@@ -258,7 +258,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
$instance
=
array
(
'field_name'
=>
$this
->
card_2
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_select'
,
),
...
...
@@ -341,7 +341,7 @@ class OptionsWidgetsTestCase extends DrupalWebTestCase {
$instance
=
array
(
'field_name'
=>
$this
->
bool
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'options_onoff'
,
),
...
...
modules/field/modules/text/text.test
View file @
34119ba9
...
...
@@ -10,7 +10,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
return
array
(
'name'
=>
'Text Field'
,
'description'
=>
"Test the creation of text fields."
,
'group'
=>
'Field'
'group'
=>
'Field
Types
'
);
}
...
...
@@ -41,7 +41,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this
->
instance
=
array
(
'field_name'
=>
$this
->
field
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'text_textfield'
,
),
...
...
@@ -53,7 +53,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
);
field_create_instance
(
$this
->
instance
);
// Test valid and invalid values with field_attach_validate().
$entity
=
field_test_create_stub_entity
(
0
,
0
,
FIELD_TEST_BUNDLE
);
$entity
=
field_test_create_stub_entity
();
$langcode
=
FIELD_LANGUAGE_NONE
;
for
(
$i
=
0
;
$i
<=
$max_length
+
2
;
$i
++
)
{
$entity
->
{
$this
->
field
[
'field_name'
]}[
$langcode
][
0
][
'value'
]
=
str_repeat
(
'x'
,
$i
);
...
...
@@ -87,7 +87,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this
->
instance
=
array
(
'field_name'
=>
$this
->
field_name
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'label'
=>
$this
->
randomName
()
.
'_label'
,
'settings'
=>
array
(
'text_processing'
=>
TRUE
,
...
...
@@ -141,7 +141,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
$this
->
instance
=
array
(
'field_name'
=>
$this
->
field_name
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'label'
=>
$this
->
randomName
()
.
'_label'
,
'settings'
=>
array
(
'text_processing'
=>
TRUE
,
...
...
@@ -224,7 +224,7 @@ class TextSummaryTestCase extends DrupalWebTestCase {
return
array
(
'name'
=>
'Text summary'
,
'description'
=>
'Test text_summary() with different strings and lengths.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
Types
'
,
);
}
...
...
modules/field/field.test
→
modules/field/
tests/
field.test
View file @
34119ba9
...
...
@@ -82,7 +82,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
return
array
(
'name'
=>
'Field attach tests (storage-related)'
,
'description'
=>
'Test storage-related Field Attach API functions.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -400,7 +400,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
* Test insert with missing or NULL fields, with default value.
*/
function
testFieldAttachSaveMissingDataDefaultValue
()
{
// Add a default value.
// Add a default value
function
.
$this
->
instance
[
'default_value_function'
]
=
'field_test_default_value'
;
field_update_instance
(
$this
->
instance
);
...
...
@@ -802,7 +802,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
return
array
(
'name'
=>
'Field attach tests (other)'
,
'description'
=>
'Test other Field Attach API functions.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -1129,7 +1129,7 @@ class FieldInfoTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field info tests'
,
'description'
=>
'Get information about existing fields, instances and bundles.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -1181,7 +1181,7 @@ class FieldInfoTestCase extends FieldTestCase {
// Verify that no unexpected instances exist.
$core_fields
=
field_info_fields
();
$instances
=
field_info_instances
(
'test_entity'
,
FIELD_TEST_BUNDLE
);
$instances
=
field_info_instances
(
'test_entity'
,
'test_bundle'
);
$this
->
assertTrue
(
empty
(
$instances
),
t
(
'With no instances, info bundles is empty.'
));
// Create a field, verify it shows up.
...
...
@@ -1206,7 +1206,7 @@ class FieldInfoTestCase extends FieldTestCase {
$instance
=
array
(
'field_name'
=>
$field
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'label'
=>
$this
->
randomName
(),
'description'
=>
$this
->
randomName
(),
'weight'
=>
mt_rand
(
0
,
127
),
...
...
@@ -1265,7 +1265,7 @@ class FieldInfoTestCase extends FieldTestCase {
$instance_definition
=
array
(
'field_name'
=>
$field_definition
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
);
field_create_instance
(
$instance_definition
);
...
...
@@ -1334,7 +1334,7 @@ class FieldFormTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field form tests'
,
'description'
=>
'Test Field form handling.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -1690,7 +1690,7 @@ class FieldCrudTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field CRUD tests'
,
'description'
=>
'Test field create, read, update, and delete.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -1923,7 +1923,7 @@ class FieldCrudTestCase extends FieldTestCase {
$this
->
instance_definition
=
array
(
'field_name'
=>
$this
->
field
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'test_field_widget'
,
),
...
...
@@ -2020,7 +2020,7 @@ class FieldCrudTestCase extends FieldTestCase {
// Create a decimal 5.2 field.
$field
=
array
(
'field_name'
=>
'decimal53'
,
'type'
=>
'number_decimal'
,
'cardinality'
=>
3
,
'settings'
=>
array
(
'precision'
=>
5
,
'scale'
=>
2
));
$field
=
field_create_field
(
$field
);
$instance
=
array
(
'field_name'
=>
'decimal53'
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
);
$instance
=
array
(
'field_name'
=>
'decimal53'
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
'test_bundle'
);
$instance
=
field_create_instance
(
$instance
);
// Update it to a deciaml 5.3 field.
...
...
@@ -2137,7 +2137,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field instance CRUD tests'
,
'description'
=>
'Create field entities by attaching fields to entities.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -2153,7 +2153,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
'field_name'
=>
$this
->
field
[
'field_name'
],
'object_type'
=>
'test_entity'
,
'object_type'
=>
'test_entity'
,
'bundle'
=>
FIELD_TEST_BUNDLE
,
'bundle'
=>
'test_bundle'
,
);
}
...
...
@@ -2329,7 +2329,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field translations tests'
,
'description'
=>
'Test multilanguage fields logic.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
@@ -2563,7 +2563,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
return
array
(
'name'
=>
'Field bulk delete tests'
,
'description'
=>
'Bulk delete fields and instances, and clean up afterwards.'
,
'group'
=>
'Field'
,
'group'
=>
'Field
API
'
,
);
}
...
...
modules/field/tests/field_test.entity.inc
0 → 100644
View file @
34119ba9
<?php
// $Id$
/**
* @file
* Defines an entity type.
*/
/**
* Implements hook_entity_info().
*/
function
field_test_entity_info
()
{
$bundles
=
variable_get
(
'field_test_bundles'
,
array
(
'test_bundle'
=>
array
(
'label'
=>
'Test Bundle'
)));
return
array
(
'test_entity'
=>
array
(
'name'
=>
t
(
'Test Entity'
),
'object keys'
=>
array
(
'id'
=>
'ftid'
,
'revision'
=>
'ftvid'
,
'bundle'
=>
'fttype'
,
),
'cacheable'
=>
FALSE
,
'bundles'
=>
$bundles
,
'fieldable'
=>
TRUE
,
),
// This entity type doesn't get form handling for now...
'test_cacheable_entity'
=>
array
(
'name'
=>
t
(
'Test Entity, cacheable'
),
'object keys'
=>
array
(
'id'
=>
'ftid'
,
'revision'
=>
'ftvid'
,
'bundle'
=>
'fttype'
,
),
'fieldable'
=>
TRUE
,
'cacheable'
=>
TRUE
,
'bundles'
=>
$bundles
,
),
);
}
/**
* Implements hook_entity_info_alter().
*/
function
field_test_entity_info_alter
(
&
$entity_info
)
{
// Enable/disable field_test as a translation handler.
foreach
(
field_test_entity_info_translatable
()
as
$obj_type
=>
$translatable
)
{
$entity_info
[
$obj_type
][
'translation'
][
'field_test'
]
=
$translatable
;
}
// Disable locale as a translation handler.
foreach
(
$entity_info
as
$obj_type
=>
$info
)
{
$entity_info
[
$obj_type
][
'translation'
][
'locale'
]
=
FALSE
;
}
}
/**
* Creates a new bundle for test_entity objects.
*
* @param $bundle
* The machine-readable name of the bundle.
* @param $text
* The human-readable name of the bundle. If none is provided, the machine
* name will be used.
*/
function
field_test_create_bundle
(
$bundle
,
$text
=
NULL
)
{
$bundles
=
variable_get
(
'field_test_bundles'
,
array
(
'test_bundle'
=>
array
(
'label'
=>
'Test Bundle'
)));
$bundles
+=
array
(
$bundle
=>
array
(
'label'
=>
$text
?
$text
:
$bundle
));
variable_set
(
'field_test_bundles'
,
$bundles
);
$info
=
field_test_entity_info
();
foreach
(
$info
as
$type
=>
$type_info
)
{
field_attach_create_bundle
(
$type
,
$bundle
);
}
}
/**
* Renames a bundle for test_entity objects.
*
* @param $bundle_old
* The machine-readable name of the bundle to rename.
* @param $bundle_new
* The new machine-readable name of the bundle.
*/
function
field_test_rename_bundle
(
$bundle_old
,
$bundle_new
)
{
$bundles
=
variable_get
(
'field_test_bundles'
,
array
(
'test_bundle'
=>
array
(
'label'
=>
'Test Bundle'
)));
$bundles
[
$bundle_new
]
=
$bundles
[
$bundle_old
];
unset
(
$bundles
[
$bundle_old
]);
variable_set
(
'field_test_bundles'
,
$bundles
);
$info
=
field_test_entity_info
();
foreach
(
$info
as
$type
=>
$type_info
)
{
field_attach_rename_bundle
(
$type
,
$bundle_old
,
$bundle_new
);
}
}
/**
* Deletes a bundle for test_entity objects.
*
* @param $bundle
* The machine-readable name of the bundle to delete.
*/
function
field_test_delete_bundle
(
$bundle
)
{
$bundles
=
variable_get
(
'field_test_bundles'
,
array
(
'test_bundle'
=>
array
(
'label'
=>
'Test Bundle'
)));
unset
(
$bundles
[
$bundle
]);
variable_set
(
'field_test_bundles'
,
$bundles
);
$info
=
field_test_entity_info
();
foreach
(
$info
as
$type
=>
$type_info
)
{
field_attach_delete_bundle
(
$type
,
$bundle
);
}
}
/**
* Implements hook_field_build_modes().
*/
function
field_test_field_build_modes
(
$obj_type
)
{
$modes
=
array
();
if
(
$obj_type
==
'test_entity'
||
$obj_type
==
'test_cacheable_entity'
)
{
$modes
=
array
(
'full'
=>
t
(
'Full node'
),
'teaser'
=>
t
(
'Teaser'
),
);
}
return
$modes
;
}
/**
* Creates a basic test_entity object.
*/
function
field_test_create_stub_entity
(
$id
=
1
,
$vid
=
1
,
$bundle
=
'test_bundle'
)
{
$entity
=
new
stdClass
();
// Only set id and vid properties if they don't come as NULL (creation form).
if
(
isset
(
$id
))
{
$entity
->
ftid
=
$id
;
}
if
(
isset
(
$vid
))
{
$entity
->
ftvid
=
$vid
;
}
$entity
->
fttype
=
$bundle
;
return
$entity
;
}
/**
* Loads a test_entity.
*
* @param $ftid
* The id of the entity to load.
* @param $ftvid
* (Optional) The revision id of the entity to load. If not specified, the
* current revision will be used.
* @return
* The loaded entity.
*/
function
field_test_entity_test_load
(
$ftid
,
$ftvid
=
NULL
)
{
// Load basic strucure.
$query
=
db_select
(
'test_entity'
,
'fte'
,
array
())
->
fields
(
'fte'
)
->
condition
(
'ftid'
,
$ftid
);
if
(
$ftvid
)
{
$query
->
condition
(
'ftvid'
,
$ftvid
);
}
$entities
=
$query
->
execute
()
->
fetchAllAssoc
(
'ftid'
);
// Attach fields.
if
(
$ftvid
)
{
field_attach_load_revision
(
'test_entity'
,
$entities
);
}
else
{
field_attach_load
(
'test_entity'
,
$entities
);
}
return
$entities
[
$ftid
];
}
/**
* Saves a test_entity.
*
* A new entity is created if $entity->ftid and $entity->is_new are both empty.
* A new revision is created if $entity->revision is not empty.
*
* @param $entity
* The entity to save.
*/
function
field_test_entity_save
(
&
$entity
)
{
field_attach_presave
(
'test_entity'
,
$entity
);
if
(
!
isset
(
$entity
->
is_new
))
{
$entity
->
is_new
=
empty
(
$entity
->
ftid
);
}
if
(
!
$entity
->
is_new
&&
!
empty
(
$entity
->
revision
))
{
$entity
->
old_ftvid
=
$entity
->
ftvid
;
unset
(
$entity
->
ftvid
);
}
$update_entity
=
TRUE
;
if
(
$entity
->
is_new
)
{
drupal_write_record
(
'test_entity'
,
$entity
);
drupal_write_record
(
'test_entity_revision'
,
$entity
);
$op
=
'insert'
;
}
else
{
drupal_write_record
(
'test_entity'
,
$entity
,
'ftid'
);
if
(
!
empty
(
$entity
->
revision
))
{
drupal_write_record
(
'test_entity_revision'
,
$entity
);
}
else
{
drupal_write_record
(
'test_entity_revision'
,
$entity
,
'ftvid'
);
$update_entity
=
FALSE
;
}
$op
=
'update'
;
}
if
(
$update_entity
)
{
db_update
(
'test_entity'
)
->
fields
(
array
(
'ftvid'
=>
$entity
->
ftvid
))
->
condition
(
'ftid'
,
$entity
->
ftid
)
->
execute
();
}
// Save fields.
$function
=
"field_attach_
$op
"
;
$function
(
'test_entity'
,
$entity
);
}
/**
* Menu callback: displays the 'Add new test_entity' form.
*/
function
field_test_entity_add
(
$fttype
)
{
$fttype
=
str_replace
(
'-'
,
'_'
,
$fttype
);
$entity
=
(
object
)
array
(
'fttype'
=>
$fttype
);
drupal_set_title
(
t
(
'Create test_entity @bundle'
,
array
(
'@bundle'
=>
$fttype
)),
PASS_THROUGH
);
return
drupal_get_form
(
'field_test_entity_form'
,
$entity
,
TRUE
);
}
/**
* Menu callback: displays the 'Edit exiisting test_entity' form.
*/
function
field_test_entity_edit
(
$entity
)
{
drupal_set_title
(
t
(
'test_entity @ftid revision @ftvid'
,
array
(
'@ftid'
=>
$entity
->
ftid
,
'@ftvid'
=>
$entity
->
ftvid
)),
PASS_THROUGH
);
return
drupal_get_form
(
'field_test_entity_form'
,
$entity
);
}
/**
* Test_entity form.
*/
function
field_test_entity_form
(
$form
,
&
$form_state
,
$entity
,
$add
=
FALSE
)
{
if
(
isset
(
$form_state
[
'test_entity'
]))
{
$entity
=
$form_state
[
'test_entity'
]
+
(
array
)
$entity
;
}
$entity
=
(
object
)
$entity
;
foreach
(
array
(
'ftid'
,
'ftvid'
,
'fttype'
)
as
$key
)
{
$form
[
$key
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
isset
(
$entity
->
$key
)
?
$entity
->
$key
:
NULL
,
);
}
// Add field widgets.
$form
[
'#builder_function'
]
=
'field_test_entity_form_submit_builder'
;
field_attach_form
(
'test_entity'
,
$entity
,
$form
,
$form_state
);
if
(
!
$add
)
{
$form
[
'revision'
]
=
array
(
'#access'
=>
user_access
(
'administer field_test content'
),
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Create new revision'
),
'#default_value'
=>
FALSE
,
'#weight'
=>
100
,
);
}
$form
[
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Save'
),
'#weight'
=>
101
,
);
return
$form
;
}
/**
* Validate handler for field_test_entity_form().
*/
function
field_test_entity_form_validate
(
$form
,
&
$form_state
)
{
$entity
=
field_test_create_stub_entity
(
$form_state
[
'values'
][
'ftid'
],
$form_state
[
'values'
][
'ftvid'
],
$form_state
[
'values'
][
'fttype'
]);
field_attach_form_validate
(
'test_entity'
,
$entity
,
$form
,
$form_state
);
}
/**
* Submit handler for field_test_entity_form().
*/
function
field_test_entity_form_submit
(
$form
,
&
$form_state
)
{
$entity
=
field_test_entity_form_submit_builder
(
$form
,
$form_state
);
$insert
=
empty
(
$entity
->
ftid
);
field_test_entity_save
(
$entity
);