Theming/building own module - drupal

I'm new to Drupal and want to make my own module for Drupal 7. But i don't understand the theming / templates system in drupal jet. So i will be ready glad if some one can help me with that. I'm building a twitter module that shows the latest tweets with a certain #hashtag. Loading the data is not the problem. The problem is choosing the best solution for displaying the data. I want to show it like this:
[the link to twitter author_url]
[title] by [author_url]
[close the link]
Thanks for the help.
twitter.install file: (my custom fields)
array(
'twitter_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'author' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'author_url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''
),
'published' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => ''
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
'description' => array(
'type' => 'text',
'not null' => FALSE
),
'link' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
'image' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE
),
),
'primary key' => array('twitter_id'),
);
return $schema;
}

You should collaborate with http://drupal.org/project/twitter instead of writing a new module.

Related

getting error 500 after trying to add a tab to wordpress customizer

i'm trying to add a tab to my wordpress customizer.
i use the next code:
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_settings('facebook',
array(
'default' => 'http://facebook.com/ahiad'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize,'txtFacebookAddress',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
)));
}
the problem is every time i run this piece of code in my website, i get an error 500, could not spot the problem here...
You are using $wp_customize->settings which is not not exists, Please use $wp_customize->setting.
Please try below code :
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_setting('facebook',
array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
'default' => 'http://facebook.com/ahiad',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '',
));
$wp_customize->add_control('facebook',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
));
}
I hope it will helps you. Thanks

How to add custom fields in ACF programmatically?

I want to programmatically add a tab with repeater inside but I can't seem to find a solution, I've googled all available resources but still not working.
I already tried using acf_add_local_field_group and acf_add_local_field but still no luck.
Well I can create a tab using acf_add_local_field but when I tried to add a child which in this case a repeater OR even a text field it still doesn't work.
Here's my code to create a tab and its child but the child doesn't work.
acf_add_local_field(array(
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => '',
'parent' => 'field_5bd14c9349930',
'fields' => array (
array(
'key' => 'field_2',
'label' => 'This is a test',
'name' => 'my_test',
'type' => 'text',
)
)
));
You should use acf_add_local_field_group to construct the whole field group.
Here's the proper code for adding a group and a custom tab with single repeater field inside:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_1',
'title' => 'My Group',
'fields' => array (
array (
'key' => 'field_unique_key',
'label' => 'First Tab',
'name' => '',
'type' => 'tab',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'placement' => 'top',
'endpoint' => 0,
),
array (
'key' => 'field_unique_key',
'label' => 'Simple Repeater',
'name' => 'simple_repeater',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 10,
'layout' => 'table',
'button_label' => 'Add row',
'sub_fields' => array ( // Here you can add as many subfields for this repeater as you want
array (
'key' => 'field_unique_key',
'label' => 'Link',
'name' => 'link',
'type' => 'link', // example link type
'instructions' => 'Link name and URL',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
),
),
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
));
endif;

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,
) );

create custom content type with custom table fields in drupal 7

I want to create a module in which, when I install that module, it should create custom table defined in homepage_blocks_schema(), create content-type defined in homepage_blocks_install() and in that content type, create custom fields same as my schema.
Here is function,
function homepage_blocks_schema() {
$schema['homepage_blocks'] = array(
'fields' => array(
'hid' => array(
'type' => 'int',
'length' => 11,
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
),
'image' => array(
'type' => 'varchar',
'length' => 255,
),
),
'primary key' => array('hid'),
);
return $schema;
}
homepage_blocks_install() {
$homepage_blocks = array(
'type' => 'homepage_blocks',
'name' => $t('Homepage Blocks'),
//'base' => 'node_content',
'base' => 'homepage_blocks',
'custom' => true,
'modified' => true,
'locked' => false,
'title_label' => $t('Homepage Blocks')
);
$content_type = node_type_set_defaults($homepage_blocks);
//node_add_body_field($content_type, 'Body'); // add the body field to the content type
node_type_save($content_type); // create the content type
variable_set('node_options_homepage_blocks', array('status'));
variable_set('comment_homepage_blocks', 'COMMENT_NODE_HIDDEN'); // hide comments for this node.
variable_set('node_submitted_homepage_blocks', false); // Hide date and author information
//drupal_install_schema('homepage_blocks');
foreach (_homepage_blocks_installed_fields() as $field) { // Create all the fields we are adding to our content type.
//krumo(field_create_field($field));
field_create_field($field);
}
foreach (_homepage_blocks_installed_instances() as $instance) { // Create all the instances for our fields.
$instance['entity_type'] = 'node';
$instance['bundle'] = 'homepage_blocks';
field_create_instance($instance);
}
}
function _homepage_blocks_installed_fields() {
$t = get_t();
$fields = array(
'hmblock_title' => array(
'field_name' => 'hmblock_title',
'label' => $t('Title'),
//'cardinality' => 1,
'type' => 'text',
'settings' => array(
'max_length' => 255,
),
),
'hmblock_image' => array(
'field_name' => 'hmblock_image',
'label' => $t('Image'),
//'cardinality' => 1,
'type' => 'image',
'settings' => array(
'default_image' => 0,
'uri_scheme' => 'public',
),
),
);
//$fields = drupal_get_schema('homepage_blocks');
return $fields;
}
function _homepage_blocks_installed_instances() {
$t = get_t();
$instances = array(
'hmblock_title' => array(
'field_name' => 'hmblock_title',
'label' => $t('Title'),
'cardinality' => 1,
'widget' => array(
'type' => 'text_textfield',
'settings' => array('size' => 255),
),
),
'hmblock_image' => array(
'field_name' => 'hmblock_image',
'label' => $t('Image'),
'cardinality' => 1,
'type' => 'image',
'settings' => array(
'alt_field' => 1,
'file_directory' => 'image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '50mb',
'max_resolution' => '',
'min_resolution' => '',
'title_field' => 1,
'user_register_form' => FALSE,
),
'widget' => array(
'settings' => array(
'preview_image_style' => 'thumbnail',
'progress_indicator' => 'throbber',
),
)
),
);
return $instances;
}
This code creates table and content type but not its fields..
Can anyone help ?
There is an easier way
you can create your custom type using drupal core and fields module and then export it into a module using Features module.
You can find a full guide here : Bundling site settings using Features

Resources