Don't try to validate terms with an empty name/label value

Created on 25 March 2020, over 4 years ago
Updated 3 May 2024, 7 months ago

Problem/Motivation

The module has compatibility issues with the experimental core module "workspaces". Once both modules are activated the following error gets thrown:

Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1269 of core/lib/Drupal/Core/Database/Connection.php).

One of the reasons is, that with "workspaces" activated, our taxonomy_term query will be of type "Drupal\workspaces\EntityQuery\Query" before executing. Without workspaces, it will be of type "Drupal\Core\Entity\Query\Sql\Query".

The error gets thrown inside "TaxonomyUniqueManager" in line 50, when the unique query gets executed.

Steps to reproduce

  • Install both "workspaces" and "taxonomy unique"
  • Add a taxonomy vocabulary and enable the "Terms should be unique." option
  • Add a term.
  • The error gets thrown.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wrd

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Could someone please check if that still happens?

    As this should work with all core modules, we should set up a dedicated automated test with both modules enabled, if this is still the case. If not, we should close this outdated.

  • Assigned to Grevil
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Grevil could you please check this and perhaps write a quick test to ensure it works as expected for the future?
    Then we can close this :)

  • Status changed to Needs work over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    The exact error is not reproducable in 2.x, BUT as soon as workspaces is activated, trying to add a new term to a unique term vocabulary, will lead to the following error:

    Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Grevil thanks! We should add this as a separate error. This one should be closed "cannot reproduce" or back to maintainer needs more info for the exact issue summary and steps to reproduce.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    PS: Please always add the file and line where the error happens, that's the most important detail with errors :D

  • Status changed to Needs review over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Interesting, "workspaces" seems to high jack the entity query object! No wonder it is highly experimental.

    With "workspaces" activated, our taxonomy_term query will be of type "Drupal\workspaces\EntityQuery\Query" before executing. Without workspaces, it will be of type "Drupal\Core\Entity\Query\Sql\Query", so this is on their part.

    @Anybody should decide on how to proceed here, but for me this module seems to be highly intrusive and not worthy to build around.

  • πŸ‡©πŸ‡ͺGermany Grevil

    @Anybody, regarding #9, I was still investigating the problem...

  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Grevil: NP! :)

    Could you please still provide the details for

    Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated

    ?
    (editing your comment above)

    If it only appears with workspaces, this should be fixed here. If it's always appearing, it should please be fixed in a separate issue.

    You and me won't do anything about the Workspaces object, as we're not using it anywhere, so we'd have to pay the development without any benefit.

    Then just leave this "Needs work" please for someone to fix. Happy to review MR with tests.

  • Status changed to Closed: won't fix over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Full Error:

    Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1269 of core/lib/Drupal/Core/Database/Connection.php).
    Drupal\Core\Database\Connection->escapeLike(NULL) (Line: 431)
    Drupal\Core\Database\Query\Select->escapeLike(NULL) (Line: 125)
    Drupal\Core\Entity\Query\Sql\Condition::translateCondition(Array, Object, ) (Line: 70)
    Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 176)
    Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 81)
    Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 52)
    Drupal\taxonomy_unique\TaxonomyUniqueManager->isUnique(Object) (Line: 52)
    Drupal\taxonomy_unique\Plugin\Validation\Constraint\TaxonomyUniqueValidator->validate(Object, Object) (Line: 202)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object, '00000000000004970000000000000000', Array) (Line: 154)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object) (Line: 164)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object, Array, 1) (Line: 106)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object, NULL, NULL) (Line: 93)
    Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object) (Line: 132)
    Drupal\Core\TypedData\TypedData->validate() (Line: 489)
    Drupal\Core\Entity\ContentEntityBase->validate() (Line: 277)
    Drupal\workspaces\EntityOperations->entityFormAlter(Array, Object, 'taxonomy_term_my_tax_boiiii_form') (Line: 63)
    workspaces_form_alter(Array, Object, 'taxonomy_term_my_tax_boiiii_form') (Line: 545)
    Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'taxonomy_term_my_tax_boiiii_form') (Line: 838)
    Drupal\Core\Form\FormBuilder->prepareForm('taxonomy_term_my_tax_boiiii_form', Array, Object) (Line: 282)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 26)
    Drupal\taxonomy\Controller\TaxonomyController->addForm(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 686)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    

    This is not fixable as it is a problem inside workspaces.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @wrd & @iarc13 perhaps you may create an issue at Workspaces and link this one?

  • πŸ‡©πŸ‡ͺGermany Grevil

    The error gets thrown inside "TaxonomyUniqueManager" in line 50, when the query gets executed.

    The issue queue for workspaces is pretty hard to find, here is the link: https://www.drupal.org/project/issues/drupal?component=workspaces.module β†’ .

  • Status changed to Needs work over 1 year ago
  • Status changed to Needs review over 1 year ago
  • πŸ‡·πŸ‡΄Romania amateescu

    @Grevil, there's nothing wrong with overriding the entity query classes, and Workspaces is certainly not "highly experimental" because of it.

    This problem is caused by \Drupal\workspaces\EntityOperations::entityFormAlter() which runs entity validation when the submitted form is being rebuilt, before the form values are extracted and set on the entity (term) object. That is arguably not the intended use case for entity validation, and we could explore a different approach in the core issue mentioned above.

    However, until then, there is a quick fix that can be done in this module: return early in \Drupal\taxonomy_unique\TaxonomyUniqueManager::isUnique() when the term object doesn't have a value set for the name field. IMO this makes sense even without the Workspace issue, because there could be other modules which run entity validation outside of the regular form submit flow.

  • Status changed to Closed: outdated 7 months ago
  • πŸ‡·πŸ‡΄Romania amateescu

    It seems this small change won't make it into this module, the core issue in Workspaces is getting fixed though, so closing this one.

Production build 0.71.5 2024