/**
  * beforeValidate callback
  *
  * @param Model $Model Model using this behavior
  * @return boolean False or null will abort the operation. Any other result will continue.
  */
 public function beforeValidate(Model $Model)
 {
     if (isset($Model->data[$Model->alias][self::TAG_FIELD])) {
         $tags = $this->TagCollection->parseTags($Model->data[$Model->alias][self::TAG_FIELD]);
         if (empty($tags)) {
             return true;
         }
         // check number of tags
         if (isset($this->settings[$Model->alias]['maxTags']) && count($tags) > $this->settings[$Model->alias]['maxTags']) {
             $Model->invalidate(self::TAG_FIELD, __('Too many tags. Maximum number of tags: %d', $this->settings[$Model->alias]['maxTags']));
             return false;
         }
         // check length of tags
         foreach ($tags as $tag) {
             $this->Tag->create();
             $this->Tag->set('name', $tag);
             if (!$this->Tag->validates()) {
                 $Model->invalidate(self::TAG_FIELD, __('Invalid tag: %s. Max length: %d', $tag, Tag::NAME_MAX_LENGTH));
                 return false;
             }
         }
     }
     return true;
 }