Problem/Motivation

I am using default_content_deploy for content export and when exporting it reports the following error

 [error]  Invalid values given. Values must be represented as an associative array. 
 [notice] List of available content entity types:
block_content (Blocco custom)
file (File)
media (Media)
menu_link_content (Link personalizzato nel menu)
node (Contenuto)
paragraph (Paragrafo)
path_alias (Alias URL)
redirect (Reindirizzamento)
taxonomy_term (Termine di tassonomia)
user (Utente)

Steps to reproduce

Used:
- Drupal Core: 8.9.3
- default_content: 1.0-alpha8
- default_content_deploy: 1.0-beta1

And execute this command:
drush dcder menu_link_content

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

simone.marchese created an issue. See original summary.

sophie.sk’s picture

We're seeing this on our sites too, when using the TMGMT Smartling module. For some translation jobs that we request, there's an error:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Invalid values given. Values must be represented as an associative array. in Drupal\Core\TypedData\Plugin\DataType\Map->setValue() (line 76 of core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php).

Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object, 'options', ) (Line: 116)
Drupal\Core\TypedData\Plugin\DataType\Map->get('options') (Line: 160)
Drupal\Core\TypedData\Plugin\DataType\Map->getProperties() (Line: 28)
Drupal\tmgmt_content\DefaultFieldProcessor->extractTranslatableData(Object) (Line: 17)
Drupal\tmgmt_content\LinkFieldProcessor->extractTranslatableData(Object) (Line: 182)
Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->extractTranslatableData(Object) (Line: 100)
Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource->getData(Object) (Line: 395)
Drupal\tmgmt\Entity\JobItem->getSourceData() (Line: 999)
Drupal\tmgmt\Entity\JobItem->recalculateStatistics() (Line: 925)
Drupal\tmgmt\Entity\Job->getSuggestions() (Line: 804)
Drupal\tmgmt\Form\JobForm->buildSuggestions(Array, Object) (Line: 348)
Drupal\tmgmt\Form\JobForm->form(Array, Object) (Line: 149)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('tmgmt_job_edit_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 166)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

It looks like the error comes from the options value in the link override. In some cases, it's set to FALSE rather than NULL, so it tries to set the value incorrectly.

In the database I can see three different values for the override options:

MySQL [database]> select distinct(link_override__options) from menu_link_content_data;
+------------------------+
| link_override__options |
+------------------------+
| NULL                   |
| N;                     |
| a:0:{}                 |
+------------------------+
3 rows in set (0.004 sec)

I wonder which it should be ... probably NULL! I'm doing more digging.

sophie.sk’s picture

Status: Active » Needs review
StatusFileSize
new1.89 KB

I can't quite figure out what's causing it, but it seems that if a link is empty then the original link options get added into an overridden options array, which has a FALSE key rather than NULL.

Attaching a patch - it fixes the issue by by switching the options around, and adds a crude update hook to make all of the overridden option values the same as the parent options. The update checks whether the overridden value is a serialized array (which suggests that it's had values set) and, if not, it sets the value to the same as the parent link's.

It is really crude and it works for our use case but hopefully it can provide some steer on how to fix more widely :)

sophie.sk’s picture

StatusFileSize
new1.89 KB

I can't wait for the day when I upload the right patch the first time around. I made manual changes to it before uploading it so it was failing to apply. Duh.

jsobiecki’s picture

Hello @Sophie.SK, thanks for patch. I had quite busy time recently, but I'll do my best to take a look on this over this weekend.

Best,
Jarek

nwom’s picture

Category: Support request » Bug report
Status: Needs review » Needs work

The patch fixed an issue I was having, however it results in the following error when attempting to update the db via drush updatedb:

[error]  ParseError: syntax error, unexpected end of file in module_load_include() (line 41 of /modules/contrib/translatable_menu_link_uri/translatable_menu_link_uri.install) #0 /core/includes/module.inc(23): module_load_include('install', 'translatable_me...')
#1 /core/includes/install.inc(86): module_load_install('translatable_me...')
#2 /vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(42): drupal_load_updates()
#3 [internal function]: Drush\Commands\core\UpdateDBCommands->updatedb(Array)
#4 /vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#5 /vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#6 /vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#7 /vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#15 /vendor/drush/drush/includes/preflight.inc(18): require('/var/www/vhosts...')
#16 phar:///usr/local/bin/drush/bin/drush.php(143): drush_main()
#17 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#18 {main}.

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

maacl’s picture

Status: Needs work » Needs review

After applying the patch, the file "translatable_menu_link_uri.install" was missing a "}", so I uploaded the patch again in an issue fork. Although the diff looks the same, I now have a working patch.

The patch solves the problem in tmgmt for me.

stefan.butura’s picture

Attached patch with closing brackets in translatable_menu_link_uri.install

stefan.butura’s picture

Updated patch to make it so that the hook_update also fixes the menu_link_content_field_revision table.

stefan.butura’s picture

kmonty’s picture

We encountered the same issue after installing this module using TMGMT patched to work with layout_builder_st. Confirming the patch in #11 resolved our issue.

Noting that our `menu_link_content_data` DB table matched that of #2 prior to running the database update command. After running it, it was cleaned up.

anybody’s picture

qusai taha’s picture

Patch #11 working fine and fixing an issue with the TMGMT module.

Thank you

qusai taha’s picture

Status: Needs review » Reviewed & tested by the community
jsobiecki’s picture

Hi All, thank you for reviewing patch and providing patches. I'm working on final review as part of GlobalContributionWeekend2023.

jsobiecki’s picture

1. I believe that 8.x is not supported anymore, so I decided to skip this version
2. I tested on D10, with newest version of default content module - PASS
3. I tried to reproduce problem with TMGMT - PASS

I wasn't able to create NULL value at database, but I agree that fixing serialization is good thing.

Patch looks ok, decided to commit it.

Thanks all for contributing!

jsobiecki’s picture

jsobiecki’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

snehauskoim’s picture

Could this patch also be reworked for Drupal 9?

function translatable_menu_link_uri_update_8001()

Because for some older sites this problem still exists and requires database updates

carma03’s picture

As per @SnehauskoiM's comment and request, this is the patch for Drupal 9.

carma03’s picture

As per @SnehauskoiM's comment and request, this is the right patch for Drupal 9.

damondt’s picture

There may have been a regression, I'm getting this error on D10 and translatable_menu_link_uri 2.1
The options value is null in the db if not overridden which gets unserialized as false which throws an error when using tmgmt.
The attached patch sets options to [] when null on menu_link_content load, I don't know weather this is the ideal solve.