Cannot use object of type PluralTranslatableMarkup as array

Issue information

From user: heliogabal

Related to !310 (merged)

Contribution record

Fork management

Hi, thanks for this great module that I finally got a use case for to try it out. Unfortunately, I didn't get very far, and as I'm not a programmer, I can't fix this myself. So reporting here:

Problem/Motivation

After Installation of ECA and the BPMN Modeler, I want to create a first model. Instead of getting to the Modeler, I get a WSOD saying the following:

Error: Cannot use object of type Drupal\Core\StringTranslation\PluralTranslatableMarkup as array in Drupal\eca_modeller_bpmn\ModellerBpmnBase->prepareConfigFields() (Zeile 740 in /var/www/html/html/modules/contrib/eca/modules/modeller_bpmn/src/ModellerBpmnBase.php)

#0 /var/www/html/html/modules/contrib/eca/modules/modeller_bpmn/src/ModellerBpmnBase.php(591): Drupal\eca_modeller_bpmn\ModellerBpmnBase->prepareConfigFields(Array)
#1 /var/www/html/html/modules/contrib/eca/modules/modeller_bpmn/src/ModellerBpmnBase.php(547): Drupal\eca_modeller_bpmn\ModellerBpmnBase->properties(Object(Drupal\social_group\Plugin\Action\AddMembersToGroup), 'action', 'bpmn:Task', Array)
#2 /var/www/html/html/modules/contrib/bpmn_io/src/Plugin/ECA/Modeller/BpmnIo.php(76): Drupal\eca_modeller_bpmn\ModellerBpmnBase->getTemplates()
#3 /var/www/html/html/modules/contrib/bpmn_io/src/Controller/BpmnIo.php(61): Drupal\bpmn_io\Plugin\ECA\Modeller\BpmnIo->edit()
#4 [internal function]: Drupal\bpmn_io\Controller\BpmnIo->add()
#5 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#6 /var/www/html/html/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#7 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#8 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#9 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#10 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#11 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /var/www/html/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/html/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#21 {main}

Steps to reproduce

- Install ECA and the BPMN Modeler after having installed a second language
- go to /admin/config/workflow/eca/add/bpmn-io
- see the error

Proposed resolution

Fix this function in eca/modules/modeller_bpmn/src/ModellerBpmnBase.php line 736:

  protected function prepareConfigFields(array $form): array {
    // @todo Add support for nested form fields like e.g. in container/fieldset.
    $fields = [];
    foreach ($form as $key => $definition) {
      $label = $definition['#title'] ?? Modellers::convertKeyToLabel($key);
      $description = $definition['#description'] ?? NULL;
      $value = $definition['#default_value'] ?? '';
      $weight = $definition['#weight'] ?? 0;
      $type = 'String';
      if (isset($definition['#type'])) {
        // @todo Map to more proper property types of bpmn-js.
        switch ($definition['#type']) {

          case 'hidden':
          case 'actions':
            // The modellers can't handle these types, so we ignore them for
            // the templates.
            continue 2;

          case 'textarea':
            $type = 'Text';
            break;

          case 'checkbox':
            $fields[] = $this->checkbox($key, $label, $weight, $description, $value);
            continue 2;

          case 'checkboxes':
          case 'radios':
          case 'select':
            $fields[] = $this->optionsField($key, $label, $weight, $description, $definition['#options'], (string) $value, $definition['#required'] ?? FALSE);
            continue 2;

        }
      }
      if (is_bool($value)) {
        $fields[] = $this->checkbox($key, $label, $weight, $description, $value);
        continue;
      }
      if (is_array($value)) {
        $value = implode(',', $value);
      }
      $field = [
        'name' => $key,
        'label' => $label,
        'weight' => $weight,
        'type' => $type,
        'value' => $value,
      ];
      if ($description !== NULL) {
        $field['description'] = $description;
      }
      $fields[] = $field;
    }

    // Sort fields by weight.
    usort($fields, static function ($f1, $f2) {
      $l1 = (int) $f1['weight'];
      $l2 = (int) $f2['weight'];
      if ($l1 < $l2) {
        return -1;
      }
      if ($l1 > $l2) {
        return 1;
      }
      return 0;
    });

    return $fields;
  }
Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information