Make sure all settings are present at run time

yched - July 3, 2009 - 21:40
Project:Drupal
Version:7.x-dev
Component:field system
Category:task
Priority:normal
Assigned:yched
Status:closed
Issue tags:Fields in Core
Description

For DX sake, the Field API tries to make sure that $field and $instances always contain all the expected (field|instance|widget|formatter) settings, avoiding the need for $foo = isset($field['settings']['foo']) ? $field['settings']['some_setting'] : 'default_for_foo'; code all over the place.

Currently, field_create_field() and field_create_instance() add missing settings on field / instance creation.

However, by the time we read the definition back, the execution context might have changed:
- the module implementing the field type, widget or formatter has been updated and has a new setting
- a 3rd party module, using the new *_info_alter hooks (#502522: Allow drupal_alter() on the various Field API declarative hooks) to add new settings, has been enabled.

The attached patch :
- makes sure missing settings and their default values are filled in field_read_fields() / field_read_instances() (was a TODO so far)
- adds some tests for this : testReadField(), testReadFieldInstance()
- reworks the existing testCreateField(), testCreateFieldInstance() so that they only test field_create_*(), not field_read_*()
- burns a kitten's whiskers by unifying minor things between field and instances CRUD test classes, and adding missing PHPdocs.test functions.

AttachmentSize
field_settings_on_read.patch13.53 KB
Testbed results
field_settings_on_read.patchfailedFailed: 11577 passes, 1 fail, 1 exception Detailed results

#1

yched - July 3, 2009 - 21:43

Er, typo in the sample ugly-code-we-want-to-avoid :
$foo = isset($field['settings']['foo']) ? $field['settings']['foo'] : 'default_for_foo';, of course.

#2

System Message - July 3, 2009 - 21:50
Status:needs review» needs work

The last submitted patch failed testing.

#3

yched - July 3, 2009 - 22:14
Status:needs work» needs review

Fix test error.

AttachmentSize
field_settings_on_read-509736-3.patch 13.54 KB
Testbed results
field_settings_on_read-509736-3.patchfailedFailed: Failed to apply patch. Detailed results

#4

System Message - July 11, 2009 - 01:40
Status:needs review» needs work

The last submitted patch failed testing.

#5

yched - July 14, 2009 - 00:40
Status:needs work» needs review

Rerolled, moved a few kittens over to #518412: Minor cleanup in field.test

Would be cool to get in, there are other cleanups pending in this area ;-)

AttachmentSize
field_settings_on_read-509736-5.patch 12.58 KB
Testbed results
field_settings_on_read-509736-5.patchpassedPassed: 11664 passes, 0 fails, 0 exceptions Detailed results

#6

yched - July 14, 2009 - 00:45

Note to reviewers / core committers: the actual patch is like 6 lines, the rest is test adjustments :-)

#7

bjaspan - July 14, 2009 - 01:06
Status:needs review» reviewed & tested by the community

This patch increases the consistency of Field API by making field and instance objects more complete in more places.

#8

Dries - July 14, 2009 - 10:28
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#9

philipnet - July 16, 2009 - 09:39
Status:fixed» needs work
Issue tags:+PIFR 2.x blocker

This fails on the PIFR #2 clients :(

The change:

-class FieldInstanceTestCase extends DrupalWebTestCase {
+class FieldInstanceCrudTestCase extends DrupalWebTestCase {

Because of the name change, when the tests are run this causes a PHP exception which is not capture by the testbot.
Running the tests via the CLI/PHP script, reports:

Class 'FieldInstanceTestCase' not found in scripts/run-tests.sh on line 349

#10

yched - July 16, 2009 - 11:47

@philipnet: thanks for the report, but I'm a little confused.
This patch is now committed. So do you mean that current HEAD fails on PIFR #2 because a test class name is different from what it was 3 days ago ?

If so, I'd be tempted to call this a bug in PIFR ?

#11

philipnet - July 17, 2009 - 11:55
Status:needs work» fixed
Issue tags:-PIFR 2.x blocker

Sorry, my bad :(

It looks like the registry in D7 cached the old class name and the PHP script tried to call that. After a fresh install of HEAD I can't replicate the problem.

#12

System Message - July 31, 2009 - 12:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.