Skip to content

Commit

Permalink
ref: simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Dec 12, 2023
1 parent b845a43 commit d006d6d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions EMS/core-bundle/src/Form/DataField/ChoiceFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ChoiceFieldType extends DataFieldType
{
private ?int $fakeIndex = null;
/** @var array<string, string> */
/** @var array<string, string|int> */
private array $choices;

public function getLabel(): string
Expand Down Expand Up @@ -221,8 +221,8 @@ public function viewTransform(DataField $dataField)
}

/**
* @param array<string, mixed> $options
* @return array<string, string>
* @param array<string, mixed> $options
* @return array<string, string|int>
*/
private function buildChoices(array $options): array
{
Expand All @@ -240,11 +240,11 @@ private function buildChoices(array $options): array
}
}

if ($options['linked_collection']) {
if (\is_string($options['linked_collection'] ?? null)) {
$idx = 0;
if (isset($options['raw_data'][$options['linked_collection']]) && \is_array($options['raw_data'][$options['linked_collection']])) {
if (\is_array($options['raw_data'][$options['linked_collection']] ?? null)) {
foreach ($options['raw_data'][$options['linked_collection']] as $idx => $child) {
$choices['#'.$idx.': '.((isset($child[$options['collection_label_field']]) && null !== $child[$options['collection_label_field']]) ? $child[$options['collection_label_field']] : '')] = $idx;
$choices['#'.$idx.': '.((null !== ($child[$options['collection_label_field'] ?? 'label'] ?? null)) ? $child[$options['collection_label_field']] : '')] = $idx;
}
++$idx;
}
Expand Down

0 comments on commit d006d6d

Please sign in to comment.