From webchick in #369562: Field: Trivial cleanup
"it would be wonderful to have a fields in core sprint attendee do a "TODO" pass and just make sure the list matches our actual remaining todos"

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Title: feilds : do a pass of TODOs checking » fields : do a pass of TODOs checking
crotown’s picture

Assigned: Unassigned » crotown

I'll take this on and post what I find when I'm done.

crotown’s picture

I updated my view of HEAD a few minutes ago and there are 89 occurrences of "TODO" in the Field module. Now I need to know where the current TODO list is located so I can compare. Anyone? Thanks in advance!

crotown’s picture

bjaspan (over IRC) thought that this issues is more involved than a 2. He suggested I look through the TODO and fix what I can and post patches, so that will be my approach. As possible, I will look to comparing with the issue queue open issues at http://drupal.org/project/issues/drupal?status=Open&priorities=All&categ..., but as he suggested, that may be a bit much for me as a newcomer...

crotown’s picture

Assigned: crotown » Unassigned

I'm not getting to this in a timely fashion, and many of the TODO comments require advanced knowledge of the Field API, who is working on what, etc... So I am returning this one to the larger group.

fgm’s picture

Status: Active » Needs review
FileSize
1.28 KB

Not sure whether this is the proper issue, but here is one patch for one of the TODOs: the one about field name length.

fgm’s picture

In addition, fixing this made me wonder: currently, nothing prevents field_create_field from creating fields with names starting with a number instead of [a-z_]. Shouldn't this be prevented ?

yched’s picture

The patch looks good. Can we just add a corresponding test in 'Field CRUD tests' ? I think there's a // TODO: test other failures line in there.

You're perfectly right that we should prevent field names starting with a number. It would turn into invalid $object->1_foo properties and $1_foo variable names in templates.
Care to roll that in your patch ?

fgm’s picture

FileSize
4 KB

Here is a revised version. It now checks the start character.

I've also added simpletest for illegal field names (non-alpha first char, and non-alnum other char).

I've also added a test for the field name length, however here I ran into a limitation of the simpletest mechanism (see patch for details) and had to remove that test. Not sure there is an actual solution, and it would likely have to be at the simpletest level anyway.

yched’s picture

Heh, true... well, I think we need to forget about that specific test, then. Not *that* bad. Let's just leave a comment on why we don't test this...
Other than that, looks ready to me.

fgm’s picture

FileSize
3.62 KB

Rerolled with just a comment instead of the test.

yched’s picture

Status: Needs review » Needs work

Great, only minor nitpicking now.

+++ modules/field/field.crud.inc	4 Aug 2009 20:00:56 -0000
@@ -208,11 +208,17 @@
+  // We use drupal_strlen because the DB layer assumes that column widths
+  // are given in characters, not bytes.
+++ modules/field/field.test	4 Aug 2009 20:00:57 -0000
@@ -1296,6 +1296,33 @@
+    // the length of which exceeds MySQL max schema item size of 64 bytes, causing

Comments should wrap at 80 characters. The 1st line above is too short, the other too long ;-)

+++ modules/field/field.crud.inc	4 Aug 2009 20:00:56 -0000
@@ -208,11 +208,17 @@
+  // Field name cannot be longer than 32 characters
+++ modules/field/field.test	4 Aug 2009 20:00:57 -0000
@@ -1296,6 +1296,33 @@
+    // Check that field name must start with a letter or _
...
+    // Check that field name must only contain lowercase alnum or _

Missing period at the end of the sentence. Also, I'm not sure 'alnum' abbreviation is good practice, we usually avoid abbreviations in comments.

This review is powered by Dreditor.

yched’s picture

Hm, I might have replied a little too fast in #10. Actually I don't understand why we couldn't test that a field name > 32 chars fails : it's supposed to raise an exception before it reaches the point where a table would be created, so we shouldn't care that MySQL would fail to create the table because of simpletest prefix ?

fgm’s picture

It fails if we test it with a name that should be valid, because it is 31 characters long: in that case, the assertion succeeds and processing continues to create the field, triggering the mysql error because the table name is now 65 (minimum) characters long. This is not demonstrated by the test in its current state, though, only by the "positive" test which I wrote and removed before committing, which tests that creation succeeds below 32 and fails above, as it succeeds only below 30 or 29 depending on the number of previously created fields (number of digits in the field fid).

yched’s picture

Well, there's no need to test that field_name < 32 char works, the whole field.test demonstrates that ;-)
We just want to check that > 32 fails with a FieldException.

fgm’s picture

Status: Needs work » Needs review
FileSize
3.71 KB

Here it is with the test reinserted and commenting style fixed.

yched’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
5.43 KB

Thanks. Just fixed a couple minor points (missing trailing periods, trailing whitespaces) + grouped all failure checks at the bottom of testCreateField().
Other than that, RTBC.
Thanks !

yched’s picture

Status: Reviewed & tested by the community » Active

Dries committed #17.
Back to active for the rest of the TODOs :-)

fgm’s picture

Status: Active » Needs review
FileSize
2.32 KB

Taken into account active/inactive field and instances.

fgm’s picture

Issue tags: +Fields in Core

Adding Fields in Core tag.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine by me. Thks fgm !

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Setting back to 'code needs work' for the remaining TODOs. Thanks fgm.

Dries’s picture

Status: Fixed » Needs work
h3rj4n’s picture

TODO's find in the fields module:

./field.form.inc:293: * TODO : convert to a template.
./field.crud.inc:478:  // TODO: Check that the widget type is known and can handle the field type ?
./field.crud.inc:479:  // TODO: Check that the formatters are known and can handle the field type ?
./field.crud.inc:480:  // TODO: Check that the display view modes are known for the entity type ?
./field.crud.inc:574:    // TODO: what if no 'default_widget' specified ?

The first one can be found on the function function theme_field_multiple_value_form($variables) { ... } on line 301. There TODO claims that the HTML part should be in a seperate HTML tpl. The HTML is as follows:

$output = '<div class="form-item">';
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => $table_id, 'class' => array('field-multiple-table'))));
$output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
$output .= '<div class="clearfix">' . drupal_render($add_more_button) . '</div>';
$output .= '</div>';

I'm not shure if these lines should be in a seperate html tpl. Wouldn't it be a little bit overkill?
http://api.drupal.org/api/drupal/modules!field!field.form.inc/function/theme_field_multiple_value_form/7
Suggestion: Remove the TODO from description.

The second, third and fourth one can be found in function field_create_instance($instance) { ... } on line 454 with a notice:

  // TODO: Check that the widget type is known and can handle the field type ?
  // TODO: Check that the formatters are known and can handle the field type ?
  // TODO: Check that the display view modes are known for the entity type ?
  // Those checks should probably happen in _field_write_instance() ?
  // Problem : this would mean that a UI module cannot update an instance with a disabled formatter.

I couldn't find any issues regarding these TODO's.
http://api.drupal.org/api/drupal/modules!field!field.crud.inc/function/field_create_instance/7

Last one can be found in _field_write_instance($instance, $update = FALSE) { ... } on line 554.
http://api.drupal.org/api/drupal/modules!field!field.crud.inc/function/_field_write_instance/7

yched’s picture

@h3rj4n : yes, I think those @todos can be removed, actually.

h3rj4n’s picture

@yched: All of them?

  • Dries committed 4a3dd05 on 8.3.x
    - Patch #372330 by fgm, yched, et al: better validation of field names.
    
    
  • Dries committed 157f6ee on 8.3.x
    - Patch #372330 by fgm: improved error messages to improve usability.
    
    

  • Dries committed 4a3dd05 on 8.3.x
    - Patch #372330 by fgm, yched, et al: better validation of field names.
    
    
  • Dries committed 157f6ee on 8.3.x
    - Patch #372330 by fgm: improved error messages to improve usability.
    
    

  • Dries committed 4a3dd05 on 8.4.x
    - Patch #372330 by fgm, yched, et al: better validation of field names.
    
    
  • Dries committed 157f6ee on 8.4.x
    - Patch #372330 by fgm: improved error messages to improve usability.
    
    

  • Dries committed 4a3dd05 on 8.4.x
    - Patch #372330 by fgm, yched, et al: better validation of field names.
    
    
  • Dries committed 157f6ee on 8.4.x
    - Patch #372330 by fgm: improved error messages to improve usability.
    
    

  • Dries committed 4a3dd05 on 9.1.x
    - Patch #372330 by fgm, yched, et al: better validation of field names.
    
    
  • Dries committed 157f6ee on 9.1.x
    - Patch #372330 by fgm: improved error messages to improve usability.