You are here

function wysiwyg_template_save_template in Wysiwyg API template plugin 7.2

Wysiwyg template database save function.

3 calls to wysiwyg_template_save_template()
wysiwyg_template_features_rebuild in ./wysiwyg_template.features.inc
Implements hook_features_rebuild().
wysiwyg_template_import_from_code in ./wysiwyg_template.admin.inc
Helper function to parse template import PHP code and save the template.
wysiwyg_template_template_form_submit in ./wysiwyg_template.admin.inc
Wysiwyg template form submit - delete and save handlers

File

./wysiwyg_template.module, line 419
Makes TinyMCE Templates available as plugin for client-side editors integrated via Wysiwyg API.

Code

function wysiwyg_template_save_template($template) {
  $new_template = array(
    'name' => $template['name'],
    'title' => $template['title'],
    'description' => $template['description'],
    'weight' => isset($template['weight']) ? $template['weight'] : 0,
    'fid' => $template['fid'],
    'body' => $template['body'],
    // Avoid PHP Notice when importing templates without format.
    'format' => isset($template['format']) ? $template['format'] : filter_fallback_format(),
  );
  $existing = wysiwyg_template_name_exists($template['name']);

  // Save to database.
  if (drupal_write_record('wysiwyg_templates', $new_template, $existing ? 'name' : array())) {
    db_query("DELETE FROM {wysiwyg_templates_content_types} WHERE name = :name", array(
      ':name' => $template['name'],
    ));
    if (isset($template['content_types'])) {
      foreach ($template['content_types'] as $key => $content_type) {
        if (!empty($content_type)) {
          $values = array(
            'name' => $template['name'],
            'type' => $key,
          );
          drupal_write_record('wysiwyg_templates_content_types', $values);
        }
      }
    }
    return TRUE;
  }
  return FALSE;
}