You are here

function assets_wysiwyg_form_submit in Asset 7

Custom submit handler.

1 string reference to 'assets_wysiwyg_form_submit'
assets_wysiwyg_form in includes/asset.admin.inc
Page callback for wysiwyg form.

File

includes/asset.admin.inc, line 364
Asset admin page callbacks.

Code

function assets_wysiwyg_form_submit(&$form, &$form_state) {
  $asset = $form_state['asset'];
  $values = $form_state['values'];
  $view_mode = isset($values['view_mode']) ? $values['view_mode'] : ASSET_DEFAULT_MODE;
  $alignment = isset($values['align']) ? $values['align'] : '';
  $placeholder = assets_build_placeholder($asset, array(
    'mode' => $view_mode,
    'align' => $alignment,
  ));
  $placeholder = addslashes($placeholder);
  $placeholder = str_replace("\r\n", '\\n', $placeholder);

  // @todo: This is pretty ugly way, we need to implement own ajax commands and use ajax_deliver().
  if ($form_state['op'] == 'edit') {
    $js = 'var CKEDITOR = parent.CKEDITOR;
    var dialog =  CKEDITOR.dialog.getCurrent();
    var outdated = dialog._outdatedAssetEl;
    if (outdated) {
      var tag_id = outdated.data(\'asset-cid\');
      dialog._.editor.plugins.asset.replaceAsset(tag_id, \'' . $placeholder . '\' );
    }
    dialog.hide();';
  }
  else {
    $js = 'var CKEDITOR = parent.CKEDITOR;
    var dialog = CKEDITOR.dialog.getCurrent();
    var newHtml = dialog._.editor.plugins.asset.Assets.getContentByTag(\'' . $placeholder . '\');
    if (newHtml) {
      var element = CKEDITOR.dom.element.createFromHtml(newHtml);
      element.setAttribute(\'contentEditable\', \'false\');   //Hello, Chrome
      dialog._.editor.insertElement(element);
      if (CKEDITOR.env.gecko && newHtml.search(/<object /i) > 0) {
        var wysiwyg = dialog._.editor.getMode();
        wysiwyg.loadData(wysiwyg.getData());
      }
    }
    dialog.hide();';
  }
  echo '<script>' . $js . '</script>';
  drupal_exit();
}