-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathitem.json
More file actions
6 lines (6 loc) · 1.67 KB
/
item.json
File metadata and controls
6 lines (6 loc) · 1.67 KB
1
2
3
4
5
6
{
"name": "guid",
"short_description": "Globally Unique Identifier",
"inherit": "0",
"php": "\t\/**\r\n\t * Method to test for a Globally Unique Identifier.\r\n\t *\r\n\t * @param \\SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.\r\n\t * @param mixed $value The form field value to validate.\r\n\t * @param string $group The field name group control value. This acts as an array container for the field.\r\n\t * For example if the field has name=\"foo\" and the group value is set to \"bar\" then the\r\n\t * full field name would end up being \"bar[foo]\".\r\n\t * @param Registry $input An optional Registry object with the entire data set to validate against the entire form.\r\n\t * @param Form $form The form object for which the field is being tested.\r\n\t *\r\n\t * @return boolean True if the value is valid, false otherwise.\r\n\t *\r\n\t *\/\r\n\tpublic function test(\\SimpleXMLElement $element, $value, $group = null, ?Registry $input = null, ?Form $form = null)\r\n\t{\r\n\t\t$value = trim($value);\r\n\r\n\t\t\/\/ If the field is empty and not required, the field is valid.\r\n\t\t$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');\r\n\r\n\t\tif (!$required && empty($value))\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t\/\/ thanks to Lewie https:\/\/stackoverflow.com\/a\/1515456\/1429677\r\n\t\treturn preg_match(\"\/^(\\{)?[a-f\\d]{8}(-[a-f\\d]{4}){4}[a-f\\d]{8}(?(1)\\})$\/i\", $value);\r\n\t}\r\n"
}