Created
February 25, 2014 01:50
-
-
Save emmairwin/9201099 to your computer and use it in GitHub Desktop.
Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// This module, taxonomy_menu_patch, should have a dependency of `tm_custom_paths` | |
function taxonomy_menu_patch_module_implements_alter(&$implementations, $hook) { | |
if ('form_taxonomy_form_vocabulary_alter' == $hook) { | |
// We need to ensure that taxonomy_menu_patch is that last one to be called | |
// as this way we can ensure that 'tm_custom_paths_vocabulary_validate' | |
// callback is removed from the $form's #validate callback stack. | |
$group = $implementations['taxonomy_menu_patch']; | |
unset($implementations['taxonomy_menu_patch']); | |
$implementations['taxonomy_menu_patch'] = $group; | |
} | |
} | |
function taxonomy_menu_patch_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { | |
// Should `tm_custom_path`'s implementation exists for vocabulary validate callback, | |
// let's search it to ensure that it exists and remove it. | |
if ($key = array_search('tm_custom_paths_vocabulary_validate', $form['#validate'])) { | |
unset($form['#validate'][$key]); | |
} | |
// let's search it to ensure that it exists and remove it. | |
if ($key = array_search('taxonomy_form_vocabulary_validate', $form['#validate'])) { | |
unset($form['#validate'][$key]); | |
} | |
array_unshift($form['#validate'], 'taxonomy_menu_patch_vocabulary_validate'); | |
} | |
/** | |
* Direct copy of tm_custom_paths_vocabulary_validate with the exception | |
* of the patch https://drupal.org/files/issues/2194077-validating-custom-paths.patch | |
* fix applied directly here by rewriting the $path = drupal_get_normal_path( ... | |
*/ | |
function taxonomy_menu_patch_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)) { | |
form_set_error('custom_path_base', 'A base path must be provided when using a custom path.'); | |
} | |
elseif (empty($depth)) { | |
$path = drupal_get_normal_path($base); | |
if (!_taxonomy_menu_valid_path($path)) { | |
form_set_error('custom_path_base', 'The path ' . $path . ' is not available in Drupales. This is required to use custom paths.'); | |
} | |
} | |
else { | |
$path = drupal_get_normal_path($base . '/%/%'); | |
if (!_taxonomy_menu_valid_path($path)) { | |
form_set_error('custom_path_depth', 'The path ' . $path . ' is not available in Drupal. This is required to use custom paths.'); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment