Correct ModalForm $form['body']

Created on 24 February 2023, over 1 year ago
Updated 25 April 2023, about 1 year ago

Problem/Motivation

Modal Form contain wrong code:
TypeError: Cannot access offset of type string on string in Drupal\modal_page\Form\ModalForm->form() (line 128 of /app/web/modules/contrib/modal_page/src/Form/ModalForm.php).

Steps to reproduce

  1. Using PHP 8.1
  2. Enable modal 5.x
  3. Create any modal
  4. Form will not load sucessfully because of
    $body = $modal->getBody();                      // $body as string
    if (empty($body['value'])) {                    // $body as array
          $body['value'] = '';
        }
        // Drupal controls the default format value.
        if (empty($body['format'])) {
          $body['format'] = NULL;
        }
    $form['body'] ....
    

    is not set as correct format

Proposed resolution

- Remove `$body['format']`
- Use `$modal->getBody()` instead of `$body['value']`

πŸ› Bug report
Status

Needs work

Version

5.0

Component

Code

Created by

πŸ‡»πŸ‡³Vietnam mrddthi

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

Comments & Activities

  • Issue created by @mrddthi
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    Thanks

  • Status changed to Needs work about 1 year ago
  • πŸ‡§πŸ‡·Brazil Diego_Mow

    Tested this with Drupal 10.1.x and result is that I cannot edit an existing form:

    The website encountered an unexpected error. Please try again later.
    
    TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php).
    Drupal\Component\Utility\Unicode::validateUtf8(Array) (Line: 65)
    Drupal\Component\Utility\Xss::filter(Array, Array) (Line: 70)
    Drupal\editor\EditorXssFilter\Standard::filterXss(Array, Object, NULL) (Line: 349)
    editor_filter_xss(Array, Object) (Line: 109)
    Drupal\editor\Element->preRenderTextFormat(Array)
    call_user_func_array(Array, Array) (Line: 101)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 168)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    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: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 686)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • First commit to issue fork.
Production build 0.69.0 2024