forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
LeadFieldsType.php
86 lines (77 loc) · 2.5 KB
/
LeadFieldsType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* @copyright 2014 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
namespace Mautic\LeadBundle\Form\Type;
use Mautic\LeadBundle\Model\FieldModel;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class LeadFieldsType.
*/
class LeadFieldsType extends AbstractType
{
/**
* @var FieldModel
*/
protected $fieldModel;
/**
* @param FieldModel $fieldModel
*/
public function __construct(FieldModel $fieldModel)
{
$this->fieldModel = $fieldModel;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
/** @var \Mautic\LeadBundle\Model\FieldModel $model */
$model = $this->fieldModel;
$resolver->setDefaults([
'choices' => function (Options $options) use ($model) {
$fieldList = $model->getFieldList();
if ($options['with_tags']) {
$fieldList['Core']['tags'] = 'mautic.lead.field.tags';
}
if ($options['with_company_fields']) {
$fieldList['Company'] = $model->getFieldList(false, true, ['isPublished' => true, 'object' => 'company']);
}
if ($options['with_utm']) {
$fieldList['UTM']['utm_campaign'] = 'mautic.lead.field.utmcampaign';
$fieldList['UTM']['utm_content'] = 'mautic.lead.field.utmcontent';
$fieldList['UTM']['utm_medium'] = 'mautic.lead.field.utmmedium';
$fieldList['UTM']['utm_source'] = 'mautic.lead.field.umtsource';
$fieldList['UTM']['utm_term'] = 'mautic.lead.field.utmterm';
}
return $fieldList;
},
'global_only' => false,
'required' => false,
'with_company_fields' => false,
'with_tags' => false,
'with_utm' => false,
]);
}
/**
* @return null|string|\Symfony\Component\Form\FormTypeInterface
*/
public function getParent()
{
return 'choice';
}
/**
* @return string
*/
public function getName()
{
return 'leadfields_choices';
}
}