Permalink
Browse files

A cleanup over many files.

  • Loading branch information...
1 parent 93fd2ff commit e4f76c023de7a30edc48f17e50e7c033262f0177 @csko csko committed Apr 23, 2012
Showing with 2,244 additions and 2,244 deletions.
  1. +100 −100 includes/api/api.inc
  2. +40 −40 includes/api/drush.inc
  3. +18 −18 includes/config.inc
  4. +5 −6 includes/core/batch.inc
  5. +9 −9 includes/db.inc
  6. +1 −1 includes/forms/editor.inc
  7. +318 −322 includes/forms/export.inc
  8. +395 −395 includes/forms/export.old.inc
  9. +69 −70 includes/forms/first_install.inc
  10. +64 −64 includes/forms/forms.inc
  11. +37 −38 includes/forms/import.inc
  12. +50 −50 includes/forms/info.inc
  13. +28 −28 includes/forms/lab.inc
  14. +1 −1 includes/forms/quickrun.inc
  15. +83 −85 includes/io.inc
  16. +46 −46 includes/parser/parser.inc
  17. +110 −110 includes/parser/scan.inc
  18. +13 −13 includes/servers.inc
  19. +91 −91 includes/tagmodules.inc
  20. +24 −24 includes/utils.inc
  21. +1 −1 patterns.install
  22. +27 −27 patterns.module
  23. +24 −24 patterns_components/components/color.inc
  24. +67 −66 patterns_components/components/field.inc
  25. +50 −50 patterns_components/components/menu.inc
  26. +12 −12 patterns_components/components/node.inc
  27. +30 −29 patterns_components/components/pathauto.inc
  28. +6 −6 patterns_components/components/shortcut.inc
  29. +24 −24 patterns_components/components/system.inc
  30. +36 −36 patterns_components/components/taxonomy.inc
  31. +8 −8 patterns_components/components/toolbar.inc
  32. +15 −15 patterns_components/components/user.inc
  33. +3 −3 patterns_d2d/includes/patterns_d2d.form.inc
  34. +2 −2 patterns_d2d/includes/patterns_d2d.srpc.inc
  35. +2 −2 patterns_d2d/patterns_d2d.install
  36. +10 −10 tests/block/block.test
  37. +9 −9 tests/color/color.test
  38. +15 −15 tests/field/field.test
  39. +12 −12 tests/general/general.test
  40. +10 −10 tests/importing/importing.test
  41. +8 −8 tests/menu/menu.test
  42. +7 −7 tests/node/content.test
  43. +8 −8 tests/node/node.test
  44. +7 −7 tests/parser/parser.test
  45. +14 −14 tests/pathauto/pathauto.test
  46. +90 −86 tests/patterns.test
  47. +75 −75 tests/shortcut/shortcut.test
  48. +9 −9 tests/system/system.test
  49. +12 −12 tests/taxonomy/taxonomy.test
  50. +8 −8 tests/toolbar/toolbar.test
  51. +9 −9 tests/user/user.test
  52. +72 −72 theme/common.inc
  53. +14 −11 theme/modules.inc
  54. +46 −46 theme/theme.inc
View
200 includes/api/api.inc
@@ -10,81 +10,81 @@
/**
* Returns an array containing all the reserved words
* for a Patterns.
- *
+ *
* Such words are not allowed to be used as a section heading.
- *
+ *
* @return Array
* The array of reserved words.
*/
function patterns_api_reserved_words() {
- return array(
- PATTERNS_TAG,
- PATTERNS_SECTION_INFO,
- PATTERNS_SECTION_MODULES,
- PATTERNS_CREATE,
- PATTERNS_MODIFY,
- PATTERNS_DELETE,
- PATTERNS_INCLUDE,
- );
+ return array(
+ PATTERNS_TAG,
+ PATTERNS_SECTION_INFO,
+ PATTERNS_SECTION_MODULES,
+ PATTERNS_CREATE,
+ PATTERNS_MODIFY,
+ PATTERNS_DELETE,
+ PATTERNS_INCLUDE,
+ );
}
/**
* Tells whether a string is a Patterns reserved word
- *
+ *
* @param mixed $word
- * The string to check.
- *
+ * The string to check.
+ *
* @return Boolean,
* TRUE, if it is a reserved word
*/
function patterns_api_is_reserved_word($word = NULL) {
- if (is_null($word)) return FALSE;
- return (in_array($word, patterns_api_reserved_words())) ? TRUE
- : FALSE;
+ if (is_null($word)) return FALSE;
+ return (in_array($word, patterns_api_reserved_words())) ? TRUE
+ : FALSE;
}
/**
* Checks whether a string is a valid component name.
- *
- * @param mixed $component
- * The string with the name of the component
- *
- * @return Boolean
- * TRUE, if the string is a valid component name
- *
- * @see patterns_api_build_moduletags_index
+ *
+ * @param mixed $component
+ * The string with the name of the component
+ *
+ * @return Boolean
+ * TRUE, if the string is a valid component name
+ *
+ * @see patterns_api_build_moduletags_index()
*/
function patterns_api_is_valid_component_name($component = NULL) {
- if (is_null($component)) return FALSE;
- $idx = patterns_moduletags_get_index();
- return (isset($idx[$component])) ? TRUE : FALSE;
+ if (is_null($component)) return FALSE;
+ $idx = patterns_moduletags_get_index();
+ return (isset($idx[$component])) ? TRUE : FALSE;
}
/**
- * Adds / Replaces an Info section to a pattern.
- *
+ * Adds / Replaces an Info section to a pattern.
+ *
* Missing properties are options are automatically filled in with
* standard values.
- *
+ *
* @param array $info (optional)
- * An associative array of properties for the info section.
+ * An associative array of properties for the info section.
* @param array $pattern (optional)
* An array representing a pattern file.
* @param Bool $ow (optional)
* If TRUE, overwrites existing Info sections.
*/
function patterns_api_add_info_section($info = array(), &$pattern = array(), $ow = FALSE) {
- if (isset($pattern[PATTERNS_SECTION_INFO]) && !$ow) return FALSE;
-
+ if (isset($pattern[PATTERNS_SECTION_INFO]) && !$ow) return FALSE;
+
global $user;
global $base_root;
-
+
$pattern[PATTERNS_SECTION_INFO] = array();
$pattern[PATTERNS_SECTION_INFO]['title'] = (isset($info['title'])) ? $info['title'] : 'Untitled Pattern';
$pattern[PATTERNS_SECTION_INFO]['category'] = (isset($info['category'])) ? $info['category'] : 'General';
$pattern[PATTERNS_SECTION_INFO]['description'] = (isset($info['description'])) ? $info['description'] : 'No description';
- $pattern[PATTERNS_SECTION_INFO]['version'] = (isset($info['version'])) ? $info['version'] : '1.0';
+ $pattern[PATTERNS_SECTION_INFO]['version'] = (isset($info['version'])) ? $info['version'] : '1.0';
$pattern[PATTERNS_SECTION_INFO]['core'] = (isset($info['core'])) ? $info['core'] : 'x.y';
$pattern[PATTERNS_SECTION_INFO]['author'] = (isset($info['author'])) ? $info['author'] : $user->name;
$pattern[PATTERNS_SECTION_INFO]['author_email'] = (isset($info['author_email'])) ? $info['author_email'] : $user->mail;
@@ -95,49 +95,49 @@ function patterns_api_add_info_section($info = array(), &$pattern = array(), $ow
/**
* Adds / Replaces an Info section to a pattern.
- *
+ *
* Removes duplicates from the list of modules.
- *
+ *
* @param array $modules
- * Array containing the name of the modules
+ * Array containing the name of the modules
* @param array $pattern (optional)
* The associative array representing a pattern
* @param Bool $ow (optional)
- * If TRUE, a pre-existing modules section will be
- * overwritten. Defaults FALSE.
- *
- * @return Bool|Array Return the array containing the
- * the modules section, or FALSE if an error occurred
+ * If TRUE, a pre-existing modules section will be
+ * overwritten. Defaults FALSE.
+ *
+ * @return Bool|Array Return the array containing the
+ * the modules section, or FALSE if an error occurred
*/
function patterns_api_add_modules_section($modules = NULL, &$pattern = array(), $ow = FALSE) {
- if (is_null($modules)) return FALSE;
- if (isset($pattern['modules']) && !$ow) return FALSE;
- $modules = (is_array($modules)) ? $modules : array($modules);
- $pattern['modules'] = array_unique($modules);
- return $pattern;
+ if (is_null($modules)) return FALSE;
+ if (isset($pattern['modules']) && !$ow) return FALSE;
+ $modules = (is_array($modules)) ? $modules : array($modules);
+ $pattern['modules'] = array_unique($modules);
+ return $pattern;
}
/**
* Initializes an empty section in a pattern file.
- *
+ *
* Checks whether the section name is valid before adding it.
- *
+ *
* @param mixed $section
- * A string representing the pattern name
+ * A string representing the pattern name
* @param array $pattern (optional)
* The associative array representing a pattern
* @param Bool $ow (optional)
- * If TRUE, an existing section with the same name will be
- * overwritten. Defaults FALSE.
+ * If TRUE, an existing section with the same name will be
+ * overwritten. Defaults FALSE.
*/
function patterns_api_add_section($section = NULL, &$pattern = array(), $ow = FALSE) {
- if (is_null($section)) return FALSE;
- if (patterns_api_is_reserved_word($section)) return FALSE;
- if (isset($pattern[$section]) && !$ow) return FALSE;
-
- $pattern[$section] = array();
- return $pattern;
+ if (is_null($section)) return FALSE;
+ if (patterns_api_is_reserved_word($section)) return FALSE;
+ if (isset($pattern[$section]) && !$ow) return FALSE;
+
+ $pattern[$section] = array();
+ return $pattern;
}
/**
@@ -149,60 +149,60 @@ function patterns_api_add_section($section = NULL, &$pattern = array(), $ow = FA
*/
function patterns_api_extract_actions($form, $args = array(), $tag = NULL, $action = PATTERNS_MODIFY) {
-
- set_error_handler("patterns_import_module_error_handler", E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
- // Move this inside the Macro module
- // Macro should check that only one user is using that
- $form_state = array();
- $form_state['values'] = array();
- variable_set('patterns_extract_actions', TRUE);
- variable_set('macro_enabled', TRUE);
- variable_set('macro_submissions', array());
- $args = (!is_array($args)) ? array($args) : $args;
-
- $form_state['build_info']['args'] = $args;
- drupal_form_submit($form, $form_state);
-
- $result = macro_get_macro();
-
- variable_set('macro_enabled', FALSE);
- variable_set('patterns_extract_actions', FALSE);
-
- if (!empty($result) || !is_null($tag)){
- $out = array();
- foreach ($result as $entry) {
- $a = $entry['values'];
- $out[] = array ($action => array_merge(array('tag' => $tag), $a));
- }
- $result = $out;
- }
-
- return $result;
+
+ set_error_handler("patterns_import_module_error_handler", E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
+ // Move this inside the Macro module
+ // Macro should check that only one user is using that
+ $form_state = array();
+ $form_state['values'] = array();
+ variable_set('patterns_extract_actions', TRUE);
+ variable_set('macro_enabled', TRUE);
+ variable_set('macro_submissions', array());
+ $args = (!is_array($args)) ? array($args) : $args;
+
+ $form_state['build_info']['args'] = $args;
+ drupal_form_submit($form, $form_state);
+
+ $result = macro_get_macro();
+
+ variable_set('macro_enabled', FALSE);
+ variable_set('patterns_extract_actions', FALSE);
+
+ if (!empty($result) || !is_null($tag)) {
+ $out = array();
+ foreach ($result as $entry) {
+ $a = $entry['values'];
+ $out[] = array($action => array_merge(array('tag' => $tag), $a));
+ }
+ $result = $out;
+ }
+
+ return $result;
}
/**
- * Implementation of hook_form_alter().
+ * Implements of hook_form_alter().
* needed for deactivating actual submission of the forms when submitting, i.e.
* we only want to know what gets submitted without the submission getting
* processed
*/
function patterns_form_alter(&$form, $form_state, $form_id) {
// Add the record callback on submit and delete all others
if ($form_id != 'macro_import_macro' && variable_get('macro_enabled', FALSE) && variable_get('patterns_extract_actions', FALSE)) {
- $form['#submit'] = array();
- $form['#submit'][] = 'macro_record_macro';
+ $form['#submit'] = array();
+ $form['#submit'][] = 'macro_record_macro';
}
}
/**
- * in case error happens and script gets halted
+ * In case error happens and script gets halted.
*/
function patterns_import_module_error_handler($errno, $errstr) {
variable_set('macro_enabled', FALSE);
variable_set('macro_submissions', array());
variable_set('patterns_extract_actions', FALSE);
restore_error_handler();
- // normal error handler should take over from here
+ // Normal error handler should take over from here.
return FALSE;
}
@@ -250,9 +250,9 @@ function _patterns_is_patterns_results($results) {
* @return array Allowed actions.
*/
function patterns_actions() {
- return array(PATTERNS_CREATE => PATTERNS_CREATE,
- PATTERNS_MODIFY => PATTERNS_MODIFY,
- PATTERNS_DELETE => PATTERNS_DELETE,
- PATTERNS_INCLUDE => PATTERNS_INCLUDE,
- );
-}
+ return array( PATTERNS_CREATE => PATTERNS_CREATE,
+ PATTERNS_MODIFY => PATTERNS_MODIFY,
+ PATTERNS_DELETE => PATTERNS_DELETE,
+ PATTERNS_INCLUDE => PATTERNS_INCLUDE,
+ );
+}
View
80 includes/api/drush.inc
@@ -3,23 +3,23 @@
module_load_include('inc', 'api');
function patterns_menu_alter(&$items) {
-
+
$items['admin/patterns/drush/enable/%'] = array(
'title' => 'Enable Modules',
'page callback' => 'patterns_drush_enable_modules_service',
'page arguments' => array(4),
'access arguments' => array('administer patterns'),
'type' => MENU_CALLBACK
);
-
+
$items['admin/patterns/drush/download/%'] = array(
'title' => 'Enable Modules',
'page callback' => 'patterns_drush_download_modules_service',
'page arguments' => array(4),
'access arguments' => array('administer patterns'),
'type' => MENU_CALLBACK
);
-
+
$items['admin/patterns/drush/dlenable/%'] = array(
'title' => 'Download and Enable Modules',
'page callback' => 'patterns_drush_dlenable_modules_service',
@@ -36,22 +36,22 @@ function patterns_menu_alter(&$items) {
*/
function patterns_drush_download_modules_service($module, $raw = FALSE) {
$out = patterns_drush_download_modules(array($module));
-
+
$status = $out['status'];
if ($status == PATTERNS_SUCCESS) {
- drupal_set_message("Drush download ran without errors. Check the output if no problems occured.");
+ drupal_set_message(t('Drush download ran without errors. Check the output if no problems occured.'));
}
else {
- drupal_set_message("An error occured in drush download: drush returned return code ". $out['result'] .'. See drush output', 'error');
+ drupal_set_message(t('An error occured in drush download: drush returned return code ' . $out['result'] . '. See drush output'), 'error'); // TODO: proper t()
}
-
- $form['patterns']['drush']['download'] = array (
+
+ $form['patterns']['drush']['download'] = array(
'#title' => 'Download:',
'#prefix' => '<div>',
'#suffix' => '</div><br/>',
- '#markup' => t(implode('<br>', $out['msg'])),
+ '#markup' => t(implode('<br/>', $out['msg'])),
);
-
+
return !$raw ? drupal_render($form) : $form;
}
@@ -65,17 +65,17 @@ function patterns_drush_enable_modules_service($module, $raw = FALSE) {
$out = patterns_drush_enable_modules(array($module), $dep);
$status = $out['status'];
if ($status == PATTERNS_SUCCESS) {
- drupal_set_message("Drush enable ran without errors. Check the output if no problems occured.");
+ drupal_set_message(t('Drush enable ran without errors. Check the output if no problems occured.'));
}
else {
- drupal_set_message("An error occured in drush enable: drush returned return code ". $out['result'] .'. See drush output', 'error');
+ drupal_set_message(t('An error occured in drush enable: drush returned return code ' . $out['result'] . '. See drush output'), 'error'); // TODO: proper t()
}
-
- $form['patterns']['drush']['enable'] = array (
+
+ $form['patterns']['drush']['enable'] = array(
'#title' => 'Enable:',
'#prefix' => '<div>',
'#suffix' => '</div><br/>',
- '#markup' => t(implode('<br>', $out['msg'])),
+ '#markup' => t(implode('<br/>', $out['msg'])),
);
return !$raw ? drupal_render($form) : $form;
}
@@ -99,18 +99,18 @@ function patterns_drush_dlenable_modules_service($module) {
*/
function patterns_drush_download_modules($modules) {
if (!patterns_drush_ready()) {
- return array('Drush path wasn\'t set');
+ return array('Drush path wasn\'t set');
}
-
+
$output = array('Drush download output: ');
$cmd = variable_get('patterns_drush_path');
- $cmd .= ' -r '. patterns_get_drupal_installation_path();
- $cmd .= ' dl '. implode(' ', $modules) .' -y';
+ $cmd .= ' -r ' . patterns_get_drupal_installation_path();
+ $cmd .= ' dl ' . implode(' ', $modules) . ' -y';
$cmd .= ' 2>&1'; // add error stream
-
+
$return_var;
exec($cmd , $output, $return_var);
- return patterns_results($return_var === 0 ? PATTERNS_SUCCESS : PATTERNS_ERR, $output, $return_var);
+ return patterns_results($return_var === 0 ? PATTERNS_SUCCESS : PATTERNS_ERR, $output, $return_var);
}
/**
@@ -121,26 +121,26 @@ function patterns_drush_download_modules($modules) {
* returns an array with the lines of the output of the command
*/
function patterns_drush_enable_modules($modules, $resolve_dependencies = FALSE) {
- if (!patterns_drush_ready()) {
- return array('Drush path wasn\'t set');
+ if (!patterns_drush_ready()) {
+ return array('Drush path wasn\'t set');
}
-
- $rd = '';
+
+ $rd = '';
if ($resolve_dependencies) {
$rd = '--resolve-dependencies';
- }
-
-
- $output = array('Drush enable output:');
- $cmd = variable_get('patterns_drush_path');
- $cmd .= ' -r '. patterns_get_drupal_installation_path();
- $cmd .= ' en '. $rd .' '. implode(' ', $modules) .' -y';
- $cmd .= ' 2>&1'; // add error stream
- $return_var;
- exec($cmd , $output, $return_var);
-
- return patterns_results($return_var === 0 ? PATTERNS_SUCCESS : PATTERNS_ERR, $output, $return_var);
-
+ }
+
+
+ $output = array('Drush enable output:');
+ $cmd = variable_get('patterns_drush_path');
+ $cmd .= ' -r ' . patterns_get_drupal_installation_path();
+ $cmd .= ' en ' . $rd . ' ' . implode(' ', $modules) . ' -y';
+ $cmd .= ' 2>&1'; // add error stream
+ $return_var; // ??
+ exec($cmd , $output, $return_var);
+
+ return patterns_results($return_var === 0 ? PATTERNS_SUCCESS : PATTERNS_ERR, $output, $return_var);
+
}
/**
@@ -149,9 +149,9 @@ function patterns_drush_enable_modules($modules, $resolve_dependencies = FALSE)
*/
function patterns_get_drupal_installation_path() {
// TODO: Patterns or patterns?
- return realpath(drupal_get_path('module', 'Patterns') .'/../../../..') . '/';
+ return realpath(drupal_get_path('module', 'Patterns') . '/../../../..') . '/';
}
function patterns_drush_ready() {
- return (variable_get('patterns_drush_path') !== '') ? TRUE : FALSE;
+ return (variable_get('patterns_drush_path') !== '') ? TRUE : FALSE;
}
View
36 includes/config.inc
@@ -30,11 +30,11 @@ function patterns_permission() {
* @TODO proper doc.
*/
function patterns_config_settings($form, &$form_state) {
-
- $text = 'Configure the behavior of Patterns.';
- $title = 'Patterns settings';
+
+ $text = 'Configure the behavior of Patterns.';
+ $title = 'Patterns settings';
patterns_forms_add_page_header($form, $title, $text);
-
+
$form['exec'] = array(
'#type' => 'fieldset',
'#title' => t('File system options'),
@@ -55,11 +55,11 @@ function patterns_config_settings($form, &$form_state) {
'#title' => t('Included patterns'),
'#description' => t('Default behavior with included patterns. This option can be overwritten inside the pattern code.'),
'#options' => array(PATTERNS_INCLUDE_NEVER => t('Never run'),
- PATTERNS_INCLUDE_FIRSTRUN => t('Only during the first run'),
- PATTERNS_INCLUDE_UPDATE => t('Only if pattern was updated'),
- PATTERNS_INCLUDE_FIRSTRUN_OR_UPDATE => t('If it is the first run or if the pattern was updated'),
- PATTERNS_INCLUDE_ATTACHED => t('Only if the pattern code is attached (no lookup to database)'),
- PATTERNS_INCLUDE_ALWAYS => t('Always'),
+ PATTERNS_INCLUDE_FIRSTRUN => t('Only during the first run'),
+ PATTERNS_INCLUDE_UPDATE => t('Only if pattern was updated'),
+ PATTERNS_INCLUDE_FIRSTRUN_OR_UPDATE => t('If it is the first run or if the pattern was updated'),
+ PATTERNS_INCLUDE_ATTACHED => t('Only if the pattern code is attached (no lookup to database)'),
+ PATTERNS_INCLUDE_ALWAYS => t('Always'),
),
'#default_value' => patterns_get_include_mode(),
);
@@ -105,14 +105,14 @@ function patterns_config_settings($form, &$form_state) {
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
-
+
$form['sharing']['patterns_allow_publish'] = array(
'#type' => 'checkbox',
'#title' => t('Enable sharing of patterns'),
'#description' => t('If selected, patterns can be shared with others web sites.'),
'#default_value' => variable_get('patterns_allow_publish', PATTERNS_ALLOW_PUBLISH_DEFAULT),
);
-
+
$form['sharing']['patterns_public_url'] = array(
'#type' => 'textfield',
'#title' => t('Enable patterns public page'),
@@ -127,14 +127,14 @@ function patterns_config_settings($form, &$form_state) {
'#collapsed' => FALSE,
);
-
+
$form['drush']['patterns_drush_path'] = array(
- '#type' => 'textfield',
- '#title' => t('Drush Path'),
- '#description' => t('If you have drush installed, please specify the path. Otherwise leave it empty'),
- '#required' => FALSE,
- );
-
+ '#type' => 'textfield',
+ '#title' => t('Drush Path'),
+ '#description' => t('If you have drush installed, please specify the path. Otherwise leave it empty'),
+ '#required' => FALSE,
+ );
+
$form['other'] = array(
'#type' => 'fieldset',
'#title' => t('Other'),
View
11 includes/core/batch.inc
@@ -79,7 +79,7 @@ function patterns_execute_pattern_batch($pattern, $params, $patterns_details, $a
'%section' => $section,
'%cur_sec' => $cur_sec,
'%tot_sec' => $tot_sec,
- )),
+ )),
);
$total = count($actions);
@@ -186,14 +186,13 @@ function patterns_batch_finish($success, $results, $operations) {
}
else {
$pattern = reset($info);
- drupal_set_message(t('Section "@section" of pattern "@pattern" ran with errors.
- Check the error messages to get more details.',
- array('@pattern' => $pattern['title'], '@section' => $section,
- )),
+ drupal_set_message(t('Section "@section" of pattern "@pattern" ran with errors. Check the error messages to get more details.',
+ array('@pattern' => $pattern['title'], '@section' => $section, )
+ ),
'error');
drupal_set_message($results['error_message'], 'error');
}
-
+
unset($_SESSION['patterns_batch_info']);
drupal_flush_all_caches();
}
View
18 includes/db.inc
@@ -235,7 +235,7 @@ function patterns_get_pattern($id) {
$pattern = FALSE;
$query = db_select('patterns', 'p')
- ->fields('p');
+ ->fields('p');
if (is_numeric($id)) {
$query = $query->condition('p.pid', $id);
@@ -456,35 +456,35 @@ function patterns_db_analyze_patterns_status($pattern) {
/**
* Sets the flag public to FALSE in the database for
* the pattern with the specified pattern id.
- *
+ *
* @param mixed $pattern A pattern object, an array representing
* the pattern object, a numeric id or alphanumeric name of
* the pattern as it is in the database
- *
+ *
* @return Bool TRUE, if successful
- *
+ *
*/
function patterns_db_publish_pattern($pattern) {
$pattern = _patterns_db_get_pattern($pattern);
if (!$pattern) return FALSE;
$pid = $pattern->pid;
return db_query("UPDATE {patterns} SET public = 1 WHERE pid = :pid", array('pid' => $pid));
-}
+}
/**
* Sets the flag public to FALSE in the database for
* the pattern with the specified pattern id.
- *
+ *
* @param mixed $pattern A pattern object, an array representing
* the pattern object, a numeric id or alphanumeric name of
* the pattern as it is in the database
- *
+ *
* @return Bool TRUE, if successful
- *
+ *
*/
function patterns_db_unpublish_pattern($pattern) {
$pattern = _patterns_db_get_pattern($pattern);
if (!$pattern) return FALSE;
$pid = $pattern->pid;
return db_query("UPDATE {patterns} SET public = 0 WHERE pid = :pid", array('pid' => $pid));
-}
+}
View
2 includes/forms/editor.inc
@@ -259,7 +259,7 @@ function patterns_load_co2($format = PATTERNS_FORMAT_YAML) {
drupal_add_css($co2_css_theme);
drupal_add_js($co2_js);
- // TODO: enable PHP mode for codemirror as well.
+ // TODO: enable PHP mode for codemirror as well.
// At the moment it does not work
if ($format !== PATTERNS_FORMAT_UNKNOWN && $format !== 'php') {
$co2_mode = $co2_path . '/mode/' . $format . '/' . $format . '.js';
View
640 includes/forms/export.inc
@@ -2,7 +2,7 @@
/**
* @file
* Export the components configuration to a Pattern file.
- *
+ *
*/
/**
@@ -13,107 +13,103 @@
-function _patterns_export_build_input_name($module, $tag){
- return 'ext['.$module.'][options][' . $tag . ']';
+function _patterns_export_build_input_name($module, $tag) {
+ return 'ext[' . $module . '][options][' . $tag . ']';
}
function _patterns_export_goto($form, &$form_state, $step) {
// MODULE SELECTED
-
- if ($step == 1) {
- return patterns_export_page1($form, $form_state);
- }
-
+ if ($step == 1) {
+ return patterns_export_page1($form, $form_state);
+ }
+
if ($step == 2) {
-
- // TODO: We should check if the users selects more options, and if the functions
- // require extra parameters. For later, not we just continue.
-
- return $form;
-
-
- $tm_index = patterns_tagmodules_get_index();
- $tag = $form_state['values']['options'];
- $func_id = $form_state['values'][$tag];
-
- // Check if the function wants extra parameters
- // if (isset($tm_index[$tag]) && isset($tm_index[$tag][PATTERNS_EXPORT][$func_id])){
- // if (isset($tm_index[$tag]))
- //}
-
- //if (isset($form_state['values']['module']) && !is_int($form_state['values']['module'])) {
- // return patterns_export_page2($form, $form_state);
- //}
- }
-
-
- // FORM SELECTED
- /*
+ // TODO: We should check if the users selects more options, and if the functions
+ // require extra parameters. For later, not we just continue.
+ return $form;
+
+ $tm_index = patterns_tagmodules_get_index();
+ $tag = $form_state['values']['options'];
+ $func_id = $form_state['values'][$tag];
+
+ // Check if the function wants extra parameters
+ // if (isset($tm_index[$tag]) && isset($tm_index[$tag][PATTERNS_EXPORT][$func_id])){
+ // if (isset($tm_index[$tag]))
+ //}
+
+ //if (isset($form_state['values']['module']) && !is_int($form_state['values']['module'])) {
+ // return patterns_export_page2($form, $form_state);
+ //}
+ }
+
+
+ // FORM SELECTED
+ /*
if ( $step == 3 && !isset($form_state['values']['content'])) {
- return patterns_export_page3($form, $form_state);
+ return patterns_export_page3($form, $form_state);
}
// show pattern import form
if ($step = 4) {
- return patterns_export_page4($form, $form_state);
+ return patterns_export_page4($form, $form_state);
}
*/
-
+
// step > 5 Continue, submit form
return $form;
}
/**
* Checks the form_state and returns the current step of the form.
- *
- *
+ *
+ *
* @param array $form_state
* @param bool $validate (optional)
* If TRUE, the assumes that function is called from a validation
* environment, and decrements by 1 the current value of the step
- *
+ *
* @return mixed|Bool
- * The current value of the step, or FALSE if it fails to determine it
+ * The current value of the step, or FALSE if it fails to determine it
*/
function _patterns_export_check_step(&$form_state, $validation = FALSE) {
-
- $step = FALSE;
-
- if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0) {
+
+ $step = FALSE;
+
+ if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0) {
$step = 6; // Export ALL
}
/*
- elseif (isset($form_state['values']['content'])) {
+ elseif (isset($form_state['values']['content'])) {
$step = 4;
}
- elseif (isset($form_state['values']['module_forms'])) {
+ elseif (isset($form_state['values']['module_forms'])) {
$step = 3;
}
*/
- elseif (isset($form_state['values']['options'])) {
+ elseif (isset($form_state['values']['options'])) {
$step = 2;
}
- elseif (!isset($form_state['values']['step'])) {
+ elseif (!isset($form_state['values']['step'])) {
$step = 1;
}
-
+
if ($validation && is_numeric($step)) {
- $step = $step - 1;
+ $step = $step - 1;
}
-
+
$form_state['values']['step'] = $step;
return $step;
}
function _patterns_export_if_invalid_step_goback($step = 0,
- $back = '/admin/patterns/export',
- $options = array()) {
-
- // TODO: Adjust
+ $back = '/admin/patterns/export',
+ $options = array()) {
+
+ // TODO: Adjust
if ($step < 1 || $step > 10) {
- drupal_set_message(t('Export could not proceed to the next step. Step %id not found.', array('%id' => $step)), 'error');
- drupal_goto($back);
+ drupal_set_message(t('Export could not proceed to the next step. Step %id not found.', array('%id' => $step)), 'error');
+ drupal_goto($back);
}
return $step;
}
@@ -129,255 +125,255 @@ function _patterns_export_if_invalid_step_goback($step = 0,
*/
function patterns_export($form, &$form_state) {
-
- //$step = _patterns_export_check_step($form_state);
- //_patterns_export_if_invalid_step_goback($step);
-// $form['step'] = array(
+
+ //$step = _patterns_export_check_step($form_state);
+ //_patterns_export_if_invalid_step_goback($step);
+// $form['step'] = array(
// '#type' => 'hidden',
// '#title' => t('Pattern Identifier'),
// '#description' => t('step'),
// '#value' => $step,
// );
-
+
//debug($step);
-
+
//drupal_add_js('misc/ajax.js');
$name = isset($form_state['values']['name']) ? $form_state['values']['name'] : 'name not set';
-
+
patterns_io_load_components();
-
+
return patterns_export_page1($form, $form_state);
//return _patterns_export_goto($form, $form_state, $step);
}
function patterns_export_page1($form, &$form_state) {
-
- $tm_index = patterns_tagmodules_get_index();
- $tm_index = patterns_tagmodules_filter($tm_index, null, PATTERNS_EXPORT);
-
- if (count($tm_index) == 0) {
- drupal_set_message(t('The components currently installed do not allow automatic export of the configuration of the web site'), 'error');
-
- $form['disabled'] = array (
- '#markup' => l(t('Click here to back'), 'admin/patterns'),
- );
-
- return $form;
- }
-
- $text = 'In this area you can export the current configuration of your web site to a new pattern file that will be inserted in the database.';
- $title = 'Export (experimental!)';
+
+ $tm_index = patterns_tagmodules_get_index();
+ $tm_index = patterns_tagmodules_filter($tm_index, NULL, PATTERNS_EXPORT);
+
+ if (count($tm_index) == 0) {
+ drupal_set_message(t('The components currently installed do not allow automatic export of the configuration of the web site'), 'error');
+
+ $form['disabled'] = array(
+ '#markup' => l(t('Click here to back'), 'admin/patterns'),
+ );
+
+ return $form;
+ }
+
+ $text = 'In this area you can export the current configuration of your web site to a new pattern file that will be inserted in the database.';
+ $title = 'Export (experimental!)';
patterns_forms_add_page_header($form, $title, $text);
-
- $form['all'] = array (
- '#type' => 'fieldset',
- '#title' => 'Options',
- '#collapsible' => TRUE,
+
+ $form['all'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Options',
+ '#collapsible' => TRUE,
'#collapsed' => TRUE, // TODO set to TRUE after debugging
- );
-
- $form['all']['all'] = array (
- '#type' => 'fieldset',
- '#title' => 'I want to select the components individually (Experimental)',
- '#type' => 'checkbox',
- );
-
- $form['all']['ext'] = array (
- '#type' => 'fieldset',
- '#title' => 'Components with automatic export enabled',
- '#tree' => TRUE,
- '#collapsible' => TRUE,
+ );
+
+ $form['all']['all'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'I want to select the components individually (Experimental)',
+ '#type' => 'checkbox',
+ );
+
+ $form['all']['ext'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Components with automatic export enabled',
+ '#tree' => TRUE,
+ '#collapsible' => TRUE,
'#collapsed' => FALSE, // TODO set to TRUE after debugging
- '#states' => array(
- 'visible' => array( // action to take.
- ':input[name="all"]' => array('checked' => TRUE),
- ),
- ),
- );
-
+ '#states' => array(
+ 'visible' => array( // action to take.
+ ':input[name="all"]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+
foreach ($tm_index as $module => $tags) {
-
- $form['all']['ext'][$module] = array (
- '#type' => 'fieldset',
- '#title' => $module,
- '#collapsible' => TRUE,
- '#collapsed' => FALSE, // TODO set to TRUE after debugging
- );
-
- $form['all']['ext'][$module]['options'] = array (
- '#type' => 'checkboxes',
- '#title' => t('Export options'),
- '#options' => array_combine(array_keys($tags), array_keys($tags)),
- );
-
- foreach ($tags as $tag => $forms) {
-
- $input_name = _patterns_export_build_input_name($module,$tag);
-
- $form['all']['ext'][$module][$tag]['options'] = array(
- '#type' => 'checkboxes',
- '#title' => $tag,
- '#options' => array_combine(array_keys($forms), array_keys($forms)),
- '#states' => array(
- 'visible' => array( // action to take.
- ':input[name="' . $input_name . '"]' => array('checked' => TRUE),
- ),
- 'checked' => array( // action to take.
+
+ $form['all']['ext'][$module] = array(
+ '#type' => 'fieldset',
+ '#title' => $module,
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE, // TODO set to TRUE after debugging
+ );
+
+ $form['all']['ext'][$module]['options'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Export options'),
+ '#options' => array_combine(array_keys($tags), array_keys($tags)),
+ );
+
+ foreach ($tags as $tag => $forms) {
+
+ $input_name = _patterns_export_build_input_name($module, $tag);
+
+ $form['all']['ext'][$module][$tag]['options'] = array(
+ '#type' => 'checkboxes',
+ '#title' => $tag,
+ '#options' => array_combine(array_keys($forms), array_keys($forms)),
+ '#states' => array(
+ 'visible' => array( // action to take.
+ ':input[name="' . $input_name . '"]' => array('checked' => TRUE),
+ ),
+ 'checked' => array( // action to take.
':input[name="' . $input_name . '"]' => array('checked' => TRUE),
- ),
- ),
- );
- }
-
-
- //_patterns_export_add_ajax_to_options($form['ext'][$module]);
-
- }
-
+ ),
+ ),
+ );
+ }
+
+
+ //_patterns_export_add_ajax_to_options($form['ext'][$module]);
+
+ }
+
patterns_forms_get_info_section($form, array(), array('collapsed' => TRUE));
-
+
patterns_forms_get_formats_selector($form,
- patterns_forms_get_default_format(),
- 'Export data in this format',
- FALSE
+ patterns_forms_get_default_format(),
+ 'Export data in this format',
+ FALSE
);
-
+
patterns_forms_get_name_selector($form);
-
+
$form['submit'] = array(
- '#type' => 'submit',
+ '#type' => 'submit',
'#value' => t('Export'),
);
$form['#validate'][] = 'patterns_export_validate';
-
+
return $form;
}
function patterns_export_submit($form, &$form_state) {
-
- $tm_index = patterns_tagmodules_get_index();
- $format = $form_state['values']['format'];
- $filename = $form_state['values']['pattern_name'];
- // TODO: Loop here and create a modules section
-
-
- // Sets the category for the info
+
+ $tm_index = patterns_tagmodules_get_index();
+ $format = $form_state['values']['format'];
+ $filename = $form_state['values']['pattern_name'];
+ // TODO: Loop here and create a modules section
+
+
+ // Sets the category for the info
// category: " . $modules_with_components[$form_state['values']['module']]
- $pattern = patterns_api_add_info_section($form_state['values']['info']);
-
- if (isset($form_state['values']['all']) && $form_state['values']['all'] != 0) {
- // Individual modules have selected and the tagmodules index needs to be
- // refactored.
- $exports = array();
- foreach ($form_state['values']['ext'] as $module => $data) {
-
- foreach ($data['options'] as $tag => $enabled) {
- if (empty($enabled)) {
- continue;
- }
- $exports[$tag] = array();
- // Loop along all enabled export functions
+ $pattern = patterns_api_add_info_section($form_state['values']['info']);
+
+ if (isset($form_state['values']['all']) && $form_state['values']['all'] != 0) {
+ // Individual modules have selected and the tagmodules index needs to be
+ // refactored.
+ $exports = array();
+ foreach ($form_state['values']['ext'] as $module => $data) {
+
+ foreach ($data['options'] as $tag => $enabled) {
+ if (empty($enabled)) {
+ continue;
+ }
+ $exports[$tag] = array();
+ // Loop along all enabled export functions
foreach ($data[$tag]['options'] as $export_key => $func) {
if (!empty($func)) {
$tm_index[$tag]['__to_export__'][] = $tm_index[$tag][PATTERNS_EXPORT][$func];
}
}
-
+
// If no sub-tag was selected (should not be the case)
// then we execute EXPORT_ALL (if available)
if (empty($tm_index[$tag]['__to_export__'])) {
if (isset($tm_index[$tag][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL])) {
$tm_index[$tag]['__to_export__'] = $tm_index[$tag][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL];
}
- }
- }
- }
-
- $tm_index = array_intersect_key($tm_index, $exports);
- //$tm_index = array_combine($tm_index, $exports);
- }
-
-// if (isset($form_state['values']['options']) && !empty($form_state['values']['options'])) {
-// $cmp = $form_state['values']['options'];
-// $tm_index = array($cmp => $tm_index[$cmp]);
-//
-// if (isset($form_state['values'][$cmp]) && !empty($form_state['values'][$cmp])) {
-// $tag = $form_state['values'][$cmp];
-// $func = $tm_index[$cmp][PATTERNS_EXPORT][$tag];
-// $tm_index[$cmp][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL] = $func;
-// }
-// //else {
-// // $tm_index[$cmp] = array($tag => $tm_index[$cmp][PATTERNS_EXPORT_ALL]);
-// //}
-//
-// }
-
- list($sections, $modules) = patterns_export_php($tm_index);
-
- if (empty($sections)) {
- drupal_set_message(t('Export did not return any data.'), 'error');
- return FALSE;
- }
-
- // Modules that needs to be enabled
- // to run the pattern
- patterns_api_add_modules_section($modules, $pattern);
-
- foreach($sections as $s => $values) {
- $pattern[$s] = $values;
- }
-
- // Display the exported pattern
- //drupal_set_message(print_r($pattern, true));
-
- $result = patterns_io_save_pattern($pattern, $filename, $format);
-
- if ($result) {
- drupal_set_message('Pattern succesfully imported');
- }
-
-
- //patterns_export_batch($tm_index);
-
- $form_state['redirect'] = 'admin/patterns/export';
+ }
+ }
+ }
+
+ $tm_index = array_intersect_key($tm_index, $exports);
+ //$tm_index = array_combine($tm_index, $exports);
+ }
+
+// if (isset($form_state['values']['options']) && !empty($form_state['values']['options'])) {
+// $cmp = $form_state['values']['options'];
+// $tm_index = array($cmp => $tm_index[$cmp]);
+//
+// if (isset($form_state['values'][$cmp]) && !empty($form_state['values'][$cmp])) {
+// $tag = $form_state['values'][$cmp];
+// $func = $tm_index[$cmp][PATTERNS_EXPORT][$tag];
+// $tm_index[$cmp][PATTERNS_EXPORT][PATTERNS_EXPORT_ALL] = $func;
+// }
+// //else {
+// // $tm_index[$cmp] = array($tag => $tm_index[$cmp][PATTERNS_EXPORT_ALL]);
+// //}
+//
+// }
+
+ list($sections, $modules) = patterns_export_php($tm_index);
+
+ if (empty($sections)) {
+ drupal_set_message(t('Export did not return any data.'), 'error');
+ return FALSE;
+ }
+
+ // Modules that needs to be enabled
+ // to run the pattern
+ patterns_api_add_modules_section($modules, $pattern);
+
+ foreach ($sections as $s => $values) {
+ $pattern[$s] = $values;
+ }
+
+ // Display the exported pattern
+ //drupal_set_message(print_r($pattern, true));
+
+ $result = patterns_io_save_pattern($pattern, $filename, $format);
+
+ if ($result) {
+ drupal_set_message(t('Pattern succesfully imported.'));
+ }
+
+
+ //patterns_export_batch($tm_index);
+
+ $form_state['redirect'] = 'admin/patterns/export';
}
function patterns_export_php($tagmodules) {
- $result = array();
- $modules = array();
- foreach ($tagmodules as $tag => $values) {
- if (isset($values['__to_export__'])) {
- $values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL] = $values['__to_export__'];
+ $result = array();
+ $modules = array();
+ foreach ($tagmodules as $tag => $values) {
+ if (isset($values['__to_export__'])) {
+ $values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL] = $values['__to_export__'];
}
- elseif (!isset($values[PATTERNS_EXPORT]) || !isset($values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL])) {
- continue;
- }
-
- if (isset($values[PATTERNS_FILES])) {
- $files = (!is_array($values[PATTERNS_FILES])) ? array($values[PATTERNS_FILES]) : $values[PATTERNS_FILES];
- foreach ($files as $file) {
- require_once $file;
- }
+ elseif (!isset($values[PATTERNS_EXPORT]) || !isset($values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL])) {
+ continue;
}
-
- array_push($modules, $values['module']);
- $func = $values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL];
- if (!is_array($func)) {
- $sections[$tag] = call_user_func($func);
- }
- else {
- foreach ($func as $f) {
- $result[$tag] = isset($result[$tag]) ? $result[$tag] : array();
- $sections[$tag] = array_merge($result[$tag], call_user_func($f));
- }
- }
-
+
+ if (isset($values[PATTERNS_FILES])) {
+ $files = (!is_array($values[PATTERNS_FILES])) ? array($values[PATTERNS_FILES]) : $values[PATTERNS_FILES];
+ foreach ($files as $file) {
+ require_once $file;
+ }
+ }
+
+ array_push($modules, $values['module']);
+ $func = $values[PATTERNS_EXPORT][PATTERNS_EXPORT_ALL];
+ if (!is_array($func)) {
+ $sections[$tag] = call_user_func($func);
+ }
+ else {
+ foreach ($func as $f) {
+ $result[$tag] = isset($result[$tag]) ? $result[$tag] : array();
+ $sections[$tag] = array_merge($result[$tag], call_user_func($f));
+ }
+ }
+
}
-
+
$result[] = $sections;
- $result[] = $modules;
+ $result[] = $modules;
return $result;
}
@@ -388,79 +384,79 @@ function patterns_export_php($tagmodules) {
* checks in which step we are and puts the step counter up and sets the rebuild flag
*/
function patterns_export_validate($form, &$form_state) {
-
- //$step = _patterns_export_check_step($form_state, TRUE);
- //if ($step == 1) {
- // return _patterns_export_validate_step1($form, $form_state);
- //}
-
-// shortcut_set Array [1]
-// [0...0]
-// options Array [1]
-// [0...0]
-// shortcut_set Array [1]
-// [0...0]
-// All 0
-//
-//
-//
-// taxonomy Array [3]
-// [0...2]
-// options Array [2]
-// [0...1]
-// vocabulary vocabulary
-// term term
-// vocabulary Array [1]
-// [0...0]
-// options Array [1]
-// [0...0]
-// vocabulary Array [2]
-// [0...1]
-// All All
-// Cheat (I am doing terms) 0
-// term Array [1]
-
-
-
-
+
+ //$step = _patterns_export_check_step($form_state, TRUE);
+ //if ($step == 1) {
+ // return _patterns_export_validate_step1($form, $form_state);
+ //}
+
+// shortcut_set Array [1]
+// [0...0]
+// options Array [1]
+// [0...0]
+// shortcut_set Array [1]
+// [0...0]
+// All 0
+//
+//
+//
+// taxonomy Array [3]
+// [0...2]
+// options Array [2]
+// [0...1]
+// vocabulary vocabulary
+// term term
+// vocabulary Array [1]
+// [0...0]
+// options Array [1]
+// [0...0]
+// vocabulary Array [2]
+// [0...1]
+// All All
+// Cheat (I am doing terms) 0
+// term Array [1]
+
+
+
+
//$form_state['values']['step'] = $form_state['values']['step']+1;
return TRUE;
}
function _patterns_export_validate_step1($form, &$form_state) {
-
- if (!isset($form_state['values']['format'])){
- form_set_error('format', t('No valid format selected.'));
- return FALSE;
- }
-
- if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0){
- return TRUE; // We export all, no need for further checkings
- }
-
- /*
- if (!isset($form_state['values']['module'])){
- form_set_error('ext', t('No valid module selected.'));
- return FALSE;
- }
- $module = $form_state['values']['module'];
- if (empty($module) || !patterns_api_is_valid_component_name($module)) {
- form_set_error('ext', t('No valid module selected.'));
- return FALSE;
- }
- */
-
- if (!isset($form_state['values']['options'])){
- form_set_error($module, t('No valid component selected.'));
- return FALSE;
- }
-
- $component = $form_state['values']['options'];
- if (!isset($form_state['values'][$component])){
- form_set_error($module, t('No valid tag selected for component %component selected.', array('%component' => $component)));
- return FALSE;
- }
-
+
+ if (!isset($form_state['values']['format'])) {
+ form_set_error('format', t('No valid format selected.'));
+ return FALSE;
+ }
+
+ if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0) {
+ return TRUE; // We export all, no need for further checkings
+ }
+
+ /*
+ if (!isset($form_state['values']['module'])){
+ form_set_error('ext', t('No valid module selected.'));
+ return FALSE;
+ }
+ $module = $form_state['values']['module'];
+ if (empty($module) || !patterns_api_is_valid_component_name($module)) {
+ form_set_error('ext', t('No valid module selected.'));
+ return FALSE;
+ }
+ */
+
+ if (!isset($form_state['values']['options'])) {
+ form_set_error($module, t('No valid component selected.'));
+ return FALSE;
+ }
+
+ $component = $form_state['values']['options'];
+ if (!isset($form_state['values'][$component])) {
+ form_set_error($module, t('No valid tag selected for component %component selected.', array('%component' => $component)));
+ return FALSE;
+ }
+
return TRUE;
-}
+}
View
790 includes/forms/export.old.inc
@@ -6,101 +6,101 @@
function _patterns_extract_goto($form, &$form_state, $step) {
// MODULE SELECTED
-
- if ($step == 1) {
- return patterns_extract_page1($form, $form_state);
- }
-
+ if ($step == 1) {
+ return patterns_extract_page1($form, $form_state);
+ }
+
+
if ($step == 2) {
-
- // TODO: We should check if the users selects more options, and if the functions
- // require extra parameters. For later, not we just continue.
-
- return $form;
-
-
- $tm_index = patterns_api_build_tagmodules_index();
- $tag = $form_state['values']['options'];
- $func_id = $form_state['values'][$tag];
-
- // Check if the function wants extra parameters
- // if (isset($tm_index[$tag]) && isset($tm_index[$tag][PATTERNS_EXPORT][$func_id])){
- // if (isset($tm_index[$tag]))
- //}
-
- //if (isset($form_state['values']['module']) && !is_int($form_state['values']['module'])) {
- // return patterns_extract_page2($form, $form_state);
- //}
- }
-
-
- // FORM SELECTED
- /*
+
+ // TODO: We should check if the users selects more options, and if the functions
+ // require extra parameters. For later, not we just continue.
+
+ return $form;
+
+
+ $tm_index = patterns_api_build_tagmodules_index();
+ $tag = $form_state['values']['options'];
+ $func_id = $form_state['values'][$tag];
+
+ // Check if the function wants extra parameters
+ // if (isset($tm_index[$tag]) && isset($tm_index[$tag][PATTERNS_EXPORT][$func_id])){
+ // if (isset($tm_index[$tag]))
+ //}
+
+ //if (isset($form_state['values']['module']) && !is_int($form_state['values']['module'])) {
+ // return patterns_extract_page2($form, $form_state);
+ //}
+ }
+
+
+ // FORM SELECTED
+ /*
if ( $step == 3 && !isset($form_state['values']['content'])) {
- return patterns_extract_page3($form, $form_state);
+ return patterns_extract_page3($form, $form_state);
}
// show pattern import form
if ($step = 4) {
- return patterns_extract_page4($form, $form_state);
+ return patterns_extract_page4($form, $form_state);
}
*/
-
+
// step > 5 Continue, submit form
return $form;
}
/**
* Checks the form_state and returns the current step of the form.
- *
- *
+ *
+ *
* @param array $form_state
* @param bool $validate (optional)
* If TRUE, the assumes that function is called from a validation
* environment, and decrements by 1 the current value of the step
- *
+ *
* @return mixed|Bool
- * The current value of the step, or FALSE if it fails to determine it
+ * The current value of the step, or FALSE if it fails to determine it
*/
function _patterns_extract_check_step(&$form_state, $validation = FALSE) {
-
- $step = FALSE;
-
- if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0) {
+
+ $step = FALSE;
+
+ if (isset($form_state['values']['all']) && $form_state['values']['all'] == 0) {
$step = 6; // EXTRACT ALL
}
/*
- elseif (isset($form_state['values']['content'])) {
+ elseif (isset($form_state['values']['content'])) {
$step = 4;
}
- elseif (isset($form_state['values']['module_forms'])) {
+ elseif (isset($form_state['values']['module_forms'])) {
$step = 3;
}
*/
- elseif (isset($form_state['values']['options'])) {
+ elseif (isset($form_state['values']['options'])) {
$step = 2;
}
- elseif (!isset($form_state['values']['step'])) {
+ elseif (!isset($form_state['values']['step'])) {
$step = 1;
}
-
+
if ($validation && is_numeric($step)) {
- $step = $step - 1;
+ $step = $step - 1;
}
-
+
$form_state['values']['step'] = $step;
return $step;
}
function _patterns_extract_if_invalid_step_goback($step = 0,
- $back = '/admin/patterns/extract',
- $options = array()) {
-
- // TODO: Adjust
+ $back = '/admin/patterns/extract',
+ $options = array()) {
+
+ // TODO: Adjust
if ($step < 1 || $step > 10) {
- drupal_set_message(t('Extraction could not proceed to the next step. Step %id not found.', array('%id' => $step)), 'error');
- drupal_goto($back);
+ drupal_set_message(t('Extraction could not proceed to the next step. Step %id not found.', array('%id' => $step)), 'error');
+ drupal_goto($back);
}
return $step;
}
@@ -116,21 +116,21 @@ function _patterns_extract_if_invalid_step_goback($step = 0,
*/
function patterns_extract($form, &$form_state) {
-
- $step = _patterns_extract_check_step($form_state);
- _patterns_extract_if_invalid_step_goback($step);
- $form['step'] = array(
+
+ $step = _patterns_extract_check_step($form_state);
+ _patterns_extract_if_invalid_step_goback($step);
+ $form['step'] = array(
'#type' => 'hidden',
'#title' => t('Pattern Identifier'),
'#description' => t('step'),
'#value' => $step,
);
-
+
//debug($step);
-
+
//drupal_add_js('misc/ajax.js');
$name = isset($form_state['values']['name']) ? $form_state['values']['name'] : 'name not set';
-
+
patterns_io_load_components();
return _patterns_extract_goto($form, $form_state, $step);
@@ -139,260 +139,260 @@ function patterns_extract($form, &$form_state) {
function patterns_extract_page1($form, &$form_state) {
-
- $tm_index = patterns_api_build_tagmodules_index(null, null, PATTERNS_EXPORT);
-
- if (count($tm_index) == 0) {
- drupal_set_message(t('The components currently installed do not allow automatic extraction of the configuration of the web site'), 'error');
-
- $form['disabled'] = array (
- '#markup' => l(t('Click here to back'), 'admin/patterns'),
- );
-
- return $form;
- }
-
- $form['all'] = array (
- '#type' => 'fieldset',
- '#title' => 'Options',
- '#collapsible' => TRUE,
+
+ $tm_index = patterns_api_build_tagmodules_index(NULL, NULL, PATTERNS_EXPORT);
+
+ if (count($tm_index) == 0) {
+ drupal_set_message(t('The components currently installed do not allow automatic extraction of the configuration of the web site'), 'error');
+
+ $form['disabled'] = array(
+ '#markup' => l(t('Click here to back'), 'admin/patterns'),
+ );
+
+ return $form;
+ }
+
+ $form['all'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Options',
+ '#collapsible' => TRUE,
'#collapsed' => TRUE, // TODO set to TRUE after debugging
- );
-
- $form['all']['all'] = array (
- '#type' => 'fieldset',
- '#title' => 'I want to extract configuration from single components (Experimental)',
- '#type' => 'checkbox',
- );
-
- $form['all']['ext'] = array (
- '#type' => 'fieldset',
- '#title' => 'Components with automatic extraction enabled',
- //'#tree' => TRUE,
- '#collapsible' => TRUE,
+ );
+
+ $form['all']['all'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'I want to extract configuration from single components (Experimental)',
+ '#type' => 'checkbox',
+ );
+
+ $form['all']['ext'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Components with automatic extraction enabled',
+ //'#tree' => TRUE,
+ '#collapsible' => TRUE,
'#collapsed' => TRUE, // TODO set to TRUE after debugging
- '#states' => array(
- 'visible' => array( // action to take.
- ':input[name="all"]' => array('checked' => TRUE),
- ),
- ),
- );
-
+ '#states' => array(
+ 'visible' => array( // action to take.
+ ':input[name="all"]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+
foreach ($tm_index as $module => $tags) {
-
- $form['all']['ext'][$module] = array (
- '#type' => 'fieldset',
- '#title' => $module,
- '#collapsible' => TRUE,
- '#collapsed' => FALSE, // TODO set to TRUE after debugging
- );
-
- /*
- $form['all']['ext'][$module]['module'] = array(
- '#type' => 'hidden',
- '#default_value' => $module,
- );
- */
-
- $form['all']['ext'][$module]['options'] = array(
- '#type' => 'radios',
- '#title' => t('Extraction options'),
- '#options' => array_combine(array_keys($tags), array_keys($tags)),
- );
-
- foreach ($tags as $tag => $forms) {
-
- /*
- $form['all']['ext'][$module][$tag]['tag'] = array(
- '#type' => 'hidden',
- '#default_value' => $tag,
- );
- */
-
- $form['all']['ext'][$module][$tag]['options'][$tag] = array(
- //$form['all']['ext'][$module][$tag]['options'] = array(
- '#type' => 'radios',
- '#title' => $tag,
- '#options' => array_combine(array_keys($forms), array_keys($forms)),
- '#states' => array(
- 'visible' => array( // action to take.
- ':input[name="options"]' => array('value' => $tag),
- ),
- ),
- );
- }
-
-
- //_patterns_extract_add_ajax_to_options($form['ext'][$module]);
-
- // TODO: do we need this?
- $form['all']['ext']['module'] = array(
- '#type' => 'hidden',
- '#default_value' => $module,
- );
-
- }
-
+
+ $form['all']['ext'][$module] = array(
+ '#type' => 'fieldset',
+ '#title' => $module,
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE, // TODO set to TRUE after debugging
+ );
+
+ /*
+ $form['all']['ext'][$module]['module'] = array(
+ '#type' => 'hidden',
+ '#default_value' => $module,
+ );
+ */
+
+ $form['all']['ext'][$module]['options'] = array(
+ '#type' => 'radios',
+ '#title' => t('Extraction options'),
+ '#options' => array_combine(array_keys($tags), array_keys($tags)),
+ );
+
+ foreach ($tags as $tag => $forms) {
+
+ /*
+ $form['all']['ext'][$module][$tag]['tag'] = array(
+ '#type' => 'hidden',
+ '#default_value' => $tag,
+ );
+ */
+
+ $form['all']['ext'][$module][$tag]['options'][$tag] = array(
+ //$form['all']['ext'][$module][$tag]['options'] = array(
+ '#type' => 'radios',
+ '#title' => $tag,
+ '#options' => array_combine(array_keys($forms), array_keys($forms)),
+ '#states' => array(
+ 'visible' => array( // action to take.
+ ':input[name="options"]' => array('value' => $tag),
+ ),
+ ),
+ );
+ }
+
+
+ //_patterns_extract_add_ajax_to_options($form['ext'][$module]);
+
+ // TODO: do we need this?
+ $form['all']['ext']['module'] = array(
+ '#type' => 'hidden',
+ '#default_value' => $module,
+ );
+
+ }
+
patterns_forms_get_info_section($form, array(), array('collapsed' => TRUE));
-
+
patterns_forms_get_formats_selector($form,
- patterns_forms_get_default_format(),
- 'Extract data in this format',
- FALSE
+ patterns_forms_get_default_format(),
+ 'Extract data in this format',
+ FALSE
);
-
+
patterns_forms_get_name_selector($form);
-
+
$form['submit'] = array(
- '#type' => 'submit',
+ '#type' => 'submit',
'#value' => t('Extract'),
);
$form['#validate'][] = 'patterns_extract_validate';
-
+
return $form;
}
function patterns_extract_submit($form, &$form_state) {
-
- $tm_index = patterns_api_build_tagmodules_index();
- $format = $form_state['values']['format'];
- $filename = $form_state['values']['pattern_name'];
- // TODO: Loop here and create a modules section
-
-
- // Sets the category for the info
+
+ $tm_index = patterns_api_build_tagmodules_index();
+ $format = $form_state['values']['format'];
+ $filename = $form_state['values']['pattern_name'];
+ // TODO: Loop here and create a modules section
+
+
+ // Sets the category for the info
// category: " . $modules_with_components[$form_state['values']['module']]
- $pattern = patterns_api_add_info_section($form_state['values']['info']);
-
- if (isset($form_state['values']['options'])) {
- $cmp = $form_state['values']['options'];
- $tm_index = $tm_index[$cmp];
- if (isset($form_state['values'][$cmp])) {
- $tag = $form_state['values'][$cmp];
- $tm_index[$tag];
- }
- else {
- $tm_index = $tm_index[PATTERNS_EXPORT_ALL];
- }
- }
-
- $sections = patterns_extract_php($tm_index);
- foreach($sections as $s => $values) {
- $pattern[$s] = $values;
- }
- //$pattern = array_merge($info, $sections);
-
- //if (patterns_validate_pattern($pattern, ))
-
- //$parsed = patterns_parser_parse($pattern, $format);
- drupal_set_message(print_r($pattern, true));
-
- if ($parsed) {
- drupal_set_message('Pattern succesfully extracted');
- }
-
- $result = patterns_io_save_pattern($pattern, $filename, $format);
-
- if ($result) {
- drupal_set_message('Pattern succesfully imported');
- }
-
-
- //patterns_extract_batch($tm_index);
-
-
-
- $form_state['redirect'] = 'admin/patterns/extract';
- /*
- // Only extract all for now
-
- $pattern = patterns_api_add_info_section();
-
-
- $exports = patterns_api_build_moduletags_index($form_state['values']['module'], null, PATTERNS_EXPORT);
- $func = $exports[$form_state['values']['options']];
-
- $sections = call_user_func_array($func, array());
-
- $pattern = array_merge($info, $sections);
-
- //debug($pattern);
- */