By jerrac on
I am using Drupal 7 Alpha 7.
My code:
function fieldTesting_field_schema($field)
{
switch ($field['type']) {
case 'latlng':
$columns = array(
'latitude' => array(
'type' => 'float',
'not null' => FALSE,
),
'longitude' => array(
'type' => 'float',
'not null' => FALSE,
),
);
break;
}
return array('columns' => $columns);
}
Is there anything wrong with that?
I ask because of this error:
Notice: Undefined index: schema_fields_sql in C:\wamp\www\d7a7\includes\entity.inc on line 254 Catchable fatal error: Argument 2 passed to SelectQuery::fields() must be an array, null given, called in C:\wamp\www\d7a7\includes\entity.inc on line 273 and defined in C:\wamp\www\d7a7\includes\database\select.inc on line 1189
My goal is to create a new field for a latitude and longitude pair. You would enter the latitude in one text field, and the longitude in another.
Comments
Remove your switch
Completely remove your switch structure and let me know:
Thanks! That worked! I pulled
Thanks! That worked!
I pulled the initial schema code from this tutorial: http://www.figover.com/node/16
Why was there a switch statement in that tutorial?
Also, what clued you in to what was wrong with my code? I'd like to know, just in case I run into something similar in the future.
Multiple field types
Hi David,
the
switch()is necessary when your module creates different field types.The
number.moduledoes that for obvious reasons:But if you handle only one, there is no need for it.
Here's what's declared in the famous
taxonomy.module:In your case, I guessed your
hook_field_schema()returned NULL, and broke something in the calling function.Which makes me wonder whether you did the right definiton in
hook_field_infofor 'latlng'... can you copy/paste it here ?the switch() is necessary
Ah, I see. That's why it worked when I was creating separate fields for latitude and longitude.
Here's my hook_field_info().
Seems OK
Seems OK to me. Check my comment at http://drupal.org/node/919620#comment-3480158.