You are here

function ds_extras_ds_fields_ui_alter in Display Suite 7.2

Same name and namespace in other branches
  1. 7 modules/ds_extras/ds_extras.vd.inc \ds_extras_ds_fields_ui_alter()

Implements hook_ds_fields_ui_alter().

File

modules/ds_extras/includes/ds_extras.vd.inc, line 200
Views displays functions.

Code

function ds_extras_ds_fields_ui_alter(&$fields, $context) {

  // Check on the $bundle string to see if the key 2 exists. If it exists,
  // we'll call the view to put the fields of this view on and remove
  // the fields which comes default by ds_extras_field_extra_fields()
  // and only work for the views template.
  $bundle = $context['bundle'];
  $fields_check = explode('-', $bundle);
  if (isset($fields_check[2])) {
    $field_copy = array(
      'title' => 'dummy',
      'field_type' => DS_FIELD_TYPE_IGNORE,
    );

    // Remove the view template fields.
    $remove_fields = ds_extras_ds_fields_info('ds_views');
    foreach ($remove_fields['ds_views'] as $key => $properties) {
      unset($fields[$key]);
    }

    // Get the view and its fields.
    $view = views_get_view($fields_check[0]);
    $view
      ->set_display($fields_check[1]);
    $fields = $view->display_handler
      ->get_field_labels();
    foreach ($fields as $field_key => $field_label) {
      $field_properties = $field_copy;
      $field_properties['title'] = $field_label;
      $fields[$field_key] = $field_properties;
    }
  }
}