You are here

function patterns_io_get_format_from_file in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/io/ \patterns_io_get_format_from_file()

Extracts and validates the pattern format from a file string

The pattern format can be specified as parameter, and it this case the first parameter will be ignored. The format will be anyway validated.


string $file A path to a file:

string $format Optional. Enforces the format type:

Return value

string|bool $format The pattern format, or FALSE, if the format is invalid

4 calls to patterns_io_get_format_from_file()
drush_patterns_export in ./
Export data from the patterns components to file, zip archive, or database
patterns_drush_get_file_format in ./
patterns_export_start_engine in patterns_export/patterns_export.module
Start the exporting process
patterns_io_import_file in includes/io/


includes/io/, line 79
Importing Patterns from a file or using an URL.


function patterns_io_get_format_from_file($file, $format = PATTERNS_FORMAT_UNKNOWN, $verbose = TRUE) {
  if ($format == PATTERNS_FORMAT_UNKNOWN) {
    $format = pathinfo($file, PATHINFO_EXTENSION);
  if (!patterns_parser_exists($format)) {
    if ($verbose) {
      drupal_set_message(t('Unknown pattern format: %format. Please check available parsers.', array(
        '%format' => $format,
      )), 'error');
    return FALSE;
  return $format;