Validating a field value is unique I have a custom field type which I need to be unique. So far I have this:

/**
 * Validates the field values is unique
 *
 * @param mixed $value
 *
 * @return true|string|array
 */
public function validate($value)
{
    $existingEntryCount = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry)-&gt;total(array(
        $this-&gt;model-&gt;getAttribute('handle') =&gt; $value
    ));

    return ($existingEntryCount) ? $this-&gt;model-&gt;getAttribute('name') . Craft::t(' must be unique') : true;
}


This works in that it returns an error if any entry is found with the value submitted, however I need to restrict the search so that it excludes the current entry from the search query.
If anybody is interested, I created a simple unique text field plugin that extends the core text field: https://github.com/fuel-digital/Craft-Unique-Text-FieldType.