User tests: Successful: Unsuccessful:
Pull Request for Issue #33801
Refactored the foreach block. The loop iteration is executed if the field's value exists and its parent Field Group is to be displayed.
Before the PR, you will be able to see the field groups for all possible groups, including those left blank.
After the PR, Only those groups will be shown that have a field with a value.
None
| Status | New | ⇒ | Pending |
| Category | ⇒ | Front End com_contact |
| Labels |
Added:
?
|
||
I haven't tested but I think you are making more change than needed (and even the current code is having more lines of code than it should)
I think all you need to do is change the current block of code https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_contact/tmpl/contact/default_user_custom_fields.php#L29-L32 with something like:
<?php if ($field->value) : ?>
<?php $userFieldGroups[$field->group_title][] = $field; ?>
<?php endif; ?>No need for defining an extra array, no need for initialize $userFieldGroups[$field->group_title] with an empty array like in the current code.
Or even better, you can move the $field->value check to the if check at the top https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_contact/tmpl/contact/default_user_custom_fields.php#L26, and then remove these lines of code https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_contact/tmpl/contact/default_user_custom_fields.php#L29-L31 and everything will just work well.
Hope I don't miss anything.
Thanks, @joomdonation for the amazing solution. It worked out perfectly!
@sandramay0905 Thank you for testing. If you have time, could you please re-test.
Edit: Please wait before testing, I will be adding one more commit to remove some extra code
Edit 2: Thank you for your patience, you may test the code now
I have tested this item
I created a Group, then went to create a Field and got a 500 error:
500 Unknown column 'a.only_use_in_subform' in 'field list'
JROOT/administrator/components/com_fields/src/View/Fields/HtmlView.php:90
This before applying the patch. I just merged the latest origin into my local copy. I don't know what has wrong but I can't test this PR.
@ceford Your Joomla is outdated. If it is possible, please download nightly build and re-install it. Or if you don't want to re-install, update to Joomla 4 nightly build, then run this SQL command to your database:
ALTER TABLE `#__fields` ADD COLUMN `only_use_in_subform` tinyint(1) NOT NULL DEFAULT 0;Of course you need to replace #__fields with correct database table on your site (depends on the table prefix which you are using for your Joomla installation)
I have tested this item
| Status | Pending | ⇒ | Ready to Commit |
Thanks !
It is not that my installation is out of date. I simply forgot that there is a Database Update option. Anyone, we have two tests so all good.
| Status | Ready to Commit | ⇒ | Fixed in Code Base |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-05-13 13:12:06 |
| Closed_By | ⇒ | richard67 | |
| Labels |
Added:
?
|
||
Thanks!
Thanks all
I have tested this item✅ successfully on 8da070d
Without pull request
With pull request
With pull request, no empty field
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33818.