You are here

function file_style_name_validate in Styles 7

Same name and namespace in other branches
  1. 7.2 contrib/file_styles/file_styles.admin.inc \file_style_name_validate()

Element validate function to ensure unique, URL safe style names.

2 string references to 'file_style_name_validate'
file_style_add_form in contrib/file_styles/file_styles.admin.inc
Form builder; Form for adding a new file style.
file_style_form in contrib/file_styles/file_styles.admin.inc
Form builder; Edit a file style name and effects order.

File

contrib/file_styles/file_styles.admin.inc, line 64
Administrative page callbacks for the File: Styles module.

Code

function file_style_name_validate($element, $form_state) {

  // Check for duplicates.
  $styles = file_styles();
  if (isset($styles[$element['#value']]) && (!isset($form_state['file_style']['msid']) || $styles[$element['#value']]['msid'] != $form_state['file_style']['msid'])) {
    form_set_error($element['#name'], t('The file style name %name is already in use.', array(
      '%name' => $element['#value'],
    )));
  }

  // Check for illegal characters in file style names.
  if (preg_match('/[^0-9a-z_\\-]/', $element['#value'])) {
    form_set_error($element['#name'], t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'));
  }
}