You are here

function patterns_edit_submit in Patterns 5

Same name and namespace in other branches
  1. 6.2 patterns.module \patterns_edit_submit()
  2. 6 patterns.module \patterns_edit_submit()
  3. 7.2 includes/forms/editor.inc \patterns_edit_submit()
  4. 7 includes/forms/editor.inc \patterns_edit_submit()

Submit edits to the pattern

File

./patterns.module, line 451
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_edit_submit($form_id, $form_values) {

  // If this is an enabled pattern, make sure the enabled pattern is saved in its current state
  if ($file = db_result(db_query('SELECT file FROM {patterns} WHERE status = 1 AND name = "%s"', $form_values['name']))) {
    $dir = file_directory_path() . '/' . variable_get('patterns_save_xml', 'patterns') . '/enabled';
    file_check_directory($dir, true);
    $path = $dir . '/' . $form_values['name'] . '.xml';
    if (!file_exists($path)) {
      file_copy($file, $path, FILE_EXISTS_ERROR);
    }
  }

  // Save the new pattern into the pattern files dir.
  $path = file_directory_path() . '/' . variable_get('patterns_save_xml', 'patterns') . '/' . $form_values['name'] . '.xml';
  file_save_data($form_values['xml'], $path, FILE_EXISTS_REPLACE);
  $old = db_result(db_query('SELECT file FROM {patterns} WHERE name = "%s"', $form_values['name']));

  // Load and save pattern
  if ($pattern = patterns_load_xml($path)) {
    if ($old) {
      db_query('UPDATE {patterns} SET file = "%s", updated = "%s" WHERE pid = "%d"', $path, time(), $form_values['pid']);
    }
    patterns_save_pattern($pattern, $path);
  }
  drupal_set_message(t('%name was saved.', array(
    '%name' => $form_values['name'],
  )));
  return 'admin/build/patterns';
}