CCK field with multiple fields inside - drupal

im new on drupal and im having a problem with CCK fields.
I made a custom cck field and the install schema its like this:
function usig_location_field_schema($field) {
return array(
'columns' => array(
'location_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'lat_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'lon_cck_usig' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
);
}
But when i save the new content .. drupal crash with this log :
Fatal error: Cannot create references to/from string offsets nor
overloaded objects in /includes/common.inc on line 6392
So .. i know that im doing something wrong. I just dont know which hook use to save the fields.. (its possible save various fields at once ?)
Thx for all and sry for my english

You can always use this great module called Field Collection
Cheers

Related

Drupal 6 schema not installing all tables

So this has been driving me crazy for 2 days, I have a module I've written that uses 3 DB tables, 2 of them install perfectly, and this is the third one:
$schema['tags_twistal'] = array(
'description' => t('Taxonomy for videos (tags)'),
'fields' => array(
'vid' => array(
'description' => t('The video ID'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'tag' => array(
'description' => t('The tag name'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array('tag','vid'),
);
All I can think is that it has something to do with the primary key that I set, I've also tried:
'unique keys' => array(
'tag_vid' => array('tag', 'vid'),
),
'primary key' => array('tag_vid'),
Any ideas? I'm about to pull my hair out!
I'm having a similar issue in Drupal 7.
The tables of mine that install correctly are those which have a matching entry in the array returned by hook_node_info().
It looks as though Drupal will not create any tables that are not referenced in hook_node_info(), even if they are explicitly enumerated in hook_scheme(). I can't find this documented anywhere, but it matches my experience, and is a pain in the butt.

Drupal7 .install script not working

I am trying to convert my module from drupal6 to drupal 7 this is my code. The database table is not created.
function example_install() {
drupal_install_schema('example');
}
/**
* Implements hook_schema().
*/
function example_schema() {
$schema['example'] = array(
'description' => 'example settings',
'fields' => array(
'name' => array(
'description' => 'name',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'age' => array(
'description' => 'age',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
) ,
);
return $schema;
}
Can any one explain whats wrong.
You don't want to run drupal_install_schema() yourself in Drupal 7, hook_schema() is called automatically if it exists in the .install file. That will probably cause a few problems but you'd still expect the table to be created at least once.
Once you've removed hook_install() try uninstalling (not just disabling) your module, then re-enabling it. I recommend the Devel module to do this as it provides a page (devel/reinstall) where you can easily force a reinstall of a module.
If you don't want to do that though, go to the modules page, disable the module, then click the 'Uninstall' tab at the top to uninstall it fully. Then go back to the modules page and re-enable it.
Doing this should force Drupal to re-run your hook_schema() script and the table should be created.

set default value for custom field type: list_boolean / options_onoff

$instance = array(
'field_name' => $field_name,
'entity_type' => $entity,
'bundle' => $bundle,
'field types' => 'list_boolean',
'widget' => array(
'type' => 'options_onoff',
'settings' => array('display_label' => 1)
),
'default_value' => array(array('value' => 1)),
);
this is not taken, and i have to save it twice in the admin contenttype - field/edit,
until it takes it ...
i now exported the finished field with the features module,
and took the generated code - suddenly it works, with default_value
i guess i was missing the property module on the field, also field types is inexistant ..
In your field definition, you have to set the allowed_values in the settings array in order for the default_value in the instance to get picked up.
so like this assuming you are doing this in a module
$fields[] = array(
'field_name' => '$field_name',
'type' => 'list_boolean',
'settings' => array(
'allowed_values' => drupal_map_assoc(range(0, 1)),
),
);
Instead of using 'default_value', I got it to work by using 'default_value_function' and creating a function that returns array(array('value' => 1)).

Drupal 7: Make custom content translatable

I'm creating a custom module which enables me to add Countries to a custom table in the database. I'll do later more with it, but as I got stuck at the beginning, I can't go on.
First my piece of code:
function partners_schema()
{
$schema['partners_country'] = array(
'description' => 'TODO: please describe this table!',
'fields' => array(
'id' => array(
'description' => 'auto inc id of country',
'type' => 'serial',
'not null' => true,
),
'name' => array(
'description' => 'name of country',
'type' => 'varchar',
'length' => '255',
'not null' => true,
'translatable' => true,
),
'needDistributor' => array(
'description' => 'is a distributor needed',
'type' => 'int',
'size' => 'tiny',
'not null' => true,
),
),
'primary key' => array('id'),
);
return $schema;
}
The code above generates my Database table. After searching I found that I can add 'translatable' => true to my schema, so Drupal knows that this field is translatable content.
I've added a form, to insert data into that schema, but now I got stuck. What do I have to do, that the user is able to translate the column name?
Thanks for your help.
Have a look at the accepted answer on this post it should help clear a few things up.

ER-Diagram : How to manage sessions ? (parallel drupal <-> symfony2)

I am building my app and have been annoyed concerning sessions storage. I am a newbie about sessions. I am working with Symfony2 and MySQL, and as Symfony is storage-agnostic, I am searching into the Drupal 7 diagram to find a good model.
So I wondered a couple of things :
How to manage sessions in an Entity-Relationship diagram ?
In drupal 7 diagram, what do sessions->fields mean ?
Sessions -> uid (int(10)) -> OK
Sessions -> sid (varchar(128)) ?
Sessions -> ssid (varchar(128)) ?
Sessions -> hostname (varchar(128)) -> OK
Sessions -> timestamp (int(11)) -> guessing date of connection
Sessions -> cache (int(11)) -> Why only an integer ?
Sessions -> session (longblob) -> What do you put inside ?
As I imagined my own diagram, I had 2 tables :
Session that stored the sessionId, cookie and establishing date
User_Session, association between Sessions and Users, which stores IP address and DateInit.
Why not storing one session by Cookie and storing also each time the user connects ?
If someone could help me understand and help me find the true entity-relationship model...
Description of the session table from Drupal 7 is given in its system_schema() function:
$schema['sessions'] = array(
'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'sid' => array(
'description' => "A session ID. The value is generated by Drupal's session handlers.",
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'ssid' => array(
'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'hostname' => array(
'description' => 'The IP address that last used this session ID (sid).',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'cache' => array(
'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'session' => array(
'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
),
'primary key' => array(
'sid',
'ssid',
),
'indexes' => array(
'timestamp' => array('timestamp'),
'uid' => array('uid'),
'ssid' => array('ssid'),
),
'foreign keys' => array(
'session_user' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
But this is not an E-R model. Also, it heavily depends on Drupal own session handling function.

Resources