function taxonomy_menu_custom_paths_vocabulary_validate in Taxonomy menu 8
Same name and namespace in other branches
- 7.2 taxonomy_menu_custom_paths/taxonomy_menu_custom_paths.module \taxonomy_menu_custom_paths_vocabulary_validate()
Validation handler for settings of custom path in the taxonomy vocabulary.
We make sure that a base path is provided and paths are registered.
See also
taxonomy_form_vocabulary()
1 string reference to 'taxonomy_menu_custom_paths_vocabulary_validate'
- taxonomy_menu_custom_paths_form_taxonomy_vocabulary_form_alter in taxonomy_menu_custom_paths/
taxonomy_menu_custom_paths.module - Implements hook_form_FORM_ID_alter().
File
- taxonomy_menu_custom_paths/
taxonomy_menu_custom_paths.module, line 63 - Enables custom paths to Taxonomy Menu.
Code
function taxonomy_menu_custom_paths_vocabulary_validate($form, $form_state) {
$options = $form_state['values']['taxonomy_menu'];
$base = $options['options_custom_path']['custom_path_base'];
$depth = $options['options_custom_path']['custom_path_depth'];
// Don't allow base path value to be empty when a custom path is selected.
// Check that the required path are registered in Drupal before processing.
if ($options['path'] == 'taxonomy_menu_path_custom') {
if (empty($base)) {
\Drupal::formBuilder()
->setErrorByName('custom_path_base', $form_state, 'A base path must be provided when using a custom path.');
}
elseif (empty($depth)) {
$path = \Drupal::service('path.alias_manager.cached')
->getSystemPath($base . '/%');
if (!drupal_valid_path($path)) {
\Drupal::formBuilder()
->setErrorByName('custom_path_base', $form_state, 'The path ' . $path . ' is not available in Drupal. This is required to use custom paths.');
}
}
else {
$path = \Drupal::service('path.alias_manager.cached')
->getSystemPath($base . '/%/%');
if (!drupal_valid_path($path)) {
\Drupal::formBuilder()
->setErrorByName('custom_path_depth', $form_state, 'The path ' . $path . ' is not available in Drupal. This is required to use custom paths.');
}
}
}
}