function patterns_io_save_pattern in Patterns 7.2
Same name and namespace in other branches
- 7 includes/io/io.inc \patterns_io_save_pattern()
Saves a pattern string or array into the database AND in the file system.
Updates the same file to the newer version, but does not replace an existing file (e.g. if we are moving a file to a new location).
TODO: if content is array and original is null, dump the array into the correct original file
Parameters
mixed $content The content of the pattern to be saved. Can be a string the: or an array represeting the pattern. In the latter case @param $original can be contain the string. If @param $original is missing the pattern is saved as a PHP array.
mixed $name The name of the pattern file.:
mixed $format file format (notice: it is not the extension!): (optional) The format of the pattern. Defaults to PATTERNS_FORMAT_YAML.
mixed $dir the destination directory:
mixed $original the string representation of the pattern. Optional.:
mixed $username (Optional): A name for the author/uploader of the pattern. Defaults, logged user
bool $verbose Optional. If TRUE, a message is displayed with drupal_set_message. : Defaults, TRUE
Return value
bool TRUE on success, FALSE otherwise.
See also
_patterns_io_save_pattern
6 calls to patterns_io_save_pattern()
- patterns_d2d_push_patterns_server in patterns_d2d/
includes/ patterns_d2d.srpc.inc - patterns_edit_submit in includes/
forms/ editor.inc - Form submission handler for patterns_edit_form().
- patterns_export_to_db in patterns_export/
finalize.inc - Exports a pattern by importing it into the database
- patterns_import_submit in includes/
forms/ import.inc - patterns_io_import_file in includes/
io/ import.inc
File
- includes/
io/ io.inc, line 470 - Functions related to input/output operations.
Code
function patterns_io_save_pattern($content = NULL, $name = NULL, $format = PATTERNS_FORMAT_YAML, $dir = NULL, $original = NULL, $username = NULL, $verbose = TRUE) {
if (is_null($username)) {
global $user;
$username = $user->name;
}
$result = _patterns_io_save_pattern($content, $name, $format, $dir, $original, $username);
if ($verbose && !empty($result['msg'])) {
$status = $result['status'] == PATTERNS_SUCCESS ? 'status' : 'error';
drupal_set_message($result['msg'], $status);
}
return $result['status'] == PATTERNS_SUCCESS ? TRUE : FALSE;
}