1

i have a custom table created using .install file and in views.inc i am writing code to expose fields to views but i dont want to join that table with node. my code is as follow

function core_sms_views_data() {

  $data['core_sms_details']['table']['group'] = t('Core SMS Details Table');
  $data['core_sms_details']['table']['base'] = array(
    'field' => 'date', // This is the identifier field for the view.
    'title' => t('Core SMS Details Table'),
    'help' => t('Example table contains example content and can be related to nodes.'),
    'weight' => -10,
  );

  $data['core_sms_details']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'date',
    ),
  );

  $data['core_sms_details']['date'] = array(
    'title' => t('Example content'),
    'help' => t('Some example content that references a node.'),

    'relationship' => array(
      'base' => 'core_sms_details', // The name of the table to join with.
      'base field' => 'date', // The name of the field on the joined table.
      // 'field' => 'nid' -- see hook_views_data_alter(); not needed here.
      'handler' => 'views_handler_relationship',
      'label' => t('Default label for the relationship'),
      'title' => t('Title shown when adding the relationship'),
      'help' => t('More information on this relationship'),
    ),
  );


  // SMS failed field.
  $data['core_sms_details']['sms_failed'] = array(
    'title' => t('SMS failed field'),
    'help' => t('sms failed daily wise.'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  return $data;
}

if i removed $data['core_sms_details']['table']['join'] = array( 'node' => array( 'left_field' => 'nid', 'field' => 'date', ), ); then the field is not appearing in view what i am doing wrong here?

  • What type of view is it? If it lists nodes, then you'll obviously need a join to the node table to have a field show up in it... – Clive Feb 21 '15 at 8:02
  • Thank you Clive.i deleted joins. my problem got resolved. actually i was looking at wrong place. while creating new view i selected content type instead of "Core SMS Details Table". Thats why i was not able to add fields inside view. – SHRIDHAR Feb 21 '15 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.