Skip to content

Commit

Permalink
implemented new provider with correct implementation of the interface…
Browse files Browse the repository at this point in the history
… to avoid BC break
  • Loading branch information
Sztig committed Jan 20, 2025
1 parent 1f6fdd0 commit d53ab22
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ services:
Ibexa\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProvider:
arguments:
$fieldsGroupsList: '@Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList'

Ibexa\ContentForms\Content\Form\Provider\NonLocalizedGroupedContentFormFieldsProvider:
arguments:
$fieldsGroupsList: '@Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList'
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\ContentForms\Content\Form\Provider;

use Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface;
use Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;

class NonLocalizedGroupedContentFormFieldsProvider implements GroupedContentFormFieldsProviderInterface, TranslationContainerInterface
{
/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */
private $fieldsGroupsList;

public function __construct(FieldsGroupsList $fieldsGroupsList)
{
$this->fieldsGroupsList = $fieldsGroupsList;
}

public function getGroupedFields(array $fieldsDataForm): array
{
$groupedFields = [];

foreach ($fieldsDataForm as $fieldForm) {
/** @var \Ibexa\Contracts\ContentForms\Data\Content\FieldData $fieldData */
$fieldData = $fieldForm->getViewData();
$fieldGroupIdentifier = $this->fieldsGroupsList->getFieldGroup($fieldData->fieldDefinition);
$groupedFields[$fieldGroupIdentifier][] = $fieldForm->getName();
}

return $groupedFields;
}

public static function getTranslationMessages(): array
{
return [
Message::create('content', 'ibexa_fields_groups')->setDesc('Content'),
Message::create('metadata', 'ibexa_fields_groups')->setDesc('Metadata'),
];
}
}

0 comments on commit d53ab22

Please sign in to comment.