0

I have seen this question, but it seems that the behaviour in my case is even worse.

I have a text field with custom autocomplete which connects to an external service to get terms, and then it creates them if they do not exist in Drupal. Since I am in a early development phase, I am constantly creating and deleting terms. I re-enabled the standard autocomplete widget for a test, and I found that it shows all the terms I had created and deleted! I checked in taxonomy_term_field_data, and of course they are present there.

The terms were created with the following code:

use Drupal\taxonomy\Entity\Term;

[...]

Term::create(array(
  'vid' => 'my_taxonomy',
  'field_codetype' => $codeType,
  'field_mycode' => $myCode,
  'field_codedate' => $codeDate,
  'field_denominazione' => $denominazione,
  'name' => $denominazione,
))->save() ;

and were deleted from the admin interface. Maybe I am missing some mandatory field?

  • How did you delete them through the UI? Presumably by submitting the form at /taxonomy/term/[tid]/delete? – Clive Jul 17 '18 at 8:21
  • Yes. If I am not mistaken, it's the only way to delete a term from the admin interface, isn't it? – Francesco Marchetti-Stasi Jul 17 '18 at 8:48
  • It's the most common but there could be others, worth checking at least. When you delete a term and visit the vocab page again, is the term still listed? If not then it has been deleted, and your issue is likely to be caching – Clive Jul 17 '18 at 8:52
  • The terms are not present in the vocabulary. Which cache are you talking about? I regularly issue druch cr, if I understand correctly that should clear all caches, correct? Just to be on the safe side, I also cleaned the browser's cache, and I event uninstalled and reinstalled my module, but the terms are still there... – Francesco Marchetti-Stasi Jul 17 '18 at 9:02
  • It's not really a serious problem, in production each term should be created at the first use and only be referenced afterwards, I also plan to set up a unique constraint using the Validation API; but since I am both developing a project and learning Drupal at the same time, I would like to understand what's going on. – Francesco Marchetti-Stasi Jul 17 '18 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.