Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom compound CCK field - How to display individual sub-fields in Views?
    primarykey
    data
    text
    <p>In Drupal 6, I have created a simple Pricing CCK compound field module with a "cost" and a "product" sub-field based on this excellent tutorial: <a href="http://www.poplarware.com/articles/cck_field_module" rel="nofollow noreferrer">http://www.poplarware.com/articles/cck_field_module</a></p> <pre><code>function usginpricing_field_settings($op, $field) { switch ($op) { case 'database columns': $columns['cost'] = array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; FALSE, 'sortable' =&gt; TRUE, 'default' =&gt; '', 'views' =&gt; TRUE); $columns['product'] = array('type' =&gt; 'varchar', 'length' =&gt; 1000, 'not null' =&gt; FALSE, 'sortable' =&gt; TRUE, 'default' =&gt; '', 'views' =&gt; TRUE); return $columns; } } </code></pre> <p>I can retrieve the compound values in Views but how can I pull out the individual sub-fields? So far, I only know where to modify the response (CCK hook_field() implementation - <code>case 'views data':</code>) for Views but am otherwise stumped:</p> <pre><code>function usginpricing_field($op, &amp;$node, $field, &amp;$items, $teaser, $page) { switch ($op) { // Do validation on the field values here. The widget // will do its own validation and you cannot make any // assumptions about what kind of widget has been used, // so don't validate widget values, only field values. case 'validate': if (is_array($items)) { foreach ($items as $delta =&gt; $item) { if ($item['cost'] != '' &amp;&amp; !is_numeric(trim($item['cost']))) { form_set_error($field['field_name'],t('"%name" is not a valid numeric value',array('%name' =&gt; $item['cost']))); } } } break; case 'sanitize': foreach ($items as $delta =&gt; $item) { foreach ($item as $col =&gt; $dat) { $items[$delta]['safe_' . $col ] = check_plain($item[ $col ]); } } break; // Optional: Make changes to the default $data array // created for Views. Omit this if no changes are // needed, use it to add a custom handler or make // other changes. case 'views data': // UNFINISHED // Start with the $data created by CCK // and alter it as needed. The following // code illustrates how you would retrieve // the necessary data. $data = content_views_field_views_data($field); $db_info = content_database_info($field); $table_alias = content_views_tablename($field); $field_data = $data[$table_alias][$field['field_name'] .'_value']; // Make changes to $data as needed here. return $data; } } </code></pre> <p>I'd appreciate any advice or sample code! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload