简体   繁体   English

EntityType 的格式选择 label

[英]Formatting choice label of EntityType

I have a Symfony form that display a list of patients with a checkbox to select each one.我有一个 Symfony 表格,其中显示了一个患者列表,每个患者都有一个 select 复选框。 I'm trying to format the display of the choice_label sent to the form to make it more readable.我正在尝试格式化发送到表单的choice_label 的显示以使其更具可读性。

I've tried several PHP functions and HTML tags in the return statement to try and add formatting or even spaces but was unsuccessful.我在 return 语句中尝试了几个 PHP 函数和 HTML 标记来尝试添加格式甚至空格,但没有成功。

->add('sampleExtractions', EntityType::class, [
                    'class' => SampleExtraction::class,
                    'multiple' => true, 'expanded' => true,
                    'choices' => $this->sampleExtractionRepository->getDNAExtractions(), 'by_reference' => false,
                    'choice_label'=> function(SampleExtraction $sampleExtraction) {
                            $patientName = $sampleExtraction->getPatientSample()->getPatient()->getLastNameFirst();
                            $patientMRN = $sampleExtraction->getPatientSample()->getPatient()->getMRN();
                            $patientDOB = $sampleExtraction->getPatientSample()->getPatient()->getDateOfBirth();
                          return 'Name: ' . $patientName . 'MRN: ' .  $patientMRN .  $patientDOB->format('Y-m-d');                    }
            ])

As you can see I've tried adding details to the return but it all runs together.如您所见,我尝试向退货中添加详细信息,但它们都一起运行。

I would like to be able to format the output to make it more readable for the end user.我希望能够格式化 output 以使其对最终用户更具可读性。

For this you have to create (or update) your form theme, check How to Work with Form Themes > Fragment Naming for Individual Fields .为此,您必须创建(或更新)您的表单主题,检查如何使用表单主题 > 单个字段的片段命名 Check also a good example in Symfony demo application .查看Symfony 演示应用程序中的一个很好的示例。

Here for example这里例如

{% block _YOUR_FORM_TYPE_NAME_ sample_extractions_widget %}
{# your custom HTML here #}
{% endblock %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM