You are here

function brightcove_admin_player_edit_form_submit in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.player.inc \brightcove_admin_player_edit_form_submit()

Submit handler for brightcove_admin_player_edit_form().

_state

Parameters

array $form:

File

./brightcove.player.inc, line 201

Code

function brightcove_admin_player_edit_form_submit(array $form, array &$form_state) {
  $bcid = $form_state['values']['bcid'];
  $player_id = $form_state['values']['player_id'];
  $name = $form_state['values']['name'];
  $description = $form_state['values']['description'];

  /** @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 ($player_id) {
    $player = $pm
      ->getPlayer($player_id);
    $configuration = $player
      ->getBranches()
      ->getPreview()
      ->getConfiguration();
  }
  else {
    $configuration = _brightcove_admin_empty_configuration();
  }
  _brightcove_admin_apply_on_configuration($form_state, $configuration);
  $success = brightcove_try(function () use (&$player_id, $pm, $configuration, $name, $description) {
    if ($player_id) {
      $update_data = new \Brightcove\Object\Player\UpdateData();
      $update_data
        ->setName($name);
      $update_data
        ->setDescription($description);
      $pm
        ->updatePlayer($player_id, $update_data);
      $pm
        ->updatePlayerConfigurationBranch($player_id, $configuration);
    }
    else {
      $create_data = new \Brightcove\Object\Player\CreateData();
      $create_data
        ->setName($name);
      $create_data
        ->setDescription($description);
      $create_data
        ->setConfiguration($configuration);

      /** @var \Brightcove\Object\Player\CreateResult $result */
      $result = $pm
        ->createPlayer($create_data);
      $player_id = $result
        ->getId();
    }
    return TRUE;
  }, function () use ($player_id) {
    if ($player_id) {
      drupal_set_message(t('Failed to update player'));
    }
    else {
      drupal_set_message(t('Failed to create player.'), 'error');
    }
    return FALSE;
  });
  if ($success) {
    $form_state['redirect'] = "admin/config/media/brightcove/players/{$bcid}/{$player_id}";
  }
}