Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This patch remove taxonomy_term_hierarchy:
Comment | File | Size | Author |
---|---|---|---|
#9 | 2932067-9.patch | 4.06 KB | Wim Leers |
#5 | Screen Shot 2018-01-16 at 13.42.48.png | 134.88 KB | Wim Leers |
Comments
Comment #2
larowlanSee https://www.drupal.org/node/2936675
This module will break because it is interacting directly with entity tables via SQL instead of using the methods on TermStorage handler.
Comment #3
larowlanThe core issue has been committed to 8.6.x and is being considered for backport to 8.5.x
Comment #4
Wim LeersI wanted to help file a patch for this, but the first bit of code I wanted to update was this:
… but
taxonomy_term_save()
doesn't actually exist in D8…Comment #5
Wim LeersAFAICT 100% of the code in
taxonomy_manager.admin.inc
is just there to be ported, it's not executed. The commit log also supports this:Zero commits touching this file since the release of Drupal 8. The last commit was on Sep 2, 2014, more than a year before Drupal 8 was released.
Yet
taxonomy_manager.admin.inc
has 8 of the 12 occurrences of the stringtaxonomy_term_hierarchy
:This means rather than 12 places to update, there are only 4. Working on it!
Comment #6
Wim LeersThis fixes 2 occurrences of
taxonomy_term_hierarchy
to use the actual Taxonomy API, with minimal changes. These occurrences are definitely being used in the actual code.Comment #7
Wim LeersThe next use, in
\Drupal\taxonomy_manager\Element\TaxonomyManagerTree::isRoot()
, is only called by\Drupal\taxonomy_manager\Element\TaxonomyManagerTree::getFirstPath()
, which in turn is only called by\Drupal\taxonomy_manager\Element\TaxonomyManagerTree::processTree()
, which in turn is only called if$element['#terms_to_expand']
is set, which is never set by the module itself, only by potential custom code.If I do set
#terms_to_expand
to something, then\Drupal\taxonomy_manager\Element\TaxonomyManagerTree::isRoot()
is called and … results in a fatal PHP error because the code is wrong:This results in the following PHP fatal error:
Comment #8
Wim LeersDespite #7's explanation about how this is completely broken in HEAD, the intent of the code is clear, and I can update it to use the proper API and fix the fatal error in doing so!
Comment #9
Wim LeersThe fourth and final occurrence of
taxonomy_term_hierarchy
cannot be updated to useTermStorageInterface
, because it also uses a pager.TermStorage
doesn't support paging.But … that's what entity queries are for! Entity queries do support paging. But … entity queries don't yet support the
parent
field, because it uses custom storage, as described in #2599450: Drupal\Core\Entity\Query\QueryException: 'parent' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable. But that's exactly what #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration is fixing!So, let's be a bit creative. Let's use an entity query, but catch the exception that will be thrown on sites that don't yet have #2599450: Drupal\Core\Entity\Query\QueryException: 'parent' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable. If that exception is caught, we just execute HEAD's code (which uses the
taxonomy_term_hierarchy
table). In the future, we'll just be able to remove that code!Comment #10
Wim LeersNote that the patch in #9 makes the module work with both Drupal 8 HEAD (without #2543726) and with #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration applied!
Comment #11
JacobSanford@Wim-Leers
This is superb work, thanks so much. I applied for maintainer status late last year in attempt get the 3-4 patches in our build system committed and to start getting the module in a reasonable shape for 8. I don't have a lot of time, but the primary maintainer isn't running 8.x yet and isn't focused on it. So I'll fill in where I can.
As you say, it does appear MUCH of the code is 'awaiting a D8 port', many functions avoid using OOP, and some files in the tree are no longer even used in D8 (#2792761: taxonomy_vocabulary_load and taxonomy_vocabulary_load have been deprecated).
It's really great to get this cleanup started in such a thorough way..
Comment #13
JacobSanfordComment #14
Wim Leers@JacobSanford: wow, I did not expect this to get committed so fast! And thank you for the kind words :)
Porting a module can be hard, especially one that has seemingly been minimally maintained for a while: rather than lots of straightforward changes, it means much more complex changes are necessary, and that can definitely be challenging! I'm glad that I was able to lend you a hand in this very small way — hopefully it makes you feel a bit more optimistic about the rest :)