book.views.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data for book.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function book_views_data() {
  12. $data = [];
  13. $data['book'] = [];
  14. $data['book']['table'] = [];
  15. $data['book']['table']['group'] = t('Book');
  16. $data['book']['table']['join'] = [
  17. 'node_field_data' => [
  18. 'left_field' => 'nid',
  19. 'field' => 'nid',
  20. ],
  21. ];
  22. $data['book']['nid'] = [
  23. 'title' => t('Page'),
  24. 'help' => t('The book page node.'),
  25. 'relationship' => [
  26. 'base' => 'node_field_data',
  27. 'id' => 'standard',
  28. 'label' => t('Book Page'),
  29. ],
  30. ];
  31. $data['book']['bid'] = [
  32. 'title' => t('Top level book'),
  33. 'help' => t('The book the node is in.'),
  34. 'relationship' => [
  35. 'base' => 'node_field_data',
  36. 'id' => 'standard',
  37. 'label' => t('Book'),
  38. ],
  39. ];
  40. $data['book']['pid'] = [
  41. 'title' => t('Parent'),
  42. 'help' => t('The parent book node.'),
  43. 'relationship' => [
  44. 'base' => 'node_field_data',
  45. 'id' => 'standard',
  46. 'label' => t('Book Parent'),
  47. ],
  48. ];
  49. $data['book']['has_children'] = [
  50. 'title' => t('Page has Children'),
  51. 'help' => t('Flag indicating whether this book page has children'),
  52. 'field' => [
  53. 'id' => 'boolean',
  54. ],
  55. 'sort' => [
  56. 'id' => 'standard',
  57. ],
  58. 'filter' => [
  59. 'id' => 'boolean',
  60. 'label' => t('Has Children'),
  61. ],
  62. 'argument' => [
  63. 'id' => 'numeric',
  64. ],
  65. ];
  66. $data['book']['weight'] = [
  67. 'title' => t('Weight'),
  68. 'help' => t('The weight of the book page.'),
  69. 'field' => [
  70. 'id' => 'numeric',
  71. ],
  72. 'sort' => [
  73. 'id' => 'standard',
  74. ],
  75. ];
  76. $data['book']['depth'] = [
  77. 'title' => t('Depth'),
  78. 'help' => t('The depth of the book page in the hierarchy; top level books have a depth of 1.'),
  79. 'field' => [
  80. 'id' => 'numeric',
  81. ],
  82. 'sort' => [
  83. 'id' => 'standard',
  84. ],
  85. 'filter' => [
  86. 'id' => 'numeric',
  87. ],
  88. 'argument' => [
  89. 'id' => 'standard',
  90. ],
  91. ];
  92. $parents = [
  93. 1 => t('1st parent'),
  94. 2 => t('2nd parent'),
  95. 3 => t('3rd parent'),
  96. 4 => t('4th parent'),
  97. 5 => t('5th parent'),
  98. 6 => t('6th parent'),
  99. 7 => t('7th parent'),
  100. 8 => t('8th parent'),
  101. 9 => t('9th parent'),
  102. ];
  103. foreach ($parents as $i => $parent_label) {
  104. $data['book']["p$i"] = [
  105. 'title' => $parent_label,
  106. 'help' => t('The @parent of book node.', ['@parent' => $parent_label]),
  107. 'relationship' => [
  108. 'base' => 'node_field_data',
  109. 'id' => 'standard',
  110. 'label' => t('Book @parent', ['@parent' => $parent_label]),
  111. ],
  112. ];
  113. }
  114. return $data;
  115. }