You are here

function submitEmbedForm in Entity Embed 7

Same name and namespace in other branches
  1. 7.3 entity_embed.admin.inc \submitEmbedForm()
  2. 7.2 entity_embed.admin.inc \submitEmbedForm()

Form submission handler embeds selected entity in WYSIWYG.

Parameters

$form: An associative array containing the structure of the form.

$form_state: An associative array containing the current state of the form.

1 string reference to 'submitEmbedForm'
entity_embed_dialog_form in ./entity_embed.admin.inc
Form constructor for the entity embed dialog form.

File

./entity_embed.admin.inc, line 443
Admin page callbacks for the entity_embed module.

Code

function submitEmbedForm(&$form, $form_state) {
  $values = $form_state['values'];

  // Display errors in form, if any.
  if (form_get_errors()) {
    unset($form['#prefix'], $form['#suffix']);
    $status_messages = array(
      '#theme' => 'status_messages',
    );
    $output = drupal_render($form);
    $output = '<div>' . drupal_render($status_messages) . $output . '</div>';
    $commands[] = ajax_command_html('#entity-embed-dialog-form', $output);
  }
  else {

    // Serialize entity embed settings to JSON string.
    if (!empty($values['attributes']['data-entity-embed-settings'])) {
      $values['attributes']['data-entity-embed-settings'] = drupal_json_encode($values['attributes']['data-entity-embed-settings']);
    }
    $commands[] = entity_embed_command_editor_dialog_save($values);
    $commands[] = entity_embed_command_close_modal_dialog();
  }
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}