# Adding new field to user...

**URL:** <https://forum.mautic.org/t/adding-new-field-to-user/7074>\
**Category:** Development\
**Created:** [January 6, 2017, 6:47pm UTC](https://forum.mautic.org/t/adding-new-field-to-user/7074 "2017-01-06T18:47:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lvocella](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@lvocella](https://forum.mautic.org/u/lvocella)\
**Post date:** [January 6, 2017, 6:47pm UTC](https://forum.mautic.org/t/adding-new-field-to-user/7074/1 "2017-01-06T18:47:17Z")

</div>

Hello,  
  
  
  
I’m trying to add a new field to users. I would like to specify a “pre-filter” that will apply to all queries done by the user. Any suggestion?  
  
  
  
I added the field to the user class but I think this will create some problems in future when I will update mautic…  
  
  
  
thank you for your answer.

---

<div class="post-metadata">

**Author:** ![lvocella](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@lvocella](https://forum.mautic.org/u/lvocella)\
**Post date:** [January 6, 2017, 6:47pm UTC](https://forum.mautic.org/t/adding-new-field-to-user/7074/2 "2017-01-06T18:47:17Z")

</div>

Hello,

I’m trying to add a new field to users. I would like to specify a “pre-filter” that will apply to all queries done by the user. Any suggestion?

I added the field to the user class but I think this will create some problems in future when I will update mautic…

thank you for your answer.

---

<div class="post-metadata">

**Author:** ![lvocella](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@lvocella](https://forum.mautic.org/u/lvocella)\
**Post date:** [January 8, 2017, 1:02pm UTC](https://forum.mautic.org/t/adding-new-field-to-user/7074/3 "2017-01-08T13:02:01Z")

</div>

these are the changes I have done to the userbundle. I tried to extend the bundle creating a custom bundle but nothing. probably I wrong something … Please let me know…

[code]File-\> UserBundleEntityUser.php

row: 134  
/\*\*  
\* @var string  
\*/  
private $prefilter;

row: 216 function: loadMetadata  
$builder-\>createField(‘prefilter’, ‘text’)  
-\>nullable()  
-\>build();

row: 289  
/\*\*  
\* Set prefilter.  
\*  
\* @param string $prefilter  
\*  
\* @return User  
\*/  
public function setPrefilter($prefilter)  
{  
$this-\>isChanged(‘prefilter’, $prefilter);  
$this-\>prefilter = $prefilter;

```
    return $this;
}

/**
 * Get prefilter.
 *
 * @return string
 */
public function getPrefilter()
{
    return $this->prefilter;
}

```

File-\> UserBundleFormTypeUserType.php

row: 250 function: buildForm

$defaultPrefilter = ‘’;  
if (isset($options[‘data’]) && $options[‘data’]-\>getPrefilter() === null) {  
$defaultPrefilter = ‘’;  
} elseif (isset($options[‘data’])) {  
$defaultPrefilter = $options[‘data’]-\>getPrefilter();  
}

```
    $builder->add(
        'prefilter',
        'textarea',
        [
            'label' => 'Prefilter',
            'label_attr' => ['class' => 'control-label'],
            'required' => false,
            'attr' => [
                'class' => 'form-control',
            ],
            'data' => $defaultPrefilter,
        ]
    );

```

File-\>bundles/UserBundle/Views/Profile

row: 69  
echo $view[‘form’]-\>row($userForm[‘prefilter’]);  
[/code]
