Hi, I’m using this piece of code to create a field named zoho_task_id in every node of the support_ticket type.
if (!field_info_field($field_name)) {
//drupal_set_message ("creating field");
//die();
// Create the field.
$field = array(
'field_name' => $field_name,
'type' => 'field_hidden_text',
'settings' => array(
'max_length' => 255,
),
'cardinality' => 1,
);
field_create_field($field);
// Create the instance.
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'support_ticket',
'label' => 'Zoho Task ID',
'description' => 'Zoho Task ID',
'required' => FALSE,
);
field_create_instance($instance);
watchdog('zoho', t('!field_name was added successfully.', array('!field_name' => $field_name)));
//drupal_set_message ("created field " . $field_name);
}
else {
watchdog('zoho', t('!field_name already exists.', array('!field_name' => $field_name)));
}
Now I want to override the hook_field_schema to add index and unique key into the field.
function zoho_field_schema($field)
{
//Config::display_test_result_as_drupal_message($field);
echo "Calling hook_field_schema....";
watchdog('zoho', "Calling hook_field_schema....");
watchdog('zoho', t('Creating !field_name....', array('!field_name' => $field['field_name'])));
if($field['field_name'] == Config::$zoho_task_id_fieldname)
{
watchdog('zoho', t('Modifying !field_name.', array('!field_name' => $field['field_name'])));
return array(
'columns' => array(
'value' => array(
'type' => 'varchar',
'size' => '255',
'not null' => FALSE,
),
),
'indexes' => array(
'value' => array('value'),
),
'unique keys' => array(
'value' => array('value'),
),
);
}
elseif($field['field_name'] == Config::$zoho_comment_id_fieldname)
{
watchdog('zoho', t('Modifying !field_name.', array('!field_name' => $field['field_name'])));
return array(
'columns' => array(
'value' => array(
'type' => 'varchar',
'size' => '255',
'not null' => FALSE,
),
),
'indexes' => array(
'value' => array('value'),
),
'unique keys' => array(
'value' => array('value'),
),
);
}
}
As you can see, I used the watchdog function to log when the function is called. But when I checked the log, there is no message “Calling hook_field_schema” in there. And when I check the data table field_data_zoho_task_id, I see there is no unique key nor index in the zoho_task_id_value column. I guesss these mean the hook_field_schema wasn’t called. I wonder how can I get it work? I put the function zoho_field_schema in the .install file as instructed in https://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_schema/7 but nothing happened. Please help me with this problem. Thanks.