You are here

function config_perms_admin_form_validate in Custom Permissions 7.2

Same name and namespace in other branches
  1. 6.2 config_perms.admin.inc \config_perms_admin_form_validate()

Validate handler.

File

./config_perms.admin.inc, line 156
Admin pages

Code

function config_perms_admin_form_validate($form, &$form_state) {
  $values = $form_state['values'];
  $perms = config_perms_perms();
  foreach ($values['local'] as $key => $perm) {
    $perm = (object) $perm;
    if (empty($perm->name) && empty($perm->path)) {
      unset($form_state['values']['local'][$key]);
      continue;
    }
    if (empty($perm->name)) {
      form_set_error("local][" . $key . "", t("The name cannot be empty."));
    }
    if (empty($perm->path)) {
      form_set_error("local][" . $key . "", t("The path cannot be empty."));
    }
    elseif (!$perm->remove) {
      foreach (config_perms_parse_path($perm->path) as $path) {
        $item = menu_get_item($path);
        if ($item && $item['path'] != $item['href']) {
          form_set_error("local][" . $key . "", t('The path %path is a dynamic path which cannot be protected by custom permissions. You can use a wildcard path like %wildcard to protect all paths of this type.', array(
            '%path' => $path,
            '%wildcard' => preg_replace('#(^|/)%($|/)#', '${1}*${2}', $item['path']),
          )));
        }
      }
    }
    if (array_key_exists(config_perms_generate_machine_name($perm->name), $perms) && !isset($perm->pid)) {
      form_set_error("local][" . $key . "", t("A permission with that name already exists."));
    }
  }
}