Problem/Motivation
Over in https://groups.drupal.org/node/455978#project18 I've proposed a D8 re-architect of this module for GSOC, I'm volunteering to mentor. Want to make sure we have the maintainers' blessing and support.
Thanks
Proposed architecture/resolution
So basically things in Drupal 8 make node hierarchy a lot simpler.
There is a hook_entity_base_field_info() which we can use to add a new 'pid' property/column to the node table - right there on the {node} table - see path_entity_base_field_info() for an example - it defines a path column.
In this hook we can specify this pid field is an Entity Reference field and we can add a validation plugin to make sure correct node-types are referenced (as defined in our admin form).
We can also say 'use an autocomplete widget' in that hook and it will show up in manage display, manage formatters/widgets etc.
We'll need to provide some third-party settings for the node-type config entity to say 'this node type has the following allowed parents'.
There is no need for any of the hook_node_{update|insert|delete|load} because we're registering pid as a base-field and core does everything for us - its that much better in D8 - also no need for the form_alter to add the widgets.
Then menu links.
In Drupal 7 menu links are in their own table and node hierarchy has tonnes of code to keep the menu links in sync with the node parents etc.
In Drupal 8 menu links are plugins and there is the notion of plugin derivatives in D8.
Views uses this so that any view that declares 'add a menu link' auto provides a menu link in code (no table storage).
We can do the same - declare a derivative plugin that queries the node table and finds anything with a pid value, returns a menu link derivative for that.
So the menu links aren't duplicated into a second table, they're just calculated based on node values
it should mean the module is about 75% less code (at least)
That leaves the only tricky bit - views integration. but views is smart enough to find entity reference fields and add the relationship, so that might be simple too.
Comments
Comment #1
larowlanComment #2
webdrips commentedNot sure if you saw my sandbox, but I'm still a ways off here: https://www.drupal.org/sandbox/webdrips/2407557
I'll have a look at your suggestions, and may reach out soon.
Comment #3
webdrips commentedThere's a D8 official port ready for review here: https://www.drupal.org/project/entity_hierarchy