Skip to content

Commit

Permalink
added included_fields option to AutoFormType
Browse files Browse the repository at this point in the history
  • Loading branch information
nexxome committed Jun 5, 2024
1 parent 1d60f84 commit 20d67b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Form/Manipulator/DoctrineORMManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getFieldsConfig(FormInterface $form): array

// Filtering to remove excludedFields
$objectFieldsConfig = $this->doctrineORMInfo->getFieldsConfig($class);
$validObjectFieldsConfig = $this->filteringValidObjectFields($objectFieldsConfig, $formOptions['excluded_fields']);
$validObjectFieldsConfig = $this->filteringValidObjectFields($objectFieldsConfig, $formOptions['excluded_fields'], $formOptions['included_fields']);

if (empty($formOptions['fields'])) {
return $validObjectFieldsConfig;
Expand Down Expand Up @@ -86,12 +86,15 @@ private function getDataClass(FormInterface $form): string
throw new \RuntimeException('Unable to get dataClass');
}

private function filteringValidObjectFields(array $objectFieldsConfig, array $formExcludedFields): array
private function filteringValidObjectFields(array $objectFieldsConfig, array $formExcludedFields, array $formIncludedFields): array
{
$excludedFields = array_merge($this->globalExcludedFields, $formExcludedFields);

$validFields = [];
foreach ($objectFieldsConfig as $fieldName => $fieldConfig) {
if (!empty($formIncludedFields) && !\in_array($fieldName, $formIncludedFields, true)) {
continue;
}
if (\in_array($fieldName, $excludedFields, true)) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/Form/Type/AutoFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setDefaults([
'fields' => [],
'excluded_fields' => [],
'included_fields' => [],
]);

$resolver->setNormalizer('data_class', static function (Options $options, $value): string {
Expand Down

0 comments on commit 20d67b3

Please sign in to comment.