<p>I wrote a simple fieldtype that checks that the field value is unique for a specific entry type: <a href="https://github.com/fuel-digital/Craft-Unique-Text-FieldType" rel="nofollow">https://github.com/fuel-digital/Craft-Unique-Text-FieldType</a></p>

<p>This worked fine initially but after the recent core updates, $this->element in the valueExists() method is null on new entries, where previously it was an instance of ElementType::Entry or whatever else the field was attached to.</p>

<p>While I could instantiate a new ElementType::Entry object if one doesn't exist, this limits the field's use to Entries, and not Assets, Users etc.</p>

<p>Is there some other way of getting the element's value now? I can't see anything when inspecting the field class.</p>

CC BY-SA 3.0
2015-01-06T19:32:50.533Z
`$this->element` won't necessarily be set depending on the context your field type is used in, so your field type needs to be aware of that. That's always been the case, too, so I doubt a recent update changed anything related to that.
Brad Bell
CC BY-SA 3.0
2015-01-06T21:08:37.453Z
Weird, as it was fine in testing until recently. Any suggestions on how I can achieve what I'm looking to do?
Russ Back
<plugin-development><entry-type>
Can no longer get the ElementType a field is attached to
# Can no longer get the ElementType a field is attached to

(Asked by: username_0 on 2015-01-05)

I wrote a simple fieldtype that checks that the field value is unique for a specific entry type: <https://github.com/fuel-digital/Craft-Unique-Text-FieldType>

This worked fine initially but after the recent core updates, $this->element in the valueExists() method is null on new entries, where previously it was an instance of ElementType::Entry or whatever else the field was attached to.

While I could instantiate a new ElementType::Entry object if one doesn't exist, this limits the field's use to Entries, and not Assets, Users etc.

Is there some other way of getting the element's value now? I can't see anything when inspecting the field class.

**Tags:** plugin-development, entry-type
> **Comments:**
> **username_1**: `$this->element` won't necessarily be set depending on the context your field type is used in, so your field type needs to be aware of that. That's always been the case, too, so I doubt a recent update changed anything related to that.  
> **username_0**: Weird, as it was fine in testing until recently. Any suggestions on how I can achieve what I'm looking to do?  

---

## 0 answers

