Skip to content

Commit 01b54e8

Browse files
committed
added included_fields option to AutoFormType
Signed-off-by: David <[email protected]>
1 parent 1d60f84 commit 01b54e8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Form/Manipulator/DoctrineORMManipulator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getFieldsConfig(FormInterface $form): array
3030

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

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

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

9393
$validFields = [];
9494
foreach ($objectFieldsConfig as $fieldName => $fieldConfig) {
95+
if (!\in_array($fieldName, $formIncludedFields, true)) {
96+
continue;
97+
}
9598
if (\in_array($fieldName, $excludedFields, true)) {
9699
continue;
97100
}

src/Form/Type/AutoFormType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function configureOptions(OptionsResolver $resolver): void
3535
$resolver->setDefaults([
3636
'fields' => [],
3737
'excluded_fields' => [],
38+
'included_fields' => [],
3839
]);
3940

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

0 commit comments

Comments
 (0)