Problem/Motivation
When saving a node form where we've asked Unique Field to ensure that one of the fields, which may contain multiple values, does not contain any repeated values, the last item in the $values array is an empty row with the "Add another value" button as the "value" of the field, which is a TranslatableMarkup object. This causes an error.
Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in unique_field_form_validate() (line 310 of modules/contrib/unique_field/unique_field.module).
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 280)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'node_shortcut_edit_form') (Line: 123)
Drupal\Core\Form\FormValidator->validateForm('node_shortcut_edit_form', Array, Object) (Line: 611)
Drupal\Core\Form\FormBuilder->processForm('node_shortcut_edit_form', Array, Object) (Line: 347)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 634)
Drupal\Core\Render\Renderer::Drupal\Core\Render\{closure}()
Fiber->resume() (Line: 649)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 118)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 92)
Drupal\page_cache\StackMiddleware\PageCache->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: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 745)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
1. Install Unique Field.
2. Edit or create a content type for a node such that the content type includes one entity reference field which may contain unlimited values.
3. Under "Unique field restrictions" check the box for the entity reference field, select "Single node only" and "The combination of values from the specified fields must be unique".
4. Save the content type.
5. Edit content and add a value to the entity reference field twice and save the node.
Proposed resolution
Check to ensure that the $values variable is an array.
Remaining tasks
Create and review patch(es).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | unique_field-3586017-TranslatableMarkup-3.patch | 511 bytes | i.mcbride |
Issue fork unique_field-3586017
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
Comment #2
i.mcbride commentedComment #3
i.mcbride commentedAdding a patch which I believe resolves this issue.
Comment #6
skifdesu commentedAdded a MR which applies current fix for all of 3 entity types: node, term and user.