File size: 829 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

namespace Mautic\LeadBundle\Model;

use Mautic\LeadBundle\Entity\CustomFieldEntityInterface;

trait DefaultValueTrait
{
    /**
     * @param string $object
     */
    protected function setEntityDefaultValues(CustomFieldEntityInterface $entity, $object = 'lead')
    {
        if (!$entity->getId()) {
            $fields = $this->leadFieldModel->getFieldListWithProperties($object);
            foreach ($fields as $alias => $field) {
                // Prevent defaults from overwriting values already set
                $value = $entity->getFieldValue($alias);

                if ((null === $value || '' === $value) && '' !== $field['defaultValue'] && null !== $field['defaultValue']) {
                    $entity->addUpdatedField($alias, $field['defaultValue']);
                }
            }
        }
    }
}