Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If a component is created in hook_webform_component_info(), such that $components[whatever]['features']['title'] is FALSE, an error is thrown when a new component of this type is created:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO {webform_component} (nid, cid, pid, form_key, name, type, value, extra, required, weight) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 17555 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => student [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => user [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => a:5:{s:11:"description";s:0:"";s:17:"description_above";i:0;s:15:"wrapper_classes";s:0:"";s:11:"css_classes";s:0:"";s:7:"private";i:0;} [:db_insert_placeholder_8] => 0 [:db_insert_placeholder_9] => 0 ) in webform_component_insert() (line 813 of .../sites/all/modules/webform/includes/webform.components.inc).
That's because of this section in webform_component_edit_form():
if (webform_component_feature($component['type'], 'title')) {
$form['name'] = array(
'#type' => 'textfield',
'#default_value' => $component['name'],
'#title' => t('Label'),
'#description' => t('This is used as a descriptive label when displaying this form element.'),
'#required' => TRUE,
'#weight' => -10,
'#maxlength' => NULL,
);
}
This means that if 'title' is FALSE, the 'name' form field is not created at all. This eventually leads to a NULL being passed to the SQL INSERT.
The solution is to create an empty 'name' element, as in the attached patch.
Comment | File | Size | Author |
---|---|---|---|
webform-null-name.patch | 491 bytes | Gribnif | |
|
Comments
Comment #2
Liam MorlandComment #3
Liam MorlandThanks for the patch.
I think the problem is the NOT NULL constraint on the column. If a component doesn't have a title, that means it should have no title, NULL, not a title of empty string.
We probably need a patch that drops the NOT NULL constraint. Check first that there isn't other stuff that depends on this column being NOT NULL.