Skip to content

Commit

Permalink
Merge pull request #6 from mention-me/feature-support-for-disabled-fi…
Browse files Browse the repository at this point in the history
…elds

Add support for disabled fields
  • Loading branch information
edhgoose authored Oct 29, 2021
2 parents 5509310 + d48b67c commit ec1b781
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/Limenius/Liform/Transformer/AbstractTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,14 @@ protected function isRequired(FormInterface $form)
{
return $form->getConfig()->getOption('required');
}

/**
* @param FormInterface $form
*
* @return boolean
*/
protected function isDisabled(FormInterface $form)
{
return $form->getConfig()->getOption('disabled');
}
}
4 changes: 0 additions & 4 deletions src/Limenius/Liform/Transformer/ArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ public function transform(FormInterface $form, array $extensions = [], $widget =
$transformerData = $this->resolver->resolve($field);
$transformedChild = $transformerData['transformer']->transform($field, $extensions, $transformerData['widget']);
$children[] = $transformedChild;

if ($transformerData['transformer']->isRequired($field)) {
$required[] = $field->getName();
}
}

if (empty($children)) {
Expand Down
11 changes: 7 additions & 4 deletions src/Limenius/Liform/Transformer/CompoundTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function transform(FormInterface $form, array $extensions = [], $widget =
$data = [];
$order = 1;
$required = [];
$disabled = [];

foreach ($form->all() as $name => $field) {
$transformerData = $this->resolver->resolve($field);
Expand All @@ -60,18 +61,20 @@ public function transform(FormInterface $form, array $extensions = [], $widget =
if ($transformerData['transformer']->isRequired($field)) {
$required[] = $field->getName();
}

if ($transformerData['transformer']->isDisabled($field)) {
$disabled[] = $field->getName();
}
}

$schema = [
'title' => $form->getConfig()->getOption('label'),
'type' => 'object',
'properties' => $data,
'required' => $required,
'disabled' => $disabled,
];

if (!empty($required)) {
$schema['required'] = $required;
}

$innerType = $form->getConfig()->getType()->getInnerType();

$schema = $this->addCommonSpecs($form, $schema, $extensions, $widget);
Expand Down

0 comments on commit ec1b781

Please sign in to comment.