-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
|
$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(); |
There was a problem hiding this comment.
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
There was a problem hiding this 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).
- https://github.com/ibexa/admin-ui/blob/4.6/src/bundle/Resources/views/themes/admin/content/edit_base.html.twig#L52
- https://github.com/ibexa/product-catalog/blob/4.6/src/bundle/Resources/views/themes/admin/product_catalog/product/create.html.twig#L77
Instead of the human-readable name identifier will be displayed
Alright, I will try then implementing a new provider and update the templates in |
81aef34
to
d53ab22
Compare
/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */ | ||
private $fieldsGroupsList; |
There was a problem hiding this comment.
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.
/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */ | |
private $fieldsGroupsList; | |
private FieldsGroupsList $fieldsGroupsList; |
]); | ||
|
||
$subject = new GroupedContentFormFieldsProvider($fieldsGroupsListMock); | ||
$subject = new NonLocalizedGroupedContentFormFieldsProvider($fieldsGroupsListMock); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
$matcher = $this->exactly(3); | |
$matcher = self::exactly(3); |
->getMock(); | ||
|
||
$formMock | ||
->expects($this->once()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->expects($this->once()) | |
->expects(self::once()) |
])); | ||
|
||
$formMock | ||
->expects($this->once()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->expects($this->once()) | |
->expects(self::once()) |
return $formMock; | ||
} | ||
|
||
protected function getTestForms(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: can be final.
protected function getTestForms(): array | |
final protected function getTestForms(): array |
|
||
use Ibexa\ContentForms\Content\Form\Provider\IdentifiedGroupedContentFormFieldsProvider; | ||
|
||
class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest | |
final class IdentifiedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest |
|
||
abstract class AbstractGroupedContentFormFieldsProviderTest extends TestCase | ||
{ | ||
protected function getFieldsGroupsListMock(): FieldsGroupsList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function getFieldsGroupsListMock(): FieldsGroupsList | |
final protected function getFieldsGroupsListMock(): FieldsGroupsList |
return $mock; | ||
} | ||
|
||
protected function getFormMockWithFieldData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function getFormMockWithFieldData( | |
final protected function getFormMockWithFieldData( |
|
There was a problem hiding this 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.
merged up 63d4583 |
Related PRs:
Description:
Based on the interface of
GroupedContentFormFieldsProvider
the methodgetGroupedFields
is implemented incorrectly. The description of the interface statesArray of fieldGroupIdentifier grouped by fieldGroupName
should be returned. Right now it doesn't return thefieldGroupIdentifier
but a translation of said identifier.For the example the previously retrieved key would be
Basic Information
, after the fix it's going to bebasic_information