Currently the module only supports term reference fields on nodes.

It should also handle references on other entities, e.g. term reference fields on:

  1. taxonomy terms
  2. media entity
  3. commerce product
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

malcomio created an issue. See original summary.

malcomio’s picture

Issue summary: View changes
jayhuskins’s picture

Here is my patch laid out for this issue. It worked for my circumstances: I only needed user and node entities, all of which used the same field to reference the target term. But there are some flaws in it. At the time of this post, the module Taxonomy Entity Index is still in alpha for D8, but it could better solve this problem in the future.

- Patch features:

  • Added function getEntitiesByTid() which takes a term id and returns all User and Node entities that references that term as well as the field in which they reference it.
  • Added value fields to pass entities and field name in the form so that they don't have to be calculated again in submitForm()
  • Implemented batch to run replace_term (which is in the .module file and replaces an entity's old term reference with the new one) on every entity instead of doing all that in submitForm(). This was necessary in my case to avoid php timeout errors
  • Added a checkbox to see if the user really wants to delete the term after replacing it.

- Patch flaws:

  • Assumes that all users and nodes use the same field to reference a given term.
  • Extends entities to users, but nothing else. Future solution would be implementing Taxonomy Entity Index (https://www.drupal.org/project/taxonomy_entity_index) and modifying get_nids_by_tid to use taxonomy_entity_index instead of taxonomy_index.
jayhuskins’s picture

StatusFileSize
new7.45 KB

*Updated patch for coding standards*

7thkey’s picture

Does not work with Commerce Products

7thkey’s picture

Status: Active » Needs work
rgeerolf’s picture

Also does not work with media entities.

malcomio’s picture

Issue summary: View changes
tlwatson’s picture

+1. This should be abstracted to work with any Fieldable Entity, whether core, contrib, or custom. Taxonomy, Users, Media, Paragraphs, Commerce, BibCite...

rowrowrowrow made their first commit to this issue’s fork.

rowrowrowrow’s picture

rowrowrowrow’s picture

Assigned: Unassigned » rowrowrowrow

rowrowrowrow’s picture

StatusFileSize
new27.6 KB

@jayhuskins Patch related to https://www.drupal.org/project/taxonomy_replace/issues/2935085#comment-1....

This takes the recommendations provided in https://www.drupal.org/project/taxonomy_replace/issues/2935085#comment-1... and expands on them.

Patch features:

  • Uses taxonomy_entity_index to replace all terms. First index the entities you want to replace terms on using taxonomy_entity_index then use taxonomy_replace to replace them. Works for any entity types, fields, revisions that are tracking term relationships supported by that module.

Next Steps:

  • Currently doesn't update the taxonomy_entity_index of replaced terms as they are replaced. I.e. re-indexing using taxonomy_entity_index may be necessary after performing a replace although I've seen the index update as the process is run. Running the same process for replacement is harmless if the taxonomy_entity_index hasn't been re-indexed but the index needs to be up to date for this to replace properly.
  • Allow granular customization of which terms should be replaced. The query logic was setup in getTaxonomyEntityIndicesByTid to allow for this. The options should be implemented in both the drush command and form.
rowrowrowrow’s picture

Priority: Normal » Major
Status: Needs work » Needs review
rowrowrowrow’s picture

StatusFileSize
new28.52 KB

Allow replacement for all revisions as well.