CCK Mashup -- Oh The Things You Can Do!
Abstract:
The Content Construction Kit (CCK) is pretty handy by itself, but really useful when hooked into other modules. We'll look at ways to combine CCK with Views, Panels, Devel, and lots of other modules to make Drupal sing and dance.
Presenters:
Karen Stevenson
Agenda
We'll look at ways to combine CCK with other modules to do interesting and exciting things, including:
- Protect fields with Content Permissions.
- Add fields and relationships to Views.
- Insert fields and groups into Panels.
- Generate field data with Devel.
- Populate fields from feeds using Feed API.
- Make clickable maps into input widgets using GMap and Location.
- Inject pictures into fields using Flickr.
And more!
Goals
The goal for this session is to demonstrate ways to extend Drupal by combining modules and/or adding a bit of custom code to achieve solutions that are more than the sum of their parts.
Resources
Some of the modules to be discussed include:
- CCK, and all the CCK core modules
- Views
- Panels
- Devel
- Feed API
- GMap
- Location
5 Comments
Using multiselect module with Custom Blocks
Thanks you so much for sharing this model for making blocks editable on the front end. I have added the Multiselect module to my site, which provides a multiselect widget for CCK field definitions. I have applied this to the "Show on page" field in order to assign a particular block to multiple pages. It is not working. Instead it doesn't show on any pages that I have assigned in the multiselect field. I'm wondering what needs to be changed about the custom block view in order to handle the multiple nodereference selection.
Video
http://www.archive.org/details/DrupalconDc2009-CckMashupOhTheThingsYouCanDo
Recorded by Robert Nelson Vance
Custom Blocks
Here is an export of the Custom block type and the view used in the presentation today.
$content[type] = array (
'name' => 'Block',
'type' => 'block',
'description' => 'Dynamic block content for site landing pages.',
'title_label' => 'Title',
'body_label' => 'Body',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => false,
'sticky' => false,
'revision' => false,
),
'old_type' => 'block',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'comment' => '0',
'comment_default_mode' => '4',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '3',
'comment_anonymous' => 0,
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '0',
'ant' => '0',
'ant_pattern' => '',
'ant_php' => 0,
);
$content[fields] = array (
0 =>
array (
'label' => 'Show on page',
'field_name' => 'field_block_related',
'type' => 'nodereference',
'widget_type' => 'nodereference_select',
'change' => 'Change basic information',
'weight' => '-4',
'autocomplete_match' => 'contains',
'description' => '',
'default_value' =>
array (
0 =>
array (
'nid' => '',
),
),
'default_value_php' => '',
'default_value_widget' => NULL,
'group' => false,
'required' => 0,
'multiple' => '0',
'referenceable_types' =>
array (
'event' => 'event',
'story' => 'story',
'team' => 'team',
'block' => 0,
'book' => 0,
'fisherman' => 0,
'groups' => 0,
'page' => 0,
'picture' => 0,
'result' => 0,
'test' => 0,
'place' => false,
),
'advanced_view' => '--',
'advanced_view_args' => '',
'op' => 'Save field settings',
'module' => 'nodereference',
'widget_module' => 'nodereference',
'columns' =>
array (
'nid' =>
array (
'type' => 'int',
'unsigned' => true,
'not null' => false,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
'exclude' => 0,
),
'teaser' =>
array (
'format' => 'default',
'exclude' => 0,
),
'full' =>
array (
'format' => 'default',
'exclude' => 0,
),
4 =>
array (
'format' => 'default',
'exclude' => 0,
),
2 =>
array (
'format' => 'default',
'exclude' => 0,
),
3 =>
array (
'format' => 'default',
'exclude' => 0,
),
'email_plain' =>
array (
'format' => 'default',
'exclude' => 0,
),
'email_html' =>
array (
'format' => 'default',
'exclude' => 0,
),
'token' =>
array (
'format' => 'default',
'exclude' => 0,
),
),
),
);
$content[extra] = array (
'title' => '-5',
'body_field' => '-3',
'menu' => '-1',
'book' => '-2',
);
$view = new view;
$view->name = 'custom_blocks';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'field_block_related_nid' => array(
'label' => 'Show on page',
'link_to_node' => 1,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_block_related_nid',
'table' => 'node_data_field_block_related',
'field' => 'field_block_related_nid',
'relationship' => 'none',
),
'title' => array(
'label' => 'Title',
'link_to_node' => 0,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'body' => array(
'label' => 'Body',
'exclude' => 0,
'id' => 'body',
'table' => 'node_revisions',
'field' => 'body',
'relationship' => 'none',
),
'delete_node' => array(
'label' => 'Delete link',
'text' => '',
'exclude' => 0,
'id' => 'delete_node',
'table' => 'node',
'field' => 'delete_node',
'relationship' => 'none',
),
'edit_node' => array(
'label' => 'Edit link',
'text' => '',
'exclude' => 0,
'id' => 'edit_node',
'table' => 'node',
'field' => 'edit_node',
'relationship' => 'none',
),
'status' => array(
'label' => 'Published',
'type' => 'yes-no',
'not' => 0,
'exclude' => 0,
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'field_block_related_nid' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'break_phrase' => 0,
'not' => 0,
'id' => 'field_block_related_nid',
'table' => 'node_data_field_block_related',
'field' => 'field_block_related_nid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => '',
'validate_argument_node_type' => array(),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_argument_is_member' => 0,
'validate_argument_signup_status' => 'any',
'validate_argument_signup_node_access' => 0,
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'block' => 'block',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('style_options', array(
'grouping' => '',
));
$handler->override_option('row_options', array(
'inline' => array(
'edit_node' => 'edit_node',
'delete_node' => 'delete_node',
),
'separator' => '|',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('arguments', array());
$handler->override_option('title', 'Custom Feature Blocks');
$handler->override_option('header', 'Create block content.');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 1);
$handler->override_option('empty', 'No blocks have been created. ');
$handler->override_option('empty_format', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'field_block_related_nid' => 'field_block_related_nid',
'title' => 'title',
'body' => 'body',
'delete_node' => 'delete_node',
'edit_node' => 'edit_node',
'status' => 'status',
),
'info' => array(
'field_block_related_nid' => array(
'separator' => '',
),
'title' => array(
'sortable' => 0,
'separator' => '',
),
'body' => array(
'separator' => '',
),
'delete_node' => array(
'separator' => '',
),
'edit_node' => array(
'separator' => '',
),
'status' => array(
'sortable' => 0,
'separator' => '',
),
),
'default' => '-1',
));
$handler->override_option('path', 'blocks/edit');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'Feature Blocks',
'weight' => '0',
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Custom block', 'custom_block_1');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'link_to_node' => 0,
'exclude' => 1,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'edit_node' => array(
'label' => '',
'text' => '',
'exclude' => 0,
'id' => 'edit_node',
'table' => 'node',
'field' => 'edit_node',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'delete_node' => array(
'label' => '',
'text' => '',
'exclude' => 0,
'id' => 'delete_node',
'table' => 'node',
'field' => 'delete_node',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'body' => array(
'label' => '',
'exclude' => 0,
'id' => 'body',
'table' => 'node_revisions',
'field' => 'body',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'block' => 'block',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('block_description', 'Custom feature');
$handler->override_option('block_caching', -1);
Thanks..how do you add tabs to block?
Thanks so much for this. It is exactly what I went to DC09 to find out how to do.
I've got it working but can't figure out how to add the add|delete tab to the custom block. In Views there is a MENU tab when you are making a page but not a block. Help!
Co-Presenter
I can't edit the site but wanted to be sure everyone knows how to contact the co-presenter who demonstrated using CCK with Feed API. It was Alex Barth of Development Seed.