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

Added included_fields option to AutoFormType #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DependencyInjection/A2lixAutoFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class A2lixAutoFormExtension extends Extension
{
Expand Down
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
Loading