Tag normalization is now in the model, this is refelcted elsewhere in code usage
This commit is contained in:
parent
d50e902fb9
commit
50cb351167
4 changed files with 36 additions and 12 deletions
28
app/Tag.php
28
app/Tag.php
|
@ -36,4 +36,32 @@ class Tag extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Normalize tags so they’re lowercase and fancy diatrics are removed.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public function setTagAttribute($value)
|
||||
{
|
||||
$this->attributes['tag'] = $this->normalizeTag($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method actually normalizes a tag. That means lowercase-ing and
|
||||
* removing fancy diatric characters.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public static function normalizeTag($tag)
|
||||
{
|
||||
return mb_strtolower(
|
||||
preg_replace(
|
||||
'/&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/i',
|
||||
'$1',
|
||||
htmlentities($tag)
|
||||
),
|
||||
'UTF-8'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue