You are here

function shortcut_patterns_validate in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_components/components/shortcut.inc \shortcut_patterns_validate()

hook_patterns_validate()

File

patterns_components/components/shortcut.inc, line 134
Patterns component for shortcut.

Code

function shortcut_patterns_validate($action, $tag, &$data) {
  $status = PATTERNS_SUCCESS;
  $msg = '';

  //for link's edit and delete.

  //these two form have the third parm:$shortcut_link, follow code provide the parm.
  if ($tag == 'shortcut_link') {
    $set_name = '';
    if ($action == PATTERNS_MODIFY || $action == PATTERNS_DELETE) {
      $set_name = db_select('shortcut_set', 'ss')
        ->fields('ss', array(
        'set_name',
      ))
        ->condition('title', $data['set_name'])
        ->execute()
        ->fetchField();
      if ($set_name == FALSE) {
        $status = PATTERNS_ERR;
        $msg = 'Shortcut Error:there is no such name shortcut set!';
        return patterns_results($status, $msg);
      }
      else {
        $shortcutlink = db_select('menu_links', 'ml')
          ->fields('ml')
          ->condition('menu_name', $set_name)
          ->condition('link_title', $data['link_title'])
          ->execute()
          ->fetchAssoc();

        //follow line is for test

        //drupal_set_message(t('the %acc is %mlid  dfldjdkfdld',array('%acc' =>$shortcutlink['link_title'],'%mlid' => $shortcutlink['mlid'])));
        if ($shortcutlink == FALSE) {
          $status = PATTERNS_ERR;
          $msg = 'Shortcut Error:there is no such name shortcut link!';
          return patterns_results($status, $msg);
        }
        $data['shortcut_link_parm'] = $shortcutlink;
      }
    }
  }

  //for set's edit&delete and link's add and switch user.

  //these three form(switch user just use the $set) have the third parm:$shortcut_set, follow code provide the parm.
  if ($tag == 'shortcut_set' && $action != PATTERNS_CREATE || $tag == 'shortcut_link' && $action == PATTERNS_CREATE || $tag == 'shortcut_set_user') {
    $set = db_select('shortcut_set', 'ss')
      ->fields('ss', array(
      'set_name',
    ))
      ->condition('title', $data['searchtitle'])
      ->execute()
      ->fetchField();
    if ($set == FALSE) {
      $status = PATTERNS_ERR;
      $msg = 'Shortcut Error:there is no such name shortcut set';
      return patterns_results($status, $msg);
    }
    else {
      module_load_include('module', 'shortcut');
      $shortcutsetobj = shortcut_set_load($set);
      $data['shortcut_set_obj'] = $shortcutsetobj;
      if ($tag == 'shortcut_set_user') {
        $data['set'] = $set;
        $data['new'] = $data['name'];
      }
    }
    if ($tag == 'shortcut_set_user') {

      // This form has the third parm: $account, the following code provides it.
      if (isset($data['user'])) {
        module_load_include('module', 'user');
        if (($data['account'] = user_load_by_name($data['user'])) == FALSE) {
          $status = PATTERNS_ERR;
          $msg = 'Shortcut Error:there is no such a user.';
          return patterns_results($status, $msg);
        }
      }
    }
  }
  return patterns_results($status, $msg);
}