Problem/Motivation

When installing Drupal profile with features that include webforms the following error occurs

In Inline.php line 199:
                                                              
  [Symfony\Component\Yaml\Exception\DumpException]            
  Object support when dumping a YAML file has been disabled.  
                                                              

Exception trace:
  at /www/app/vendor/symfony/yaml/Inline.php:199
 Symfony\Component\Yaml\Inline::dump() at /www/app/vendor/symfony/yaml/Dumper.php:97
 Symfony\Component\Yaml\Dumper->dump() at /www/app/vendor/symfony/yaml/Dumper.php:153
 Symfony\Component\Yaml\Dumper->dump() at /www/app/vendor/symfony/yaml/Dumper.php:153
 Symfony\Component\Yaml\Dumper->dump() at /www/app/vendor/symfony/yaml/Dumper.php:153
 Symfony\Component\Yaml\Dumper->dump() at /www/app/web/modules/contrib/webform/src/Utility/WebformYaml.php:31
 Drupal\webform\Utility\WebformYaml::encode() at /www/app/web/modules/contrib/webform/includes/webform.editor.inc:138
 _webform_get_array_file_uuids() at /www/app/web/modules/contrib/webform/includes/webform.editor.inc:119
 _webform_get_config_entity_file_uuids() at /www/app/web/modules/contrib/webform/includes/webform.editor.inc:33
 webform_webform_insert() at n/a:n/a
 call_user_func_array() at /www/app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403
 Drupal\Core\Extension\ModuleHandler->invokeAll() at /www/app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:347
 Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook() at /www/app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:535
 Drupal\Core\Entity\EntityStorageBase->doPostSave() at /www/app/web/modules/contrib/webform/src/WebformEntityStorage.php:85
 Drupal\webform\WebformEntityStorage->doPostSave() at /www/app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:460
 Drupal\Core\Entity\EntityStorageBase->save() at /www/app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:263
 Drupal\Core\Config\Entity\ConfigEntityStorage->save() at /www/app/web/modules/contrib/webform/src/WebformEntityStorage.php:92
 Drupal\webform\WebformEntityStorage->save() at /www/app/web/core/lib/Drupal/Core/Entity/EntityBase.php:395
 Drupal\Core\Entity\EntityBase->save() at /www/app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:616
 Drupal\Core\Config\Entity\ConfigEntityBase->save() at /www/app/web/core/lib/Drupal/Core/Config/ConfigInstaller.php:371
 Drupal\Core\Config\ConfigInstaller->createConfiguration() at /www/app/web/modules/contrib/features/src/FeaturesConfigInstaller.php:99
 Drupal\features\FeaturesConfigInstaller->createConfiguration() at /www/app/web/core/lib/Drupal/Core/Config/ConfigInstaller.php:137
 Drupal\Core\Config\ConfigInstaller->installDefaultConfig() at /www/app/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php:287
 Drupal\Core\Extension\ModuleInstaller->install() at /www/app/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php:83
 Drupal\Core\ProxyClass\Extension\ModuleInstaller->install() at /www/app/web/profiles/profile/profile.install:70
 profile_install() at n/a:n/a
 call_user_func_array() at /www/app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:392
 Drupal\Core\Extension\ModuleHandler->invoke() at /www/app/web/core/lib/Drupal/Core/Extension/ModuleInstaller.php:325
 Drupal\Core\Extension\ModuleInstaller->install() at /www/app/web/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php:83
 Drupal\Core\ProxyClass\Extension\ModuleInstaller->install() at /www/app/web/core/includes/install.core.inc:1649
 install_install_profile() at /www/app/web/core/includes/install.core.inc:695
 install_run_task() at /www/app/web/core/includes/install.core.inc:570
 install_run_tasks() at /www/app/web/core/includes/install.core.inc:118
 install_drupal() at /www/app/vendor/drush/drush/includes/drush.inc:229
 drush_call_user_func_array() at /www/app/vendor/drush/drush/includes/drush.inc:214
 drush_op() at /www/app/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php:145
 Drush\Commands\core\SiteInstallCommands->install() at n/a:n/a
 call_user_func_array() at /www/app/vendor/consolidation/annotated-command/src/CommandProcessor.php:257
 Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() at /www/app/vendor/consolidation/annotated-command/src/CommandProcessor.php:212
 Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() at /www/app/vendor/consolidation/annotated-command/src/CommandProcessor.php:178
 Consolidation\AnnotatedCommand\CommandProcessor->process() at /www/app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:302
 Consolidation\AnnotatedCommand\AnnotatedCommand->execute() at /www/app/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /www/app/vendor/symfony/console/Application.php:1005
 Symfony\Component\Console\Application->doRunCommand() at /www/app/vendor/symfony/console/Application.php:255
 Symfony\Component\Console\Application->doRun() at /www/app/vendor/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /www/app/vendor/drush/drush/src/Runtime/Runtime.php:118
 Drush\Runtime\Runtime->doRun() at /www/app/vendor/drush/drush/src/Runtime/Runtime.php:49
 Drush\Runtime\Runtime->run() at /www/app/vendor/drush/drush/drush.php:72
 require() at /www/app/drush9:47

which is similar to #3091252: Computed Twig leads to YAML Object Error.

Comments

VladimirAus created an issue. See original summary.

vladimiraus’s picture

Status: Active » Needs review
StatusFileSize
new910 bytes

  • VladimirAus authored c0f14d4 on 8.x-5.x
    Issue #3194495 by VladimirAus: "Object support when dumping a YAML file...

  • a5e2653 committed on 8.x-5.x
    Revert "Issue #3194495 by VladimirAus: "Object support when dumping a...
jrockowitz’s picture

Status: Needs review » Needs work

We should determine where and how Markup is being added to a Webform's config via a profile.

vladimiraus’s picture

Status: Needs work » Needs review

In my case it is not in the profile, it is in another module as yml config file.

jrockowitz’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can you please upload an example of the configuration or module which is triggering the error?

I would like to be able to reproduce the issue before applying the patch.

  • a5e2653 committed on 6.x
    Revert "Issue #3194495 by VladimirAus: "Object support when dumping a...
  • VladimirAus authored c0f14d4 on 6.x
    Issue #3194495 by VladimirAus: "Object support when dumping a YAML file...
vladimiraus’s picture

Thank @jrockowitz. I’m still debugging it trying to confirm it is caused by webform and not a custom plugin

jrockowitz’s picture

Are you using the default language which is English? If not, it is possible that Drupal core is translating the webform's strings during the installation.

vladimiraus’s picture

Yep, using single language website in english.

jrockowitz’s picture

Something is definitely converting strings into Markup or adding Markup to the webform's settings.

My hesitation about applying the patch is it will slow down the saving of webform.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Please reopen this ticket when you can provide example of the configuration or module which is triggering the error.

jcandan’s picture

The "Object support when dumping a YAML file has been disabled." error occurs with my project as well.

After upgrading to Webform 6 I am able to get the site install to complete with only 1 out of the 11 webform configs I have. Patch #2 helped me overcome the error for all 11.

I attempted to recreate the issue with a clean Drupal instance and a bare-bones custom install profile with one of my non-working webform configuration files; however I was unable to replicate the error there.

Note (in case it helps): In this attempt, I commented out a couple of custom third party settings.

jfauske’s picture

I came across this issue when updating a custom module to work with Drupal 9.
In my case the markup came from using @translation(...) on fields in in the WebformHandler annotation.
This makes i.e the handler label an instance of Drupal\Core\StringTranslation\TranslatableMarkup instead of a string in the $data passed to _webform_get_array_file_uuids().

i.e this will trigger the issue:

/**
 * Form submission handler.
 *
 * @WebformHandler(
 *   id = "my_module_handler",
 *   label = @Translation("my label"),
 *   category = @Translation("Form Handler"),
 *   description = @Translation("Sends submission data"),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
 */
class MyModuleWebformHandler extends WebformHandlerBase {

This will not:

/**
 * Form submission handler.
 *
 * @WebformHandler(
 *   id = "my_module_handler",
 *   label = "my label",
 *   category = "Form Handler",
 *   description = "Sends submission data",
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
 */
class MyModuleWebformHandler extends WebformHandlerBase {
flocondetoile’s picture

Status: Closed (cannot reproduce) » Active

I came across this issue with a custom module which have 3 custom Plugin WebformHandler. Applying comments in #15 fix the issue.
Thanks @jfauske I believe you saved my night. The automatic process for building a project was broken.

I think we have the root cause, no ? So, status back to Active.

priya sundharam’s picture

.

jrockowitz’s picture

Version: 6.0.0 » 6.1.x-dev
Status: Active » Postponed (maintainer needs more info)

Does the patch from #2 fix this issue?

jfauske’s picture

Status: Postponed (maintainer needs more info) » Active

Yes, the patch in #2 fix the issue.
Though I'm not sure if it's the optimal place to "sanitize" the content of the $data array.
That's for someone with more insight to evaluate.

amjad1233’s picture

StatusFileSize
new498 bytes

The issue came up when I was doing a functional test where I had to create a webform programatically.

The error started when I added `$this->t()` function to `#options` value using `Drupal\Core\StringTranslation\StringTranslationTrait;`

$webform = $this->createWebform([],
    [
      'conditional_field_trigger' => [
        '#type' => 'select',
        '#title' => 'Conditional Field Trigger',
        '#options' => [
          'option_1' => $this->t('Option 1'),
          'option_2' => $this->t('Option 2'),
        ],
      ],
      'conditional_field_dependent' => [
        '#type' => 'select',
        '#title' => 'Conditional Field Dependent',
        '#options' => [
          'option_1' => $this->t('Option 1'),
          'option_2' => $this->t('Option 2'),
        ],
        '#states' => [
          [':input[name="conditional_field_trigger"]' => ['value' => 'option_2']],
        ],
      ],
    ]);

I did render element bit differently in the Webform::setElement method just before encoding it we render all the strings.

If accepted solution I am happy to write some tests around it.

jrockowitz’s picture

Status: Active » Closed (won't fix)

In your code, you should be casting the TranslatedMarkup to strings via 'option_1' => (string) $this->t('Option 1'),.

Also, it is worth noting that strings in tests do not need to be translated unless you are testing translations.

@see #3133726: [meta] Remove usage of t() in tests not testing translation

amjad1233’s picture

Thanks @jrockowitz.

That works perfect. The only reason I added t() function is because the phpcs was complaining about form options not being translated.

larowlan’s picture

phpcs is not accurate in this regard, it is misinterpreting it as Form API code, but its webform code.

Run phpcs -as and take note of the rule that is wrong, and wrap your code with something like the below

e.g. if the rule is DrupalPractice.General.DescriptionT.DescriptionT

You should wrap that hunk with

     // phpcs:disable DrupalPractice.General.DescriptionT.DescriptionT

    // code here

   // phpcs:enable