Follow up to #2016701: Expand TermInterface to provide methods
Problem/Motivation
There needs to be methods to get and set the parents of a taxonomy Term.
Right now, the $parent property on taxonomy Term is doing too much. It can either be,
1. an array of the parent tids and we want to update next time Term is saved.
2. an array containing a single 0 value, meaning no parent tids but we still want to update on save. The 0 term tid needs to be passed to the storage controller during update as updateTermHierarchy uses it to insert a row into taxonomy_term_hierarchy to indicate there is no parents. Would be really good if this was not needed.
3. unset, meaning it may or may not have parent tids but we don't want to update them when the term is saved.
This is a problem because we want to add getter and setter methods to the Term to get and set the parents. Just adding this as things are now would mean the getParents() method would be odd since it would not always return a list of the term's parents (sometimes NULL for example meaning that the parents had not changed).
Proposed resolution
1. The getParents() method should be written for external audiences and so always return an array of the parent terms - these should be loaded dynamically rather than every time the Term is loaded for performance.
2. Tracking if the parents have changed so that the taxonomy hierarchy isn't updated every time a Term is saved should be an internal function of the Term Entity class and it's implementation hidden from the interface.
Comments
Comment #1
johnennew commentedAssigning to me - I'll have a go at creating an initial patch for this to aid with the discussion
Comment #2
drunken monkeyIt seems to me this can/should be closed, as #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration is doing the same thing and already has a patch and some consensus.
Comment #4
morsokDuplicate of #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration see comment #2 above.