Drupal 7: Make custom content translatable - drupal

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.

Related

Accessing value of wp_customize setting

So, I've got the following code:
function themename_customize_register($wp_customize){
// Display date
$wp_customize->add_section('display_date_section', array(
'title' => 'Datum weergeven',
'description' => 'Wil je de datum weergeven?',
'priority' => 120,
));
$wp_customize->add_setting('display_date', array(
'default' => 'value1',
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('display_date_section', array(
'label' => 'Datum weergeven:',
'section' => 'display_date_section',
'settings' => 'display_date',
'type' => 'theme_mod',
'choices' => array(
'value1' => 'Ja',
'value2' => 'Nee',
),
));
}
add_action('customize_register', 'themename_customize_register');
How can I access the value of the setting? Right now whenever I try to access it (either through get_theme_mod or $wp_customize->get_settings) My main goal with the code is to let users have the ability to control wether they want to display the date or not. Can somebody help me? :D

make CMB text_datetime_timestamp field repeatable

I'm using CMB to creat custom fields for wordpress custom post
https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress
I'm using text_datetime_timestamp to set date and time and I need to make this field repeatable which is not
as I go through the documentation we can make new fields but I can't figure out how it make "text_datetime_timestamp" field repeatable
any body can show me the way to accomplish that ?
thank you
I did not find a solution to make the field repeatable so I put the field inside group and made it repeatable
array(
'id' => $prefix . 'repeat_date_group',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => __( 'Date/Time {#}', 'cmb' ),
'add_button' => __( 'Add Another Date/Time', 'cmb' ),
'remove_button' => __( 'Remove Date/Time', 'cmb' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Date/Time',
'desc' => '',
'id' => $prefix . 'course_date',
'type' => 'text_datetime_timestamp'
),
),
),
I hope this answer will help somebody
Well here is my code, you may try this
$cmb= new_cmb2_box( array(
'id' => $prefix.'testing',
'title' => _('Testing'),
'object_types' => array('post'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
));
$cmb->add_field( array(
'name' => 'Test Date/Time Picker Combo (UNIX timestamp)',
'id' => 'wiki_test_datetime_timestamp',
'type' => 'text_datetime_timestamp',
'repeatable' => true,
) );

CCK field with multiple fields inside

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

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.

Correct way to use Drupal 7 Entities and Field API

I'm trying to use Drupal 7's entities and field API to correctly build a new module. What I have been unable to understand from the documentation is the correct way to use the new API to create a 'content type' (not a node type) with a number of set fields, such as Body.
I'm trying to set up the entity using hook_entity_info, then I believe I need to add the body field using field_create_instance, but I can't seem to get it to work.
In mycontenttype.module:
/**
* Implements hook_entity_info().
*/
function mycontenttype_entity_info() {
$return = array(
'mycontenttype' => array(
'label' => t('My Content Type'),
'controller class' => 'MyContentTypeEntityController',
'base table' => 'content_type',
'uri callback' => 'content_type_uri',
'entity keys' => array(
'id' => 'cid',
'label' => 'title',
),
'bundles' => array(
'mycontenttype' => array(
'label' => 'My Content Type',
'admin' => array(
'path' => 'admin/contenttype',
'access arguments' => array('administer contenttype'),
),
),
),
'fieldable' => true,
),
);
return $return;
}
/**
* Implements hook_field_extra_fields().
*/
function mycontenttype_field_extra_fields() {
$return['mycontenttype']['mycontenttype'] = array(
'form' => array(
'body' => array(
'label' => 'Body',
'description' => t('Body content'),
'weight' => 0,
),
),
);
return $return;
}
Then does this go in the .install file?
function mycontenttype_install() {
$field = array(
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_types' => array('survey'),
'translatable' => TRUE,
);
field_create_field($field);
$instance = array(
'entity_type' => 'mycontenttype',
'field_name' => 'body',
'bundle' => 'mycontenttype',
'label' => 'Body',
'widget_type' => 'text_textarea_with_summary',
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_default',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
),
),
);
field_create_instance($instance);
}
I think your problem is that if node module is installed, there is already a field named 'body'. You should either re-name your field to something like 'mycontenttype_body' (comment.module uses comment_body), or re-use the 'body' field and skip the adding the field part and skip to adding the instance of it. The former is recommended over the latter.
Every field has an array property, entity_types, which limits the entities to which the field can be attached.
The best Drupal solution I can find, hook_field_create_field, can alter fields as they are created, but that's no good for the body field which is created on installation.
So my solution is just to edit the database directly in my hook_install
$data_col = db_query("SELECT data from field_config where field_name = 'body'")->fetchAssoc();
$data = unserialize($data_col['data']);
$data['entity_types'][] = 'MY_ENTITY_TYPE';
db_update('field_config')
->fields(array('data' => array('data' => serialize($data))))
->condition('field_name', 'body')
->execute();
just started down the same path here is a video from fago
Here's a nice repo to start: Lawmakers entity

Resources