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

IBX-8980: Fixed getGroupedFields method implementation #77

Merged
merged 13 commits into from
Mar 5, 2025

Conversation

Sztig
Copy link
Contributor

@Sztig Sztig commented Nov 21, 2024

🎫 Issue IBX-8980

Related PRs:

Description:

Based on the interface of GroupedContentFormFieldsProvider the method getGroupedFields is implemented incorrectly. The description of the interface states Array of fieldGroupIdentifier grouped by fieldGroupName should be returned. Right now it doesn't return the fieldGroupIdentifier but a translation of said identifier.

For the example the previously retrieved key would be Basic Information, after the fix it's going to be basic_information

@Sztig Sztig requested a review from a team November 21, 2024 11:07
$groupedFields = [];

foreach ($fieldsDataForm as $fieldForm) {
/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData $fieldData */
$fieldData = $fieldForm->getViewData();
$fieldGroupIdentifier = $this->fieldsGroupsList->getFieldGroup($fieldData->fieldDefinition);
$fieldGroupName = $fieldsGroups[$fieldGroupIdentifier] ?? $this->fieldsGroupsList->getDefaultGroup();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even tho it seems like a bug, not sure we can fix it that way due to bc policy. Otoh, this seems so internal and if only used by that one place (is it tho?) it should be acceptable.
@ibexa/php-dev

@ViniTou ViniTou requested a review from a team December 9, 2024 11:37
Copy link
Contributor

@mikadamczyk mikadamczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that $fieldGroupName which is a key in the returned array is used in other places (admin-ui, product-catalog).

@Sztig
Copy link
Contributor Author

Sztig commented Jan 14, 2025

Alright, I will try then implementing a new provider and update the templates in corporate-account to use said provider instead.

@Sztig Sztig force-pushed the IBX-8980-grouped-fields-fix branch from 81aef34 to d53ab22 Compare January 20, 2025 13:44
Comment on lines 18 to 19
/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */
private $fieldsGroupsList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer typed properties over annotations, when dealing with PHP 7.4+ and no BC.

Suggested change
/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */
private $fieldsGroupsList;
private FieldsGroupsList $fieldsGroupsList;

]);

$subject = new GroupedContentFormFieldsProvider($fieldsGroupsListMock);
$subject = new NonLocalizedGroupedContentFormFieldsProvider($fieldsGroupsListMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This - given it's a separate class - should be in it's own test case/class. Currently you're replacing a test for existing class with this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I will make a new class for tests for the new provider and revert the old test as they were.

@adamwojs adamwojs requested a review from a team February 2, 2025 11:28
@@ -13,6 +13,9 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;

/**
* @deprecated since 4.6.17 this class is deprecated. Please use NonLocalizedGroupedContentFormFieldsProvider instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FQCN could be used here

@Sztig Sztig requested a review from a team February 4, 2025 15:21
@Sztig Sztig requested review from Steveb-p and ViniTou February 19, 2025 13:58
Copy link
Contributor

@Steveb-p Steveb-p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, and I don't feel like pushing more changes into tests is worth it, so I'm refraining from requesting more changes there :)

{
protected FieldsGroupsList $fieldsGroupsList;

protected array $groupContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used in abstract, and can be moved as private property to GroupedContentFormFieldsProvider.

$this->fieldsGroupsList = $fieldsGroupsList;
}

public function getGroupedFields(array $fieldsDataForm): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expect this method to be overloaded by descending classes, so let's block it off immediately.

Suggested change
public function getGroupedFields(array $fieldsDataForm): array
final public function getGroupedFields(array $fieldsDataForm): array

protected function getFieldsGroupsListMock(): FieldsGroupsList
{
$mock = $this->createMock(FieldsGroupsList::class);
$matcher = $this->exactly(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have team preference to call static methods statically only.

Suggested change
$matcher = $this->exactly(3);
$matcher = self::exactly(3);

->getMock();

$formMock
->expects($this->once())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->expects($this->once())
->expects(self::once())

]));

$formMock
->expects($this->once())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->expects($this->once())
->expects(self::once())

return $formMock;
}

protected function getTestForms(): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: can be final.

Suggested change
protected function getTestForms(): array
final protected function getTestForms(): array


use Ibexa\ContentForms\Content\Form\Provider\IdentifiedGroupedContentFormFieldsProvider;

class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest
final class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest


abstract class AbstractGroupedContentFormFieldsProviderTest extends TestCase
{
protected function getFieldsGroupsListMock(): FieldsGroupsList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function getFieldsGroupsListMock(): FieldsGroupsList
final protected function getFieldsGroupsListMock(): FieldsGroupsList

return $mock;
}

protected function getFormMockWithFieldData(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function getFormMockWithFieldData(
final protected function getFormMockWithFieldData(

Copy link

@tomaszszopinski tomaszszopinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA approved on Ibexa DXP 4.6 commerce.

@ViniTou ViniTou merged commit 3edd454 into 4.6 Mar 5, 2025
15 checks passed
@ViniTou ViniTou deleted the IBX-8980-grouped-fields-fix branch March 5, 2025 15:13
@Sztig
Copy link
Contributor Author

Sztig commented Mar 6, 2025

merged up 63d4583

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

Successfully merging this pull request may close these issues.

5 participants