Skip to content
Snippets Groups Projects
Commit 69c134c2 authored by Dan Harris's avatar Dan Harris
Browse files

Keep plugging away at views integration; getting closer to adding a custom sort.

parent da72c7a1
Branches
Tags
No related merge requests found
<?php
/**
* @file
* Views hooks for nodehierarchy_views.
*/
/**
* Implements hook_views_data().
*/
function nodehierarchy_views_data() {
$data = array();
$data['nodehierarchy'] = array();
$data['nodehierarchy']['table'] = array();
// Basic table information.
$data['nodehierarchy']['table']['group'] = t('Hierarchy');
// $data['nodehierarchy']['table']['base'] = array(
// // Identifier (primary) field in this table for Views.
// 'field' => 'nid',
// // Label in the UI.
// 'title' => t('Hierarchy table'),
// // Longer description in the UI. Required.
// 'help' => t('Hierarchy table contains the name of the views to be embedded'),
// 'weight' => -10,
// );
$data['nodehierarchy']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'cnid',
),
);
$data['nodehierarchy']['cweight'] = array(
'title' => t('Child Weight'),
'help' => t('The sort order of the child node.'),
'field' => array(
'id' => 'cweight',
// 'click sortable' => TRUE,
),
'sort' => array(
'id' => 'child_weight',
),
);
$data['nodehierarchy']['pnid'] = array(
'title' => t('Parent Node ID'),
'help' => t('The parent id of the node.'),
// Information for accepting a parent as an argument.
'argument' => array(
'field' => 'pnid',
'handler' => 'views_handler_argument_node_nid',
'click sortable' => TRUE,
),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'field' => 'pnid',
'handler' => 'views_handler_relationship',
'label' => t('Parent Node'),
),
);
// kint($data);
return $data;
}
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
module:
- node
- nodehierarchy_views
- user
id: hierarchy_children
label: 'Hierarchy Children'
module: views
description: 'Display children of a current node as a simple list or teaser list'
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' Previous'
next: 'Next ›'
first: '« First'
last: 'Last »'
quantity: 9
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: 'entity:node'
options:
relationship: none
view_mode: teaser
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters:
status:
value: true
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
group: 1
sorts:
child_weight:
id: child_weight
table: nodehierarchy
field: cweight
order: ASC
plugin_id: child_weight
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }
hierarchy_embed_1:
display_plugin: hierarchy_embed
id: hierarchy_embed_1
display_title: 'Hierarchy Embed'
position: 1
display_options:
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }
hierarchy_embed_2:
display_plugin: hierarchy_embed
id: hierarchy_embed_2
display_title: 'Children Title List'
position: 2
display_options:
display_extenders: { }
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
defaults:
style: false
row: false
row:
type: fields
options:
default_field_elements: true
inline: { }
separator: ''
hide_empty: false
display_description: ''
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
- user.permissions
tags: { }
\ No newline at end of file
# Schema for the hierarchy_embed display plugins.
# Schema for the hierarchy_embed views plugins.
views.display.hierarchy_embed:
type: views_display
label: 'Hierarchy display options'
views.sort.child_weight:
type: views_sort
label: 'Hierarchy sort by child weight'
\ No newline at end of file
<?php
/**
* @file
* Install file for nodehierarchy_views module.
*/
/**
* Implements hook_install().
*/
function nodehierarchy_views_install() {
}
/**
* Implements hook_uninstall().
*/
function nodehierarchy_views_uninstall() {
}
/**
* Implements hook_schema().
*/
function nodehierarchy_views_schema() {
$schema['nodehierarchy_views'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The {node}.nid whose children are being embedded.',
),
'nh_children_view' => array(
'type' => 'varchar',
'length' => '128',
'default' => '',
'not null' => TRUE,
'description' => 'The {views_view}.name of the embedded view.',
),
'nh_children_view_display' => array(
'type' => 'varchar',
'length' => '64',
'default' => 'default',
'not null' => TRUE,
'description' => 'The {views_display}.id of the embedded view.',
),
),
'primary key' => array('nid'),
);
return $schema;
}
\ No newline at end of file
......@@ -2,19 +2,13 @@
/**
* @file
* Contains \Drupal\nodehierarchy\Plugin\views\display\HierarchyEmbed.
* Contains \Drupal\nodehierarchy_views\Plugin\views\display\HierarchyEmbed.
*/
namespace Drupal\nodehierarchy_views\Plugin\views\display;
//use Drupal\views\Plugin\views\display\Block;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\Block\ViewsBlock;
use Drupal\views\Plugin\views\display\DisplayPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* The plugin that handles an HierarchyEmbed display.
......@@ -30,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* uses_menu_links = FALSE
* )
*/
class HierarchyEmbed extends DisplayPluginBase /*implements DisplayPluginInterface*/ {
class HierarchyEmbed extends DisplayPluginBase {
/**
* Whether the display allows attachments.
......@@ -42,9 +36,10 @@ class HierarchyEmbed extends DisplayPluginBase /*implements DisplayPluginInterfa
/**
* {@inheritdoc}
*/
public function getType() {
return 'hierarchy_embed';
}
// Causing the styles to go missing for whatever reason
// public function getType() {
// return 'hierarchy_embed';
// }
/**
* {@inheritdoc}
......
<?php
/**
* @file
* Contains \Drupal\nodehierarchy_views\Plugin\views\sort\ChildWeight.
*/
namespace Drupal\nodehierarchy_views\Plugin\views\sort;
use Drupal\views\Plugin\views\sort\SortPluginBase;
/**
* Sort handler for hierarchy children
*
* @ingroup views_sort_handlers
*
* @ViewsSort("child_weight")
*/
class ChildWeight extends SortPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
kint($options);
return $options;
}
public function query() {
$this->ensureMyTable();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment