You are here

function taxonomy_menu_trails_settings_cleanup in Taxonomy Menu Trails 6

Same name and namespace in other branches
  1. 6.x taxonomy_menu_trails.admin.inc \taxonomy_menu_trails_settings_cleanup()
1 string reference to 'taxonomy_menu_trails_settings_cleanup'
taxonomy_menu_trails_settings in ./taxonomy_menu_trails.admin.inc
@file Settings form for taxonomy_menu_trails.

File

./taxonomy_menu_trails.admin.inc, line 91
Settings form for taxonomy_menu_trails.

Code

function taxonomy_menu_trails_settings_cleanup($form, &$state) {

  //cleanup node type settings
  if (is_array($state['values']['taxonomy_menu_trails_node_types'])) {
    foreach ($state['values']['taxonomy_menu_trails_node_types'] as $type => $vocs) {
      $clean_vocs = array_filter($vocs);
      if (empty($clean_vocs)) {
        unset($state['values']['taxonomy_menu_trails_node_types'][$type]);
      }
      else {
        $state['values']['taxonomy_menu_trails_node_types'][$type] = $clean_vocs;
      }
    }
  }

  //prepare regular expressions
  $patterns = preg_split('/\\R/', $state['values']['taxonomy_menu_trails_node_paths_ui'], -1, PREG_SPLIT_NO_EMPTY);
  $exprs = array();
  foreach ($patterns as $pattern) {
    if (preg_match('/^(.*)\\[(nid|title)\\](.*)$/u', $pattern, $m)) {
      foreach (array(
        1,
        3,
      ) as $index) {
        $m[$index] = str_replace(array(
          '\\*',
          '%',
        ), array(
          '.+',
          '[^\\/]+',
        ), preg_quote($m[$index], '/'));
      }
      $placeholder = $m[2];
      switch ($placeholder) {
        case 'nid':
          $m[2] = '(\\d+)';
          break;
        case 'title':
          $m[2] = '([^\\/]+)';
          break;
      }
      $exprs[$placeholder][] = '/^' . implode('', array_slice($m, 1)) . '$/ui';
    }
  }
  $state['values']['taxonomy_menu_trails_node_paths'] = $exprs;
}