ArgumentCountError: Too few arguments to function

Created on 18 October 2023, about 1 year ago
Updated 7 November 2023, about 1 year ago

Problem/Motivation

In Drupal 10 it is not working. Once you go to Manage display (/admin/config/people/accounts/display) and try to change image widget to a new one "avatar default" there is following error:

The website encountered an unexpected error. Please try again later.

ArgumentCountError: Too few arguments to function Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::__construct(), 9 passed in \test-01\web\modules\contrib\avatar_field_formatter\src\Plugin\Field\FieldFormatter\AvatarFormatter.php on line 64 and exactly 10 expected in Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter->__construct() (line 75 of core\modules\image\src\Plugin\Field\FieldFormatter\ImageFormatter.php).
Drupal\avatar_field_formatter\Plugin\Field\FieldFormatter\AvatarFormatter->__construct('avatar_formatter_default', Array, Object, Array, 'above', 'default', Array, Object, Object, Object) (Line: 82)
Drupal\avatar_field_formatter\Plugin\Field\FieldFormatter\AvatarFormatter::create(Object, Array, 'avatar_formatter_default', Array) (Line: 64)
Drupal\Core\Field\FormatterPluginManager->createInstance('avatar_formatter_default', Array) (Line: 81)
Drupal\Core\Plugin\DefaultLazyPluginCollection->initializePlugin('avatar_formatter_default') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection->get('avatar_formatter_default') (Line: 149)
Drupal\Component\Plugin\LazyPluginCollection->getIterator() (Line: 114)
Drupal\Core\Plugin\DefaultLazyPluginCollection->getConfiguration() (Line: 295)
Drupal\Core\Config\Entity\ConfigEntityBase->preSave(Object) (Line: 270)
Drupal\Core\Entity\EntityDisplayBase->preSave(Object) (Line: 528)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 609)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('entity_view_display_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
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: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇸🇰Slovakia coaston

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

Comments & Activities

  • Issue created by @coaston
  • Assigned to Shreya_98
  • @shreya_th opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 year ago
  • 🇸🇰Slovakia coaston

    Hi,

    After your MR there is another issue instead :

    TypeError: Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::__construct(): Argument #10 ($file_url_generator) must be of type Drupal\Core\File\FileUrlGeneratorInterface, Drupal\Core\Transliteration\PhpTransliteration given, called in \test-01\web\modules\contrib\avatar_field_formatter\src\Plugin\Field\FieldFormatter\AvatarFormatter.php on line 64 in Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter->__construct() (line 75 of \test-01\web\core\modules\image\src\Plugin\Field\FieldFormatter\ImageFormatter.php).
    
  • 🇳🇱Netherlands arantxio Dordrecht

    Here is a patch that i've just created and seems to be working. haven't tested completely yet.

  • Status changed to Needs review about 1 year ago
  • 🇸🇰Slovakia coaston

    Hi Arantxio,

    Your patch works like a charm. No issues found. Can you create MR please?

  • 🇳🇱Netherlands arantxio Dordrecht

    @coaston I've updated the existing branch to use the patch that I had created. Hope this helps.

  • Status changed to RTBC about 1 year ago
Production build 0.71.5 2024