Hi there,

Thanks for the useful module.

I've added a patch to save the taxonomy term lineage (a much requested feature).

This is useful for example when the content needs to store all the data points, to serve the data via API.

The current approach does as follows:

  1. Adds a checkbox to the form display widget settings to "Save lineage"
  2. If "Save lineage" is checked, the widget function massageFormValues will transform the data to the lineage set on save
  3. If "Save lineage" is checked, the patch will alter the default settings on display to just set the taxonomy term "leaves" for the SHS widget render

It adds and uses a new class in Drupal\shs\Utility\TermLineage; based on the key code from the hierarchical select module.

Will attach the patch shortly.

Comments

davidwhthomas created an issue. See original summary.

davidwhthomas’s picture

Status: Active » Needs review
StatusFileSize
new13.48 KB
davidwhthomas’s picture

Issue summary: View changes
davidwhthomas’s picture

Issue summary: View changes
stborchert’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#1893188: Save lineage

Sorry to say, but closed as per #1893188-10: Save lineage.
SHS will never save the lineage as its not designed to do so (and never was), there is simply no use case having the complete lineage stored and you'll open up the box of Pandora by doing so.

davidwhthomas’s picture

Sorry to hear that.

As the patch is working for our needs, we will use a local fork of the SHS module.

The patch can remain here for others wanting the save lineage functionality for Drupal 8.

diogo_plta’s picture

"SHS will never save the lineage as its not designed to do"
I hadn´t imagined this module whitout this function. For me it is designed for this. Why save only the last item?
Can you explain? I think that a lot of people want this function.

proweb.ua’s picture

Thanks @davidwhthomas, the patch #2 works.

I used it as a replacement for 'Content: Has taxonomy term ID (with depth)' filter.
If you are using /taxonomy/term/% + search api, filter 'Content: Has taxonomy term ID (with depth)' is missing.

It may be better to design a patch in the form of a separate module. If they do not want to accept it.

skin’s picture

mtoscano’s picture

The ideal solution will be to update https://www.drupal.org/project/taxonomy_set_lineage to Drupal 8

bakinbox’s picture

Hi, i´m trying to apply the path #2 but seems is ok, but can´t fine some files. I can see in the form "Save lineage", but the contents get a white death screen.

EDIT, i could apply the patch (git apply -v shs-save-term-lineage-2943357-2_2.patch) but now i it has other problems.

The field need to have no limits no 1.
And in the field only gets the first (the parent or root term, not the others)

Thanks.

bakinbox’s picture

Anybody knows how to solve it? thanks

rhristov’s picture

StatusFileSize
new14.6 KB
new1.18 KB

I have created a new patch based on the one from comment #2 and I have fixed the following issue: When editing already created content and saving it without any new modifications an error appears: "You need to select a term from the deepest level in the field FIELD_NAME".

rhristov’s picture

StatusFileSize
new15.7 KB
new1.64 KB

Applying a new patch that is exposing an option to hide the Add another button link.

rhristov’s picture

StatusFileSize
new15.79 KB
new887 bytes

Created a new patch from #14 that is fixing the notices.

jbfelix’s picture

when do you plan to commit this patch ?
Thanks

alaa abbad’s picture

StatusFileSize
new15.58 KB
ooz47’s picture

Patch from comment #15 applies cleanly!
Thank you!

summit’s picture

Hi, t would be great if this could be ported to D7! Greetings, Martijn

summit’s picture

Now experimenting on D8. Why wouldn't this patch not be committed. It is a big missing feature in D8, save term lineage?
Thanks for considering this, greetings, Martijn

summit’s picture

Status: Closed (duplicate) » Reviewed & tested by the community

Hi, Yes this term lineage works great. A very good add-on to this module.
Please, please, module-maintainer...this is the only HS module on which with patches:
1- We can add new terms to lineages: https://www.drupal.org/project/shs/issues/2712115
2- With this patch, also save the term lineage.

With this finally the Hierarchical Select module, which stopped in D7, has a replacement in D8.
Please do not stop this great functionality, and please bring it within this great SHS module, because there is a need for this.

And shouldn't modules supposed to exactly do that? Fill a need?
Thanks for considering, and therefore I set this patch to Reviewed & Tested ok?
Greetings,

summit’s picture

Double input, sorry.

vm’s picture

@Summit - The project page indicates that the maintainers are no longer developing this module. Someone will need to take apply to take it over for patches to be committed and new releases to be provided.

summit’s picture

Hi VM, Thanks for bringing this to my attention. I am not enough programmer for this. Hopefully someone will fill the gab!
greetings, Martijn

msti’s picture

Status: Reviewed & tested by the community » Fixed

I am marking this as fixed. The patch has been added to the module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

summit’s picture

Thanks Mike Stivaktakis. Great addon!

seutje’s picture

It doesn't appear this patch was actually added.

Also, it produces an issue when using terms with multiple parents.

Situation as follows:
child 1 has both term 1 and term 2 as parent.
- term 1
-- child 1
- term 2
-- child 1
When I select term 2 and child 1 and save the node, the field contains the values for term 1, term 2 and child 1.

summit’s picture

Hi, You should change the Status from Closed/Fixed to what you need to get attention again for this issue I think.
greetings,

jmaties’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Issue tags: +Drupal9
StatusFileSize
new15.42 KB

Compatibility with drupal 9

summit’s picture

Hi Javier,

Will your Version 2.0.x-dev also work with Drupal 8 and is issue #28 (https://www.drupal.org/project/shs/issues/2943357#comment-13971871) solved with it ? Or is it easy to make it compatible with drupal 8?
Thanks for your reply in advance, and sorry if this is a stupid question. I am not working with Drupal 9 yet.

greetings, Martijn

summit’s picture

Hi,
I am testing Drupal 9.2.8 now, and got this with latest SHS 2.x.dev.

Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2021-05-12/save_term_lineage-2943357-15_2.patch
                                                                                                               
  [Exception]                                                                                                    
  Cannot apply patch Save term lineage (https://www.drupal.org/project/shs/issues/2943357) (https://www.drupal.  
  org/files/issues/2021-05-12/save_term_lineage-2943357-15_2.patch)!

Could you please alter the patch as such it is working with latest 2.dev.
I do not know how to see where in the patch it goes wrong, sorry.

Made a new issue to move forward on Drupal 9, see https://www.drupal.org/project/shs/issues/3248983

Thanks a lot in advance for your reply.
Greetings, Martijn

voleger’s picture

StatusFileSize
new17.11 KB

Rerolled #30
Indeed this is a missing feature in the 2.0.x branch. The issue needs to be reopened or moved to follow-up issue.

voleger’s picture

StatusFileSize
new17.11 KB

Fixed typo
public function getParents(int $tid): number => public function getParents(int $tid): array

voleger’s picture

StatusFileSize
new17.12 KB
new534 bytes

Small fix on the default value

summit’s picture

Hi,
Is this patch still needed?
When I combine SHS with https://www.drupal.org/project/taxonomy_set_lineage it will save the lineage.
See also this post: https://www.drupal.org/project/taxonomy_set_lineage/issues/2872601#comme...

But the disadvantage is that I have to alter every node now to have the lineage set. May be there is a bulk solution for this?

greetings, Martijn

summit’s picture

Hi, I let made a Drupal 10 Save term lineage patch, see https://www.drupal.org/project/shs/issues/3409930
greetings,

maria.valcheva’s picture

StatusFileSize
new17.2 KB

Patch altered to work with the latest release (2.0.0-rc12).

nnevill’s picture

Patch from #38 works well with 2.0.0-rc12

nnevill’s picture

StatusFileSize
new17.11 KB
new1.72 KB

After more testing found that patch from #38 throws errors in case of multiple SHS fields and in case field is empty so here is updated patch with interdiff.