-
Notifications
You must be signed in to change notification settings - Fork 1
/
wet_sample_article_constraints.php
40 lines (35 loc) · 1.15 KB
/
wet_sample_article_constraints.php
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
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class wet_sample_article_constraints
{
function __construct()
{
register_callback(__CLASS__.'_ignore_status', 'article_ui', 'validate_publish');
register_callback(__CLASS__.'_min_title_length', 'article_ui', 'validate_publish');
register_callback(__CLASS__.'_ignore_status', 'article_ui', 'validate_save');
register_callback(__CLASS__.'_min_title_length', 'article_ui', 'validate_save');
}
}
/**
* Constrain minimum title length
*/
class wet_LengthConstraint extends Constraint
{
function validate()
{
return mb_strlen($this->value) >= $this->options['min'];
}
}
/**
* Establish custom constraints
*/
function wet_sample_article_constraints_ignore_status($event, $step, &$rs, &$constraints)
{
// release constraints on allowed status values
unset($constraints['Status']);
}
function wet_sample_article_constraints_min_title_length($event, $step, &$rs, &$constraints)
{
// Add a custom constraint to enforce a title length of 5 characters or more
$constraints['wet_titlelength'] = new wet_LengthConstraint($rs['Title'], array('min' => 5, 'message' => 'title_too_short'));
}
if (txpinterface == 'admin') new wet_sample_article_constraints;