You are here

menu_node_views.views.inc in Menu Node Views 7.2

Same filename and directory in other branches
  1. 6 menu_node_views.views.inc
  2. 7 menu_node_views.views.inc

Menu Node Views definitions.

TODO:

  • configure and test menu_node_views_relationship_double handler

    • basic test with hard-coded value - DONE
    • change to soft value (change the handler and its parameter) - DONE
    • clean dead code
    • check meaning full comment/label/description
    • remove debug info
  • implemtent the double relationship in the other direction
  • replace custom field/sort* handler by normal handler
  • write custom handlers (like depth suggester below or in #1928244)
  • apply coder to the module.

File

menu_node_views.views.inc
View source
<?php

/**
 * @file Menu Node Views definitions.
 * 
 * TODO: 
 *  - configure and test menu_node_views_relationship_double handler
 *    - basic test with hard-coded value - DONE
 *    - change to soft value (change the handler and its parameter) - DONE
 *    - clean dead code
 *    - check meaning full comment/label/description
 *    - remove debug info
 *  - implemtent the double relationship in the other direction
 *  - replace custom field/sort/*** handler by normal handler
 *  - write custom handlers (like depth suggester below or in #1928244)
 *  - apply coder to the module.
 */

/**
 * Implement hook_views_data().
 */
function menu_node_views_views_data() {
  $data = array();

  // rewritting 7.x-2.x in progress
  // We don't want 'implicit' relationship to the node table, actually
  // the menu_node table has to be hidden
  // so comment the code below.
  // NO NO NO !!! this code is actually needed for generate smoothly the double relationship...
  $data['menu_node']['table']['group'] = t('Menu Link');

  // same group as menu_links table
  $data['menu_node']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'nid',
    ),
  );

  // rewritting 7.x-2.x in progress
  // We don't want 'implicit' relationship to the menu_node table,
  // because menu_node table will not be exposed anyway
  // so comment the code below.

  /*
  $data['menu_links']['table']['join'] = array(
    'menu_node' => array(
      'left_field' => 'mlid',
      'field' => 'mlid',
    ),
    'node' => array(
      'left_table' => 'menu_node',
      'left_field' => 'mlid',
      'field' => 'mlid',
    ),
  );
  */
  $data['menu_links']['table']['base'] = array(
    'field' => 'mlid',
    'title' => t('Menu tree'),
    'help' => t('Menu item views.'),
  );
  $data['menu_links']['table']['group'] = t('Menu link');
  $data['menu_links']['nid'] = array(
    'title' => t('Node id'),
    'help' => t('The node id, menu-sensitive.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'menu_node_views_argument_nid',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['menu_name'] = array(
    'title' => t('Menu name'),
    'help' => t('The name of the menu.'),
    'field' => array(
      'click sortable' => TRUE,
      'handler' => 'menu_node_views_field_menu_name',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // TODO: Make this auto-link?
  $data['menu_links']['link_title'] = array(
    'title' => t('Link title'),
    'help' => t('The link text used for the menu item.'),
    'field' => array(
      'click sortable' => TRUE,
      'handler' => 'menu_node_views_field_link_title',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['description'] = array(
    'title' => t('Description'),
    'help' => t('The description used for the menu item.'),
    'field' => array(
      'handler' => 'menu_node_views_field_description',
    ),
  );
  $data['menu_links']['link_path'] = array(
    'title' => t('Link path'),
    'help' => t('The link path for the menu item.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['mlid'] = array(
    'title' => t('Menu link id'),
    'help' => t('The unique menu link identifier.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['plid'] = array(
    'title' => t('Parent menu link id'),
    'help' => t('The unique menu link identifier for this item\'s parent.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'relationship' => array(
      'base' => 'menu_links',
      'field' => 'plid',
      'handler' => 'views_handler_relationship',
      'label' => t('Menu link - parent item'),
    ),
  );
  $data['menu_links']['weight'] = array(
    'title' => t('Weight'),
    'help' => t('The weight of the menu item.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['hidden'] = array(
    'title' => t('Hidden'),
    'help' => t('The menu item visibility.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['menu_links']['depth'] = array(
    'title' => t('Depth'),
    'help' => t('The depth of the menu item.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );

  // TODO: Write a depth handler.
  $data['menu_links']['p1'] = array(
    'title' => t('Parent'),
    'help' => t('The top-level parent of the menu item.'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'menu_node_views_sort_menu',
    ),
  );
  return $data;
}
function menu_node_views_views_data_alter(&$data) {

  // TODO: declare relationships:
  //   - from node to menu_links table
  //   - from menu_links to node table
  // using menu_node_views_relationship_double handler (via menu_node)
  $data['node']['menu_item'] = array(
    'title' => t('Link to Menu Link table'),
    'help' => t('Relate the menu links records to the node (if any).'),
    'relationship' => array(
      'handler' => 'menu_node_views_relationship_double',
      'label' => t('Menu links'),
      'title' => t('Menu link on the node'),
      'help' => t('Relate nodes to menu links.'),
      //'field_1' => 'nid', // not necessary
      'middle_table' => 'menu_node',
      //'middle_field_1' => 'nid', // not necessary
      'middle_field_2' => 'mlid',
      'right_table' => 'menu_links',
      'right_field_2' => 'mlid',
    ),
  );
}