|
|
|
@ -102,15 +102,20 @@ class ExtraFieldType extends AbstractType |
|
|
|
if (ExtraField::USER_FIELD_TYPE === $extraFieldType) { |
|
|
|
if (ExtraField::USER_FIELD_TYPE === $extraFieldType) { |
|
|
|
$class = 'select2_user_rel_tag'; |
|
|
|
$class = 'select2_user_rel_tag'; |
|
|
|
$tags = $this->tagRepository->getTagsByUser($extraField, $item); |
|
|
|
$tags = $this->tagRepository->getTagsByUser($extraField, $item); |
|
|
|
|
|
|
|
|
|
|
|
$choices = []; |
|
|
|
$choices = []; |
|
|
|
|
|
|
|
$choicesAttributes = []; |
|
|
|
foreach ($tags as $tag) { |
|
|
|
foreach ($tags as $tag) { |
|
|
|
$stringTag = $tag->getTag(); |
|
|
|
$stringTag = $tag->getTag(); |
|
|
|
if (empty($stringTag)) { |
|
|
|
if (empty($stringTag)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
$choices[$stringTag] = $stringTag; |
|
|
|
$choices[$stringTag] = $stringTag; |
|
|
|
|
|
|
|
$choicesAttributes[$stringTag] = ['data-id' => $tag->getId()]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$defaultOptions['choices'] = $choices; |
|
|
|
$defaultOptions['choices'] = $choices; |
|
|
|
|
|
|
|
$defaultOptions['choice_attr'] = $choicesAttributes; |
|
|
|
$defaultOptions['data'] = $choices; |
|
|
|
$defaultOptions['data'] = $choices; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -200,31 +205,34 @@ class ExtraFieldType extends AbstractType |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*$builder->addEventListener( |
|
|
|
/*$builder->addEventListener( |
|
|
|
FormEvents::PRE_SET_DATA, |
|
|
|
FormEvents::POST_SET_DATA, |
|
|
|
function (FormEvent $event) use ($item, $extraFields): void { |
|
|
|
function (FormEvent $event) use ($item, $extraFields): void { |
|
|
|
$data = $event->getData(); |
|
|
|
$data = $event->getData(); |
|
|
|
foreach ($extraFields as $extraField) { |
|
|
|
foreach ($extraFields as $extraField) { |
|
|
|
$newValue = $data[$extraField->getVariable()] ?? ''; |
|
|
|
$newValue = $data[$extraField->getVariable()] ?? null; |
|
|
|
if (!empty($newValue)) { |
|
|
|
if (!empty($newValue)) { |
|
|
|
if (\ExtraField::FIELD_TYPE_DATE === $extraField->getFieldType()) { |
|
|
|
if (\ExtraField::FIELD_TYPE_TAG === $extraField->getFieldType()) { |
|
|
|
var_dump($newValue); |
|
|
|
$formItem = $event->getForm()->get($extraField->getVariable()); |
|
|
|
exit; |
|
|
|
$formItem->setData($newValue); |
|
|
|
} |
|
|
|
|
|
|
|
if (\ExtraField::FIELD_TYPE_DATETIME === $extraField->getFieldType()) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
);*/ |
|
|
|
);*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$builder->addEventListener( |
|
|
|
$builder->addEventListener( |
|
|
|
FormEvents::PRE_SUBMIT, |
|
|
|
FormEvents::PRE_SUBMIT, |
|
|
|
function (FormEvent $event) use ($item, $extraFields): void { |
|
|
|
function (FormEvent $event) use ($item, $extraFields): void { |
|
|
|
$data = $event->getData(); |
|
|
|
$data = $event->getData(); |
|
|
|
foreach ($extraFields as $extraField) { |
|
|
|
foreach ($extraFields as $extraField) { |
|
|
|
$newValue = $data[$extraField->getVariable()] ?? null; |
|
|
|
$newValue = $data[$extraField->getVariable()] ?? null; |
|
|
|
|
|
|
|
|
|
|
|
if (\ExtraField::FIELD_TYPE_TAG === $extraField->getFieldType()) { |
|
|
|
if (\ExtraField::FIELD_TYPE_TAG === $extraField->getFieldType()) { |
|
|
|
|
|
|
|
$formItem = $event->getForm()->get($extraField->getVariable()); |
|
|
|
|
|
|
|
$options = $formItem->getConfig()->getOptions(); |
|
|
|
|
|
|
|
$options['choices'] = $newValue; |
|
|
|
|
|
|
|
$event->getForm()->add($extraField->getVariable(), ChoiceType::class, $options); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($newValue as $tag) { |
|
|
|
foreach ($newValue as $tag) { |
|
|
|
$this->tagRepository->addTagToUser($extraField, $item, $tag); |
|
|
|
$this->tagRepository->addTagToUser($extraField, $item, $tag); |
|
|
|
} |
|
|
|
} |
|
|
|
|