Cannot use object of type PluralTranslatableMarkup as array

Created on 15 February 2023, almost 2 years ago
Updated 16 February 2023, almost 2 years ago

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;
  }
🐛 Bug report
Status

Fixed

Version

1.2

Component

Code

Created by

🇩🇪Germany heliogabal Berlin

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

Comments & Activities

  • Issue created by @heliogabal
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Welcome to ECA @heliogabal and sorry that your journey starts with a bad experience.

    From looking into the stack trace, it looks like there is a custom module social_group in your Drupal installation which provides some plugin, that our tools are not yet expect.

    Is this a custom module? Or is it from a public source where we could have a look what it does?

  • 🇩🇪Germany jurgenhaas Gottmadingen

    I can't find the module social_group here on drupal.org but looking into the code, I have an assumption of what that module does: it defines a form element for one of its plugins which uses markup in a wrong way.

    To see if that's the case you can make a small modification in your Drupal installation: in the file /var/www/html/html/modules/contrib/eca/modules/modeller_bpmn/src/ModellerBpmnBase.php you can find the following code sequence around line 740:

        $fields = [];
        foreach ($form as $key => $definition) {
          $label = $definition['#title'] ?? Modellers::convertKeyToLabel($key);
          $description = $definition['#description'] ?? NULL;
          $value = $definition['#default_value'] ?? '';
    

    Please add 3 lines so that the code sequence looks like this and then save the file:

        $fields = [];
        foreach ($form as $key => $definition) {
          if (!is_array($definition)) {
            continue;
          }
          $label = $definition['#title'] ?? Modellers::convertKeyToLabel($key);
          $description = $definition['#description'] ?? NULL;
          $value = $definition['#default_value'] ?? '';
    

    If that fixes the issue, we need to think about if and how we should handle such false use of form configuration to prevent this from happening again. Or the maintainers of the social_group may want to fix that in the source.

  • 🇩🇪Germany heliogabal Berlin

    thanks @jurgenhaas, that must have been the fasted answer I've ever had in all these years in the Drupal issue queue! I appreciate that very much!

    The Social Group module is part of the Open Social Distribution , so it's buried in the distribution profile, not very obvious to find. I realize it might count as a custom module for the distro: https://git.drupalcode.org/project/social/-/tree/11.5.x/modules/social_f...

    Still, it would be nice to be able to use the two together, so I hope it's not too difficult to accommodate for that.

    Thanks for looking into it!

    As of your suggestion, I added the

    if (!is_array($definition)) {
            continue;
          }

    and tried again, but unfortunately, that doesn't fix the issue but only provides a different error:

    AssertionError: Cannot load the "group" entity with NULL ID. in assert() (Zeile 295 in /var/www/html/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php)

    #0 /var/www/html/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php(295): assert(false, 'Cannot load the...')
    #1 /var/www/html/html/profiles/contrib/social/modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php(143): Drupal\Core\Entity\EntityStorageBase->load(NULL)
    #2 /var/www/html/html/modules/contrib/eca/src/Service/Actions.php(128): Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole->buildConfigurationForm(Array, Object(Drupal\Core\Form\FormState))
    #3 /var/www/html/html/modules/contrib/eca/modules/modeller_bpmn/src/ModellerBpmnBase.php(547): Drupal\eca\Service\Actions->getConfigurationForm(Object(Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole), Object(Drupal\Core\Form\FormState))
    #4 /var/www/html/html/modules/contrib/bpmn_io/src/Plugin/ECA/Modeller/BpmnIo.php(76): Drupal\eca_modeller_bpmn\ModellerBpmnBase->getTemplates()
    #5 /var/www/html/html/modules/contrib/bpmn_io/src/Controller/BpmnIo.php(61): Drupal\bpmn_io\Plugin\ECA\Modeller\BpmnIo->edit()
    #6 [internal function]: Drupal\bpmn_io\Controller\BpmnIo->add()
    #7 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #8 /var/www/html/html/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #9 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #10 /var/www/html/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #13 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /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)
    #16 /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)
    #17 /var/www/html/html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /var/www/html/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /var/www/html/html/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #23 {main}

    Don't really know what to do with that either. Sorry to bother you with faulty code from some other module, should I post your findings to the Open Social issue group?

  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks for testing this so quickly as well. Looks like the OpenSocial distro provides some "interesting" plugin flavours that we haven't seen with any of the other modules yet, that also provide action plugins.

    I'd suggest, before we (or you) open any issues in the OpenSocial issue queue, I'd rather give that distro a try and see if I can identify what the source of the issue is. Maybe it's perfectly valid what they are doing and we are not copying with that correctly at our end. But if their usage of the action plugin API were indeed invalid, I could then provide detailed information about what needed to be corrected.

    I hope to find some time in the next few days to go through that and I'll report back here.

    If you still wanted to give ECA a test flight, maybe you could do that in the meantime on a vanilla Drupal installation?

  • 🇩🇪Germany heliogabal Berlin

    that sounds like a plan. I think the quickest way to install the distro is with the template: https://github.com/goalgorilla/social_template/

    It's a great distro, providing massive features, but I also discovered some very opinionated deviation from standard Drupal behavior already (getting rid of the Edit Tab for example), but I can't judge the code quality or standard adherence. So I am curious as to what you will find.

    Good luck finding out more, I'll postpone my initial plan then but will definitely not give up on ECA, and am sure to find my next use case on a more standard project first. Thanks again for the fastest help!

  • 🇩🇪Germany jurgenhaas Gottmadingen

    You're welcome.

    One more question: which version of that distribution are you using? I just want to use the same for my review.

  • 🇩🇪Germany heliogabal Berlin

    I'm using the latest stable version 11.7.2 (updated today). I think the profiel template is still on 11.7.0, but that shouldn't make a difference, as only a few unrelated bugs were fixed in between.

    Good luck!

  • 🇩🇪Germany jurgenhaas Gottmadingen

    OK, there are 3 issues here:

    • First: they specify are form title for their action plugin like $form['#title'] = 'some title text'; and ECA is not prepared for that, hence the first error.
    • Second: the ChangeGroupMembershipRole action plugin assumes that it is only always being called on a group page, as they call $id = $this->routeMatch->getRawParameter('group'); and require the ID to be a valid group id. If that's not available, this throws the second exception.
    • Third: they also assume that the plugin context is defined while building the configuration form. But that's not necessarily the case. This results in warning messages because they call things like $this->context['selected_count']

    The third one will create warnings that we can't prevent from being displayed. But the other 2 can be avoided and I'll provide you with a fix shortly.

  • @jurgenhaas opened merge request.
  • Status changed to Needs review almost 2 years ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is now working. I've implemented MR310 such that it now fully ignores action plugins that are causing issues. Not only for OpenSocial, but in general.

    Please give that patch a try and let me know if it works for you too.

    We can also then decide, if and who is going to report those issues in the OpenSocial project.

  • Status changed to RTBC almost 2 years ago
  • 🇩🇪Germany heliogabal Berlin

    Wow, there are quite some assumptions being made then by Open Social... might be worth notifying them about it, so they can catch any exception to those assumptions themselves as well, so other modules don't run into similar problems? Not sure if I can explain this in a good way, so maybe it may make more sense if you report this in your own words, programmer to programmer?

    Either way, I tested the provided patch and it works as advertised. I can now open the BPMN Modeler and create my first model. So to me, problem is solved, let me know if I can do anything else in the matter. And thanks again for your lightning-fast response and timely help, this already made my day!

    • jurgenhaas committed 4fbe8e3b on 1.2.x
      Issue #3341997 by jurgenhaas, heliogabal: Cannot use object of type...
    • jurgenhaas committed 2703ff7e on 1.1.x
      Issue #3341997 by jurgenhaas, heliogabal: Cannot use object of type...
  • Status changed to Fixed almost 2 years ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    And thanks again for your lightning-fast response and timely help, this already made my day!

    Sure! Also thanks for the really detailed report and also prompt response to follow-up questions. Really helpful.

    I have merged the fix into 1.2.x-dev and back ported it to 1.1.x-dev too

    The issues have been reported also to #3342372: Some issues with action plugins .

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

Production build 0.71.5 2024