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

johnennew’s picture

Assigned: Unassigned » johnennew

Assigning to me - I'll have a go at creating an initial patch for this to aid with the discussion

drunken monkey’s picture

It 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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

morsok’s picture