You are here

function patterns_edit in Patterns 6.2

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

Menu callback to edit a patterns data

1 string reference to 'patterns_edit'
patterns_menu in ./patterns.module
Implementation of hook_menu().

File

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

Code

function patterns_edit(&$form_state, $pid = null) {
  if (!is_numeric($pid)) {
    drupal_set_message(t('You must specify a pattern to edit.'));
    return;
  }
  $pattern = patterns_get_pattern($pid);

  // TODO: Turn php into xml here.
  // For now just allow modifying the original xml, which
  // means the modification cannot be further modified
  if (!$pattern->file) {
    drupal_set_message(t('This pattern does not seem to have an XML source file to base the modifications off of.'), 'error');
    return;
  }
  $xml = file_get_contents($pattern->file);
  $form['name'] = array(
    '#type' => 'value',
    '#value' => $pattern->name,
  );
  $form['pid'] = array(
    '#type' => 'value',
    '#value' => $pattern->pid,
  );

  //   if ($pattern->enabled <= $pattern->updated) {
  //     $form['revert'] = array(
  //       '#type' => 'markup',
  //       '#value' => l(t('Undo update changes to the state when you enabled the pattern.'), 'admin/build/patterns/revert/'. $pid, array(), drupal_get_destination())
  //     );
  //   }
  $form['format'] = array(
    '#type' => 'select',
    '#title' => t('Pattern syntax'),
    '#options' => array_combine(patterns_file_types(), patterns_file_types()),
    '#default_value' => pathinfo($pattern->file, PATHINFO_EXTENSION),
  );
  $form['xml'] = array(
    '#type' => 'textarea',
    '#title' => t('Pattern\'s code'),
    '#rows' => 25,
    '#default_value' => $xml,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}