Tag Archive for cck

Drupal – Get the image path of a CCK field from the fid

$file = field_file_load($node->website_logo_fid);
$output .= "<p><img src="".$file['filepath']."" alt="" /></p>";

source

Render a CCK Image Field

function render_image_field($node,$name,$title=null,$divclass=null,$limit=0,$start=0) 
{


$field_name = 'field_'.$name;
$field = $node->{$field_name};

$limit = ($limit == 0) ? count($field): $limit;

for ($i=$start; $i < $limit; $i++) {
$output .= '<div class="field field-item'. ' '.$divclass .'"> ' ;
$output .= $field[$i]['view'];
$output .= '<span>' .$field[$i]['data']['description'] .'</span>';

$output .='</div>';
}
return ($output);
}

source

Remove Drupal CCK Field Labels

$content = preg_replace('/<div class="field-label">(.*)</div>/','', $content);

source

drupal cck print multiple values

<?php
$puntuacion = "";
$i = 0;
foreach ((array)$field_proyectos_otrosmiembros as $item) {
$i = $i+1;
if ($i < count($field_proyectos_otrosmiembros)) { $puntuacion = ", "; } else { $puntuacion = ". "; }
print $item['view'].''.$puntuacion.' ';
};
?>

source

View for blog content type

$view = new stdClass();
$view->name = 'blog';
$view->description = 'Blog';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Blog';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = 'No blog posts at this time. Please check back later.';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'blog';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->block = TRUE;
$view->block_title = 'Latest Blog Posts';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '6';
$view->block_more = TRUE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = TRUE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'rss_feed',
'argdefault' => '2',
'title' => '',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'blog',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;

source

View for Image Gallery

$view = new stdClass();
$view->name = 'image_gallery';
$view->description = 'Image gallery photos uploaded by users.';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Image Gallery';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'bonus_grid';
$view->url = 'gallery';
$view->use_pager = TRUE;
$view->nodes_per_page = '24';
$view->sort = array (
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
array (
'tablename' => 'node_data_field_image',
'field' => 'field_image_fid',
'label' => '',
'handler' => 'content_views_field_handler_ungroup',
'options' => 'thickbox][square-thumbnail',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'gallery_image',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node, node_data_field_image);
$views[$view->name] = $view;

source

Insert CCK node from PHP script

$node = new StdClass();
$node->title = "test3";
$node->type = 'clasificados';
$node->body = "booooooooody";
$node->status = 1;
$node->format = 1;
$node->moderate = 0;
$node->promote = 0;
$node->sticky = 0;
$node->revision = 0;
$node->field_contenido = array(0 => array('value' => 'no mas de 140 caracteres en este texto'));
$node->field_autor = array(0 => array ('value' => 'alguntwitter'));
$node = node_submit($node);
node_save($node);

source

Drupal Taxonomy Terms From CCK Taxonomy

<?php
$i = 0;
$limit = count($field_field_of_interest);
while ($i <= ($limit-1)) {
$tags[] = l($field_field_of_interest[$i]['view'], 	'taxonomy/term/'. $field_field_of_interest[$i]['tid']);
$i++;
}
if ($field_field_of_interest){
print t("Fields of Interest") . ": " . implode(' | ', $tags);
}
?>

<br />

<?php
$i = 0;
$limit = count($field_professional_area);
while ($i <= ($limit-1)) {
$tagsTwo[] = l($field_professional_area[$i]['view'], 	'taxonomy/term/'. $field_professional_area[$i]['tid']);
$i++;
}
if ($field_professional_area){
print t("Professional Area") . ": " . implode(' | ', $tagsTwo);
}
?>

source

Import CCK definition from text file

/**
* Helper function to import a CCK content type definition from a text file.
*
* @param $cck_definition_file
*   The full path to the file containing the CCK definition.
*/
function _create_content_type($cck_definition_file) {
include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
$values = array();
$values['type_name'] = '<create>';
$values['macro'] = file_get_contents($cck_definition_file);
drupal_execute("content_copy_import_form", $values);
}

source

Helper function to create a content field (CCK field)

/**
* Helper function to create a content field (CCK field).
*
* @param $type_name
*   The content type for which the content field should be created.
* @param $properties
*   An array with field type properties, that override the default ones.
*/
function _create_content_field($type_name, $properties) {
$default = array(
'label' => 'A field label', // Override in $properties
'widget_type' => '',  // Override in $properties
'op' => 'Create field',
'submit' => 'Create field',
'locked' => FALSE,
'field_name' => '', // Override in $properties, lowercase underscore
);

$new_field = array_merge($default, $properties);
$new_field['type_name'] = $type_name;

_content_admin_field_add_new_submit('_content_admin_field_add_new', $new_field);
}

source