function pathauto_patterns_validate in Patterns 7.2
Same name and namespace in other branches
- 7 patterns_components/components/pathauto.inc \pathauto_patterns_validate()
File
- patterns_components/
components/ pathauto.inc, line 200
Code
function pathauto_patterns_validate($action, $tag, &$data = NULL) {
$result = array();
$status = PATTERNS_SUCCESS;
$msg = '';
/*
* Syntactic validation
*
*/
switch ($tag) {
case 'pathauto_setting':
switch ($action) {
case PATTERNS_CREATE:
$msg .= t('pathauto_setting could not be created. Only modify action is possible for pathauto_setting.<br>');
return patterns_results(PATTERNS_ERR, $msg);
break;
case PATTERNS_MODIFY:
//No mandatory fields in this case.
//In this case we will need to define as well the attributes generated by the hook_prepare: uid and pass
$interpretable_attributes = array(
'pathauto_verbose',
'pathauto_separator',
'pathauto_case',
'pathauto_max_length',
'pathauto_max_component_length',
'pathauto_update_action',
'pathauto_transliterate',
'pathauto_reduce_ascii',
'pathauto_ignore_words',
);
module_load_include('inc', 'pathauto');
$punctuation = pathauto_punctuation_chars();
foreach ($punctuation as $name => $details) {
$interpretable_attributes[] = 'pathauto_punctuation_' . $name;
}
if (_patterns_has_uninterpretable_attributes($data, $interpretable_attributes, $msg)) {
$status = PATTERNS_WARN;
}
break;
case PATTERNS_DELETE:
//Check mandatory fields, in this case is only one.
$msg .= t('pathauto_setting could not be Deleted. Only modify action is possible for pathauto_setting.<br>');
return patterns_results(PATTERNS_ERR, $msg);
break;
}
break;
/* case 'url_alias':
switch ($action) {
case PATTERNS_CREATE:
//Check mandatory fields, in this case is only one.
$mandatory_attributes = array('source','alias');
if (!_patterns_has_all_mandatory_attributes($data, $mandatory_attributes, $msg)) {
return patterns_results(PATTERNS_ERR, $msg);
}
//In this case we will need to define as well the attributes generated by the hook_prepare: uid and pass
$interpretable_attributes = array('source','alias','language');
if(_patterns_has_uninterpretable_attributes($data, $interpretable_attributes, $msg)) {
$status = PATTERNS_WARN;
}
break;
case PATTERNS_MODIFY:
//Check mandatory fields
$mandatory_attributes = array('source');
if (!_patterns_has_all_mandatory_attributes($data, $mandatory_attributes, $msg)) {
return patterns_results(PATTERNS_ERR, $msg);
}
$interpretable_attributes = array('pid','source','alias','language');
if(_patterns_has_uninterpretable_attributes($data, $interpretable_attributes, $msg)) {
$status = PATTERNS_WARN;
}
break;
case PATTERNS_DELETE:
//Check mandatory fields
$mandatory_attributes = array('pid');
if (!_patterns_has_all_mandatory_attributes($data, $mandatory_attributes, $msg)) {
return patterns_results(PATTERNS_ERR, $msg);
}
//In this case there are not optional attributes, so we can also use this set as interpretable attributes
if(_patterns_has_uninterpretable_attributes($data, $mandatory_attributes, $msg)) {
$status = PATTERNS_WARN;
}
break;
}
break;*/
case 'pathauto_patterns':
switch ($action) {
case PATTERNS_CREATE:
$msg .= t('pathauto_patterns could not be created. Only modify action is possible for pathauto_patterns.<br>');
return patterns_results(PATTERNS_ERR, $msg);
break;
case PATTERNS_MODIFY:
//No mandatory fields in this case.
$interpretable_attributes = array();
$all_settings = module_invoke_all('pathauto', 'settings');
foreach ($all_settings as $settings) {
$module = $settings->module;
$variable = 'pathauto_' . $module . '_pattern';
$interpretable_attributes[] = $variable;
// If the module supports a set of specialized patterns, include them here
if (isset($settings->patternitems)) {
foreach ($settings->patternitems as $itemname => $itemlabel) {
$variable = 'pathauto_' . $module . '_' . $itemname . '_pattern';
$interpretable_attributes[] = $variable;
}
}
}
if (_patterns_has_uninterpretable_attributes($data, $interpretable_attributes, $msg)) {
$status = PATTERNS_WARN;
}
break;
case PATTERNS_DELETE:
//Check mandatory fields, in this case is only one.
$msg .= t('pathauto_patterns could not be Deleted. Only modify action is possible for pathauto_patterns.<br>');
return patterns_results(PATTERNS_ERR, $msg);
break;
}
break;
}
/*
* Semantic validation
*
switch ($tag) {
case 'url_alias':
switch ($action) {
case PATTERNS_CREATE:
//Create semantic warning if the role name has already been defined
if(isset($data['language'])){
$exist= _pathauto_existing_alias_data($data['source'],$data['language']);
}else{
$exist= _pathauto_existing_alias_data($data['source']);
}
if ($exist) {
$result[] = array(PATTERNS_WARNING_ALREADY_DEFINED_ELEMENT =>
t('The url alias for source %source already exists in the system.', array('%source' =>$data['source'])));
}
break;
case PATTERNS_MODIFY:
//Create semantic warning if the rid does not exist
$exist=path_load(array('pid' => $data['pid']));
if (!$exist) {
$result[] = array(PATTERNS_WARNING_ELEMENT_UNDEFINED =>
t('The url alias for source %source dose not exist in the system.', array('%source' =>$data['source'])));
}
break;
case PATTERNS_DELETE:
$exist=path_load(array('pid' => $data['pid']));
if (!$exist ) {
$result[] = array(PATTERNS_WARNING_ELEMENT_UNDEFINED =>
t('The url alias with id %pid dose not exist in the system.', array('%pid' =>$data['pid'])));
}
break;
}
break;
}*/
return patterns_results($status, $msg, $result);
/* $status = PATTERNS_SUCCESS;
$msg = '';
if ($tag == 'url_alias' && ( $action == PATTERNS_MODIFY || $action == PATTERNS_DELETE)) {
if (!isset($data['pid'])) {
$status = PATTERNS_ERR;
$msg = t('Attempt to %update a nonexistent url alias.', array('%update' => $action));
}
else {
$exist = db_query("SELECT COUNT(*) FROM {url_alias} WHERE pid = :pid", array('pid' => $data['pid']))->fetchField(); // TODO: count()
if (!$exist) {
$status = PATTERNS_ERR;
$msg = t('Attempt to %update a nonexistent url alias.', array('%update' => $action));
}
}
}
elseif ($tag == 'url_alias' && $action == PATTERNS_CREATE) {
$lan = isset($data['language']) ? $data['language'] : 'und';
$exist = db_query("SELECT COUNT(*) FROM {url_alias} WHERE alias = :name and language = :lan", array('name' => $data['alias'], 'lan' => $lan))->fetchField(); // TODO: count()
if ($exist) {
$status = PATTERNS_ERR;
$msg = t('The alias %path is already in use in this language.', array('%path' => $data['alias']));
}
}
return patterns_results($status, $msg);*/
}