You are here

function jw_player_preset_select_ajax_callback in JW Player 7.2

Ajax callback to process preset select change.

Parameters

array $form: Array of the form from jw_player_field_formatter_settings_form.

array $form_state: Array of the form state from jw_player_field_formatter_settings_form.

Return value

array Ajax commands to rebuild 'Manage selected preset' link.

1 string reference to 'jw_player_preset_select_ajax_callback'
jw_player_field_formatter_settings_form in ./jw_player.module
Implements hook_field_formatter_settings_form().

File

./jw_player.module, line 249
Adds a theme function which allows theme developers to use the JW Player.

Code

function jw_player_preset_select_ajax_callback($form, &$form_state) {
  $commands = array();

  // This approach is required on standard entity type "Manage display" pages.
  if (isset($form_state['formatter_settings_edit'])) {
    $field_name = $form_state['formatter_settings_edit'];

    // Get $form_state values for the formatter settings.
    $values = $form_state['values']['fields'][$field_name]['settings_edit_form']['settings'];

    // Get the updated value for the preset field and build the new href.
    $updated_preset = $values['jwplayer_preset'];
    $updated_href = 'admin/config/media/jw_player/list/' . $updated_preset . '/edit';

    // Get the fields used for formatter settings, and set the value of the links element.
    $settings_fields =& $form['fields'][$field_name]['format']['settings_edit_form']['settings'];
    $settings_fields['links']['#links'][2]['href'] = $updated_href;

    // Set the links element output.
    $output = $settings_fields['links'];
  }
  else {

    // Get the #parents of the triggering element.
    $parents = $form_state['triggering_element']['#parents'];

    // Get the updated value for the preset field and build the new href.
    $updated_preset = drupal_array_get_nested_value($form_state['values'], $parents);
    $updated_href = 'admin/config/media/jw_player/list/' . $updated_preset . '/edit';
    $field_name = $parents[1];

    // Get the #array_parents to be used for the form element to be rendered.
    $array_parents = $form_state['triggering_element']['#array_parents'];

    // Remove trigger element name from the end, and add the links destination.
    array_pop($array_parents);
    array_push($array_parents, 'links', '#links', 2, 'href');

    // Set the value of the links form element.
    drupal_array_set_nested_value($form, $array_parents, $updated_href);

    // Set the links element output.
    $output = $form['displays']['settings'][$field_name]['links'];
  }
  $commands[] = ajax_command_replace('#jw-player-preset-links-wrapper', render($output));
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}