You are here

function brightcove_admin_embed_edit_form_submit in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.6 brightcove.player.inc \brightcove_admin_embed_edit_form_submit()

Submit handler for brightcove_admin_embed_edit_form().

_state

Parameters

array $form:

File

./brightcove.player.inc, line 525

Code

function brightcove_admin_embed_edit_form_submit(array $form, array &$form_state) {
  $bcid = $form_state['values']['bcid'];
  $player_id = $form_state['values']['player_id'];
  $embed_id = $form_state['values']['embed_id'];
  $name = $form_state['values']['embed_name'];
  $origin = $form_state['values']['origin'];

  /** @var \Brightcove\Object\Player\Branch\Configuration\Configuration $configuration */
  $configuration = NULL;
  $client = brightcove_client_load($bcid);

  /** @var \Brightcove\API\PM $pm */
  list(, , $pm) = brightcove_create_classes($client);
  if ($embed_id) {
    $embed = $pm
      ->getEmbed($player_id, $embed_id);
    $configuration = $embed
      ->getBranches()
      ->getPreview()
      ->getConfiguration();
  }
  else {
    $configuration = _brightcove_admin_empty_configuration();
  }
  _brightcove_admin_apply_on_configuration($form_state, $configuration);
  $success = brightcove_try(function () use (&$embed_id, $player_id, $pm, $configuration, $name) {
    if ($embed_id) {
      $pm
        ->updateEmbedConfigurationBranch($player_id, $embed_id, $configuration);
    }
    else {
      $result = $pm
        ->createEmbed($player_id, $configuration);
      $embed_id = $result
        ->getId();
    }
    return TRUE;
  }, function () use ($embed_id) {
    if ($embed_id) {
      drupal_set_message(t('Embed updated.'));
    }
    else {
      drupal_set_message(t('Failed to create embed'), 'error');
    }
    return FALSE;
  });
  if ($success) {
    switch ($origin) {
      case 'add-embed':
        sleep(6);

        // wait a couple of second for the brightcove server to update, so the user doesn't run into a file not found error.
        $form_state['redirect'] = "admin/config/media/brightcove/players/{$bcid}/{$player_id}/{$embed_id}/view";
        break;
      case 'edit':
        $form_state['redirect'] = "admin/config/media/brightcove/players/{$bcid}/{$player_id}/{$embed_id}/preview";
        break;
      default:
        $form_state['redirect'] = "admin/config/media/brightcove/players/{$bcid}/{$player_id}/{$embed_id}";
        break;
    }
  }
}