Projet

Général

Profil

Révision 6e9292aa

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ds/modules/ds_extras/ds_extras.module
335 335
  return $output;
336 336
}
337 337

  
338
/**
339
 * Implements hook_form_FORM_ID_alter().
340
 */
341
function ds_extras_form_node_type_form_alter(&$form, $form_state, $form_id) {
342
  $node_type = $form['#node_type']->type;
343

  
344
  // Get the view modes.
345
  $options = ds_extras_get_bundle_view_modes('node', $node_type);
346

  
347
  // Only fire if we have more than 1 option.
348
  if (count($options) > 1) {
349
    if (!isset($form['ds_extras'])) {
350
      $form['ds_extras'] = array(
351
        '#type' => 'fieldset',
352
        '#title' => t('Display Suite: Extras'), // There's already a 'Display settings' fieldset
353
        '#collapsible' => TRUE,
354
        '#collapsed' => TRUE,
355
        '#group' => 'additional_settings',
356
        '#weight' => 100,
357
      );
358
    }
359

  
360
    $form['ds_extras']['ds_extras_view_modes'] = array(
361
      '#type' => 'checkboxes',
362
      '#title' => t('View modes'),
363
      '#options' => $options,
364
      '#default_value' => variable_get('ds_extras_view_modes_' . $node_type, array_keys($options)),
365
      '#description' => t('Select which view modes will be available to switch to on node edit forms.'),
366
    );
367
  }
368
}
369

  
338 370
/**
339 371
 * Implements hook_form_FORM_ID_alter().
340 372
 */
341 373
function ds_extras_form_node_form_alter(&$form, $form_state, $form_id) {
374
  $node = $form['#node'];
342 375

  
343 376
  // Switch full view mode.
344
  if (user_access('ds_switch ' . $form['#node']->type)) {
345

  
346
    $view_mode_settings = field_view_mode_settings('node', $form['#node']->type);
377
  if (user_access('ds_switch ' . $node->type)) {
347 378

  
348 379
    // Get the view modes.
349
    $ds_vm = ds_entity_view_modes('node');
380
    $view_modes = ds_extras_get_bundle_view_modes('node', $node->type);
381
    $enabled_vm = variable_get('ds_extras_view_modes_' . $node->type, array_keys($view_modes));
350 382
    $layouts = array();
351
    $options = array('' => t('Default'));
352
    foreach ($ds_vm as $key => $item) {
353
      $overriden = (!empty($view_mode_settings[$key]['custom_settings']) ? TRUE : FALSE);
354
      if ($overriden) {
355
        $layout = ds_get_layout('node', $form['#node']->type, $key, FALSE);
383
    $options = array();
384
    foreach ($view_modes as $key => $label) {
385
      if (in_array($key, $enabled_vm)) {
386
        $layout = ds_get_layout('node', $node->type, $key, FALSE);
356 387
        $layouts[$key] = $layout;
357
        $options[$key] = $item['label'];
388
        $options[$key] = $label;
358 389
      }
359 390
    }
360 391

  
361
    // Add default layout settings
362
    $layouts[''] = ds_get_layout('node', $form['#node']->type, 'default', FALSE);
363

  
364 392
    // Only fire if we have more than 1 option.
365 393
    if (count($options) > 1) {
366
      $node = $form['#node'];
367

  
368 394
      if (!isset($form['ds_extras'])) {
369 395
        $form['ds_extras'] = array(
370 396
          '#type' => 'fieldset',
......
380 406
        '#type' => 'select',
381 407
        '#title' => t('View mode'),
382 408
        '#options' => $options,
383
        '#default_value' => isset($node->ds_switch) ? $node->ds_switch : '',
409
        '#default_value' => isset($node->ds_switch) ? $node->ds_switch : 'default',
384 410
        '#description' => t('Switch to a different view mode to display the full page view of this node.'),
385 411
        '#weight' => -1,
386 412
        '#ajax' => array(
......
395 421
        '#suffix' => '</div>',
396 422
      );
397 423

  
398
      $mode = isset($form_state['input']['ds_switch']) ? $form_state['input']['ds_switch'] : (isset($node->ds_switch) ? $node->ds_switch : '');
399
      $chosen_layout = $layouts[$mode];
400

  
401 424
      $fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
402
      $image = (isset($chosen_layout['image']) && !empty($chosen_layout['image'])) ? $chosen_layout['path'] . '/' . $chosen_layout['layout'] . '.png' : $fallback_image;
403
      if (isset($chosen_layout['panels']) && !empty($chosen_layout['panels']['icon'])) {
404
        $image = $chosen_layout['panels']['path'] . '/' . $chosen_layout['panels']['icon'];
425
      $mode = isset($form_state['input']['ds_switch']) ? $form_state['input']['ds_switch'] : (isset($node->ds_switch) ? $node->ds_switch : 'default');
426
      if (isset($layouts[$mode])) {
427
        $chosen_layout = $layouts[$mode];
428
        $chosen_layout = (isset($layouts[$mode])) ? $layouts[$mode] : 'default';
429

  
430
        $image = (isset($chosen_layout['image']) && !empty($chosen_layout['image'])) ? $chosen_layout['path'] . '/' . $chosen_layout['layout'] . '.png' : $fallback_image;
431
        if (isset($chosen_layout['panels']) && !empty($chosen_layout['panels']['icon'])) {
432
          $image = $chosen_layout['panels']['path'] . '/' . $chosen_layout['panels']['icon'];
433
        }
434
      }
435
      else {
436
        $image = $fallback_image;
405 437
      }
406 438

  
407 439
      $form['ds_extras']['preview']['image'] = array(
......
411 443
  }
412 444
}
413 445

  
446
/**
447
 * Get view modes for an entity bundle.
448
 */
449
function ds_extras_get_bundle_view_modes($type, $bundle) {
450
  $view_modes = array('default' => t('Default'));
451

  
452
  $view_mode_settings = field_view_mode_settings($type, $bundle);
453
  $ds_vm = ds_entity_view_modes($type);
454

  
455
  foreach ($ds_vm as $key => $item) {
456
    $overriden = (!empty($view_mode_settings[$key]['custom_settings']) ? TRUE : FALSE);
457
    if ($overriden) {
458
      $view_modes[$key] = $item['label'];
459
    }
460
  }
461

  
462
  return $view_modes;
463
}
464

  
414 465
/**
415 466
 * Ajax callback for _ds_field_ui_table_layouts_preview().
416 467
 */
......
606 657
      $contexts = array();
607 658
      $id = (arg(0) == 'taxonomy') ? arg(2) : arg(1);
608 659
      $entity = entity_load($entity_type, array($id));
609
      ds_create_entity_context($entity_type, $entity[$id], $contexts);
610
      $title = $layout['settings']['page_option_title'];
611
      $title = filter_xss_admin(ctools_context_keyword_substitute($title, array(), $contexts));
612
      $page_title['title'] = $title;
613
      $page_title['head_title'] = $title;
660
      if (isset($entity[$id])) {
661
        ds_create_entity_context($entity_type, $entity[$id], $contexts);
662
        $title = $layout['settings']['page_option_title'];
663
        $title = filter_xss_admin(ctools_context_keyword_substitute($title, array(), $contexts));
664
        $page_title['title'] = t($title);
665
        $page_title['head_title'] = t($title);
666
      }
614 667
    }
615 668
  }
616 669

  
......
771 824
  }
772 825

  
773 826
  // Render items.
827
  $item_count = count($variables['items']);
828
  $item_index = 0;
774 829
  foreach ($variables['items'] as $delta => $item) {
775 830
    // Field item wrapper.
776 831
    if (isset($config['fi'])) {
......
781 836
      if (!empty($config['fi-cl'])) {
782 837
        $class[] = $config['fi-cl'];
783 838
      }
839
      if(!empty($config['fi-first-last']) && $item_index == 0) {
840
        $class[] = "first";
841
      }
842
      if(!empty($config['fi-first-last']) && $item_index == $item_count - 1) {
843
        $class[] = "last";
844
      }
784 845
      $class = !empty($class) ? ' class="'. token_replace(implode(' ', $class), array($variables['element']['#entity_type'] => $variables['element']['#object']), array('clear' => TRUE)) .'"' : '';
785 846
      $attributes = array();
786 847
      if (!empty($config['fi-at'])) {
......
800 861
    if (isset($config['fi'])) {
801 862
      $output .= '</' . $config['fi-el'] . '>';
802 863
    }
864
    ++$item_index;
803 865
  }
804 866

  
805 867
  // Closing field items wrapper.
......
934 996
          // Odd even class.
935 997
          if ($wrapper_key == 'fi') {
936 998
            $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-odd-even'] = !(empty($values[$wrapper_key . '-odd-even'])) ? TRUE : FALSE;
999
            $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-first-last'] = !(empty($values[$wrapper_key . '-first-last'])) ? TRUE : FALSE;
937 1000
          }
938 1001
        }
939 1002
      }
......
1036 1099

  
1037 1100
  foreach ($fields as $field) {
1038 1101
    if (isset($variables['ds-config'][$field])) {
1039
      $variables['ds-config'][$field] = filter_xss($variables['ds-config'][$field]);
1102
      $variables['ds-config'][$field] = filter_xss_admin($variables['ds-config'][$field]);
1040 1103
    }
1041 1104
  }
1042 1105
}

Formats disponibles : Unified diff