public function menu_token_handler::form_validate in Menu Token 7
This function allows your plugin to act upon form validation. The return value will be added to the $options array and thus should be an array itself.
Note: Only invoked for selected plugins.
1 call to menu_token_handler::form_validate()
- menu_token_entity_user_defined::form_validate in plugins/
menu_token_entity_user_defined.inc - This function allows your plugin to act upon form validation. The return value will be added to the $options array and thus should be an array itself.
2 methods override menu_token_handler::form_validate()
- menu_token_entity_user_defined::form_validate in plugins/
menu_token_entity_user_defined.inc - This function allows your plugin to act upon form validation. The return value will be added to the $options array and thus should be an array itself.
- menu_token_panel_context::form_validate in plugins/
menu_token_panel_context.inc - This function allows your plugin to act upon form validation. The return value will be added to the $options array and thus should be an array itself.
File
- handlers/
menu_token_handler.inc, line 30
Class
- menu_token_handler
- The menu token handler class should be extended by all menu token plugins.
Code
public function form_validate($form, &$form_state) {
// Get info.
$entity_type = $form_state['_menu_token_entity_type'];
$token_info = token_get_entity_mapping();
$entity_info = entity_get_info($token_info[$entity_type]);
$entities = array_keys(variable_get('menu_token_entities', drupal_map_assoc(array(
'node',
'user',
))));
// Get link path tokens.
$link_path_tokens = array_keys(token_scan($form_state['values']['options']['menu_token_link_path']));
$link_path_tokens = array_intersect($link_path_tokens, $entities);
// Get link title tokens.
$link_title_tokens = array_keys(token_scan($form_state['values']['link_title']));
$link_title_tokens = array_intersect($link_path_tokens, $entities);
// Set error if no tokens have been detected in either field.
if (!in_array($entity_type, $link_path_tokens) && !in_array($entity_type, $link_title_tokens)) {
form_set_error('menu_token_type_' . $entity_type, t('A method of type %label has been set, but you have not provided a token of type %type in menu link title or path.', array(
'%label' => $entity_info['label'],
'%type' => $entity_type,
)));
form_set_error('link_path');
form_set_error('link_title');
}
}