This module is similar to a couple of other modules, apart from those listed on this module's page:

http://drupal.org/project/unique_field : This module performs additional validation when a node is created or updated by a user to require that a node's title, author, language, and CCK fields are unique within a given context.

(That module checks on more fields than yours, not least language)

http://drupal.org/project/unique_profile_field : If this option is checked, the module will let users only enter unique values for that field. The check for uniqueness is performed on the registration page (if any profile fields are used on the registration form); and when a user tries to add or update general profile information.

Thought it might be at least something to look into? There also is a 4.7.x module http://drupal.org/project/unique that creates a unique field for products.

Then there is http://drupal.org/project/uniqueness, a module that checks body text for uniqueness, not quite the same, but perhaps a heads up for anyone happening on this module.

Apart from that, I hope that this module will be a wider solution, and thus let me get rid of unique_field. I'd love to see some kind of serial value as well, across entities and/or bundles, to get rid of serial module as well.

Comments

g089h515r806’s picture

If you want make a field unique, you could both use this module and unique_field.
If you want make a title unique, it is better to use unique_field. But this could also be done through Field validation.
For example, you want the article title to be unique. You could do it in this hacking way.
Add php code validator to body field, then add following code

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'article');
$query->propertyCondition('title', $this->entity->title);
$flag = (bool)$query->range(0, 1)->count()->execute();
if($flag){
 form_set_error('title', $this->get_error_message());
}

A little hacking, but it also works. You could use this method validate other property besides uid, language,title.

g089h515r806’s picture

Another way is use title module, then title is field in drupal 7.Title will become field in drupal 8.
Here is another code snippet of using PHP code validator.

if($this->value < 100){
$this->set_error();
}

Also, we could pass some tokens to error message

if($this->value < 100){
$token = array('[test]' => '3.14',);
$this->set_error($token);
}

It is very simple.
we could get current value use
$this->value,
could set error message through
$this->set_error();
Could set token
$this->set_error($token);

We could also call "form_set_error('title', $this->get_error_message());" directly.

Variable we could visit in PHP code:

    $this->entity_type ;
    $this->entity ;
    $this->field;
    $this->instance;
    $this->langcode;
    $this->items ;
    $this->delta;
    $this->item ;
    $this->value ;
    $this->rule ;

For most use case, if we need set an error, just call "$this->set_error();", it will work correctly. If it does not work as your expectation, you could call "form_set_error()" directly.

The code for validate() of PHP code is very simple,

  public function validate() {
    return eval($this->rule->settings['data']);
  }

Developer should set_error by themself.

pkej’s picture

Thank you for answering so fully to what I intended to just point out some similarities and thinking of removing one or two external modules.

I will certainly use your info to the fullest.