ArgumentCountError: Too few arguments to ConditionalFieldsFormHelper::__construct()

Created on 4 March 2024, 4 months ago
Updated 5 March 2024, 4 months ago

Problem/Motivation

ArgumentCountError: Too few arguments to function Drupal\conditional_fields\ConditionalFieldsFormHelper::__construct(), 2 passed in C:\Users\www\drupal10\web\core\lib\Drupal\Component\DependencyInjection\Container.php on line 259 and exactly 3 expected in Drupal\conditional_fields\ConditionalFieldsFormHelper->__construct() (line 70 of C:\Users\www\drupal10\web\modules\contrib\conditional_fields\src\ConditionalFieldsFormHelper.php).

Steps to reproduce

update with dev version

Proposed resolution

I because call service in
modules/contrib/conditional_fields/conditional_fields.module
line 201

function conditional_fields_form_after_build($form, &$form_state) {
  return \Drupal::service('conditional_fields.form_helper')->afterBuild($form, $form_state);
}

but conditional_fields.form_helper need 3 variables

  /**
   * ConditionalFieldsFormHelper constructor.
   *
   * @param \Drupal\Core\Render\ElementInfoManager $element_info
   *   A form element information manager.
   * @param \Drupal\conditional_fields\ConditionalFieldsHandlersManager $type
   *   A manager for conditional fields handlers.
   * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
   *   The entity display repository.
   */
  public function __construct(ElementInfoManager $element_info, ConditionalFieldsHandlersManager $type, EntityDisplayRepositoryInterface $entity_display_repository) {
    $this->elementInfo = $element_info;
    $this->type = $type;
    $this->entityDisplayRepository = $entity_display_repository;
  }

to fix, i think i just need to add NULL in $entity_display_repository variables.

  public function __construct(ElementInfoManager $element_info, ConditionalFieldsHandlersManager $type, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
🐛 Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

🇫🇷France lazzyvn paris

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

Comments & Activities

  • Issue created by @lazzyvn
  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • Status changed to Needs review 4 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    130 pass
  • 🇮🇳India abhishek_virasat

    created patch as per above proposed resolution and it works. please kindly review the patch file.

  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    Thanks for the report! Can this be caused by changes from last 4.x dev issue commits? Can you review them here?:

    And is this creating a WSOD or making the site not working? If yes feel free to raise the issue priority again. Otherwise: Descriptions of the Priority and Status values can be found in the Drupal project issues documentation.

  • 🇫🇷France lazzyvn paris

    No, I don't think so, that happens with the new settings module as well, The developper is not attention to #after_build. The EntityDisplayRepositoryInterface (injection dependency) was recently added. before it call drupal service so that's why we don't have any trouble.

  • Status changed to Postponed: needs info 4 months ago
  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    Thanks for coming back on this and your efforts in here! +1 Very much appreciated. I was asking because of we both are no native tongues :) and you have mentioned "dev" in the issue summary shortly without further details. So, do I understand correctly, that you refer here rather to core dev? Could you please try to rephrase the issue summary a lit bit so that it is better understandable what it is about? That would help a lot because it still reads somewhat confusing... Thank you.

    And can you please review the patch provided regarding your reports intention?

    Great finding and thanks for the report! +1

  • 🇫🇷France lazzyvn paris

    please check the debug in the attached file, you will see what is happening

    i debug from return \Drupal::service('conditional_fields.form_helper')->afterBuild($form, $form_state);

  • Status changed to Needs work 4 months ago
  • 🇩🇪Germany diqidoq Berlin | Hamburg | New York | London | Paris

    Thank you! Please keep posting. I viewed the image before already but I haven't seen an error there popping up. What do you mean by you have debugged. In your IDE? So this error is not thrown in Drupal but only in your debug environment?

    EntityDisplayRepositoryInterface has been introduced with Drupal 10.1 so it is not that new, so I am not sure what has caused this in your case and I sadly cannot reproduce it at the moment in a Drupal install. I will take a look at it in your IDE and will try to reproduce your debug experience.

    I actually wanted to make a beta release start of this week. But now I hesitate.

  • 🇫🇷France lazzyvn paris

    I have case it create alots of bug in dev version (not in 4.0.0-alpha5 version)
    could you install state machine or Field States transitions .
    - Active conditional_fields in widget (form manage)
    - Now in the formatter (display manage) you can select formatter type form transitions, after that, site crashes.
    That means that if there is a form in the formatter (not with the widget in the form view), the conditional fields will get a lot of errors (90% with new added dependency injection in dev version)

Production build 0.69.0 2024