Make sure $callback is_callable. ( TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "FileSizeLimit" not found or invalid function name )

Created on 20 March 2024, 8 months ago
Updated 25 April 2024, 7 months ago

Problem/Motivation

Trying to use reference plugin results in this error in the console:
TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "FileSizeLimit" not found or invalid function name in filefield_sources_element_validate() (line 646 of /var/www/html/web/modules/contrib/filefield_sources/filefield_sources.module).

Set to major, as it breaks the ability to reference files.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Source: Auto-complete

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @tonytheferg
  • Merge request !9check that $function is callable β†’ (Open) created by tonytheferg
  • Status changed to Needs review 8 months ago
  • Here is the backtrace:

    #0 /var/www/html/web/modules/contrib/filefield_sources/src/Plugin/FilefieldSource/Reference.php(48): filefield_sources_element_validate(Array, Object(Drupal\file\Entity\File), Object(Drupal\Core\Form\FormState))
    #1 /var/www/html/web/modules/contrib/filefield_sources/filefield_sources.module(365): Drupal\filefield_sources\Plugin\FilefieldSource\Reference::value(Array, Array, Object(Drupal\Core\Form\FormState))
    #2 /var/www/html/web/core/modules/file/src/Element/ManagedFile.php(91): filefield_sources_field_value(Array, Array, Object(Drupal\Core\Form\FormState))
    #3 /var/www/html/web/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php(337): Drupal\file\Element\ManagedFile::valueCallback(Array, Array, Object(Drupal\Core\Form\FormState))
    #4 [internal function]: Drupal\file\Plugin\Field\FieldWidget\FileWidget::value(Array, Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1266): call_user_func_array(Array, Array)
    #6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1006): Drupal\Core\Form\FormBuilder->handleInputElement('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1076): Drupal\Core\Form\FormBuilder->doBuildForm('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #10 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(579): Drupal\Core\Form\FormBuilder->doBuildForm('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #11 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('node_tool_edit_...', Array, Object(Drupal\Core\Form\FormState))
    #12 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\NodeForm), Object(Drupal\Core\Form\FormState))
    #13 /var/www/html/web/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #14 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #18 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #33 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #34 {main}
  • Not sure if this is the right fix. Need a maintainer who knows the module to review.

  • πŸ‡©πŸ‡ͺGermany Kniekel

    Patch #3 works for me, thank you very much!

  • πŸ‡ΊπŸ‡ΈUnited States rschwab

    Attaching a patch that uses the Drupal file validator service and constraints. For more info on this see: https://www.drupal.org/node/3363700 β†’

    I think the problem with the issue branch in this thread is that you won't get the validation errors, because those functions remain invalid callback functions in D10.

    The attached patch successfully produced constraint errors like the attached image.

  • πŸ‡ΊπŸ‡ΈUnited States rschwab
  • πŸ‡²πŸ‡½Mexico gnuget Puebla

    I tried to replicate this issue without luck.

    Can you please provide a list of steps?

    The patch looks I just want to test it before to commit it.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States rschwab

    I only saw this on Drupal 10, not Drupal 9.

    Steps were (from memory):
    1. install drupal 10 and filefield sources
    2. enable filefield sources
    3. edit a content type and add a file field
    4. configure the file field to use sources: reference autocomplete
    5. edit a node of the relevant type, and try to reference a file.

  • πŸ‡²πŸ‡½Mexico gnuget Puebla

    This works great.

    I have just some doubts about the use of the file.validator service, it seems that it was added in Drupal 10.2 which was released just one month ago.

    I know that this is something that is not working anyway but the module's info file says:

    core_version_requirement: ^9.2 || ^10
    

    I wonder what is best if take advantage of this new service and just bump the core version requirement to ^10.2 or be more flexible and support at least older versions of Drupal 10?

    I understand that this branch hasn't a single release yet, so we can do whatever we want πŸ˜† but what is the best thing to do?

    Thoughts?

Production build 0.71.5 2024