You are here

function mee_ajax_widget_expand in Scald: Media Management made easy 7

Ajax callback: returns the expanded HTML atom widget.

This URL is used by the "CKEditor 4" widget plugin.

Parameters

$atom: The atom.

Other parameters, such as context, could also be passed via the querystring.

1 string reference to 'mee_ajax_widget_expand'
mee_menu in modules/fields/mee/mee.module
Implements hook_menu().

File

modules/fields/mee/mee.module, line 704
Defines a special textarea, with drag and drop media driven by Scald and dnd.module.

Code

function mee_ajax_widget_expand($atom) {
  $context = isset($_GET['context']) && in_array($_GET['context'], dnd_scald_wysiwyg_context_slugs()) ? $_GET['context'] : NULL;
  if ($atom->type == 'scald_atom_fallback') {
    $context = 'invalid-id';
  }
  $options = isset($_GET['options']) ? urldecode($_GET['options']) : '';
  $align = isset($_GET['align']) && in_array($_GET['align'], array(
    'left',
    'right',
    'center',
  )) ? $_GET['align'] : 'none';

  // The legend call needs at least the basic atom meta-data
  // to be pre-rendered, so ensure they are present by doing
  // an early render, eventually in the lightweight 'title'
  // context if no explicit context is given.
  $output = $context ? scald_render($atom, $context, $options) : scald_render($atom, 'title');
  if (empty($atom->omit_legend)) {
    $legend = theme('sdl_editor_legend', array(
      'atom' => $atom,
    ));
  }
  else {
    $legend = '';
  }
  $commands = array();
  $commands[] = array(
    'command' => 'dndck4_cache_atom_metadatadata',
    'data' => array(
      'sid' => $atom->sid,
      'meta' => array(
        'title' => $atom->title,
        'type' => $atom->type,
        'data' => !empty($atom->data) ? $atom->data : array(),
        'provider' => $atom->provider,
        'legend' => $legend,
      ),
      'actions' => array_keys(scald_atom_actions_available($atom)),
    ),
  );
  if ($context) {
    $commands[] = array(
      'command' => 'dndck4_expand_widget',
      'data' => theme('mee_widget_embed', array(
        'atom' => $atom,
        'context' => $context,
        'options' => $options,
        'align' => $align,
        'content' => $output,
        'wysiwyg' => TRUE,
      )),
    );
  }
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}