Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up null issue #391

Closed
wants to merge 2 commits into from
Closed

Fix up null issue #391

wants to merge 2 commits into from

Conversation

dereuromark
Copy link
Member

@dereuromark dereuromark commented Sep 27, 2023

In my case there was a type error:

  1. App\Test\TestCase\Controller\MiscControllerTest::testConvertText
    TypeError: BootstrapUI\View\Helper\FormHelper::injectClasses(): Argument # 1 ($classes) must be of type array|string, null given, called in /work/devilbox/data/www/sandbox/vendor/friendsofcake/bootstrap-ui/src/View/Helper/FormHelper.php on line 650

Can be avoided by defaulting it to a valid type

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (7ce12a7) 99.37% compared to head (989c448) 99.37%.

❗ Current head 989c448 differs from pull request most recent head c5612d5. Consider uploading reports for the commit c5612d5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #391   +/-   ##
=========================================
  Coverage     99.37%   99.37%           
  Complexity      369      369           
=========================================
  Files            21       21           
  Lines          1277     1277           
=========================================
  Hits           1269     1269           
  Misses            8        8           
Files Coverage Δ
src/View/Helper/FormHelper.php 99.28% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dereuromark
Copy link
Member Author

There could also be more wrong from the setup, I will have to check first again

@dereuromark dereuromark deleted the 5.x-fix branch September 27, 2023 12:52
@toggenation
Copy link

There could also be more wrong from the setup, I will have to check first again

I just ran into this null bug with a fresh install of CakePHP 5.0.2 and Bootstrap UI 5.0.0

Do we need to re-instate your patch or is there a setup issue that needs tweaking?

@ndm2
Copy link
Collaborator

ndm2 commented Nov 8, 2023

@toggenation Do you have a way to reproduce the problem?

The only way I can see this happening is when you're using FormHelper::control() without calling FormHelper::create() first. This can be fixed, but I'm not sure whether this should generally be expected to work without any side effects.

@dereuromark
Copy link
Member Author

Yeah, indeed

echo $this->Form->control('Form.result', ['type' => 'textarea', 'class' => 'halfSize']);

This is breaking existing code

I would be in favor of fixing this, as this is not necessary to blow up this hard IMO

@ryanolton
Copy link

I've just started migrating a large project from CakePHP 4.5 to 5.0.2 which has many FormHelper::control() instances with no corresponding FormHelper::create(), and I'm running into this error as well.

I've search the CakePHP documentation and implies that FormHelper::create() is required to use FormHelper::control(): does anyone know if this is a strict requirement, or merely a suggestion?

The HTML spec notes that elements such as <input> or <select> do not need to be associated with a <form>, only that they can be.

@ndm2
Copy link
Collaborator

ndm2 commented Nov 12, 2023

The error shouldn't happen, but a possible "requirement" of the helper to open a form first would not be related to the HTML specs, but to the magic that the control() method provides with regards to the form context, for example automatically rendering errors, setting default values, setting properties like required, figuring the type, etc., and in the context of BootstrapUI it would be things like the Bootstrap form layout, grid, spacing, etc.

@ryanolton
Copy link

@ndm2 thanks for your help on this, I appreciate it!

@dereuromark
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants