Projet

Général

Profil

Révision 9df8b457

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views_bulk_operations/views_bulk_operations.module
41 41
  // The list of VBO actions is fairly static, so it's hardcoded for better
42 42
  // performance (hitting the filesystem with file_scan_directory(), and then
43 43
  // caching the result has its cost).
44
  $path = drupal_get_path('module', 'views_bulk_operations') . '/actions/';
45 44
  $files = array(
46
    'archive.action.inc',
47
    'argument_selector.action.inc',
48
    'book.action.inc',
49
    'delete.action.inc',
50
    'modify.action.inc',
51
    'script.action.inc',
52
    'user_roles.action.inc',
53
    'user_cancel.action.inc',
45
    'archive.action',
46
    'argument_selector.action',
47
    'book.action',
48
    'delete.action',
49
    'modify.action',
50
    'script.action',
51
    'user_roles.action',
52
    'user_cancel.action',
54 53
  );
55 54

  
56 55
  if (!$loaded) {
57 56
    foreach ($files as $file) {
58
      include_once $path . $file;
57
      module_load_include('inc', 'views_bulk_operations', 'actions/' . $file);
59 58
    }
60 59
    $loaded = TRUE;
61 60
  }
......
77 76
function views_bulk_operations_cron() {
78 77
  db_delete('queue')
79 78
    ->condition('name', db_like('views_bulk_operations_active_queue_'), 'LIKE')
80
    ->condition('created', REQUEST_TIME - 864000, '<')
79
    ->condition('created', REQUEST_TIME - 86400, '<')
81 80
    ->execute();
82 81
}
83 82

  
......
358 357
 */
359 358
function views_bulk_operations_views_post_build(&$view) {
360 359
  $vbo = _views_bulk_operations_get_field($view);
361
  if ($vbo && $vbo->get_selected_operations() < 1) {
360
  if ($vbo && count($vbo->get_selected_operations()) < 1) {
362 361
    $vbo->options['exclude'] = TRUE;
363 362
  }
364 363
}
......
420 419
    if ($enable_select_all_pages) {
421 420
      $form['select_all']['or'] = array(
422 421
        '#type' => 'markup',
423
        '#markup' => '<em>OR</em>',
422
        '#markup' => '<em>' . t('OR') . '</em>',
424 423
      );
425 424
      $form['select_all']['all_pages'] = array(
426 425
        '#type' => 'checkbox',
......
443 442
 */
444 443
function views_bulk_operations_form($form, &$form_state, $vbo) {
445 444
  $form['#attached']['js'][] = drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.js';
445
  $form['#attached']['js'][] = array(
446
    'data' => array('vbo' => array(
447
      'row_clickable' => $vbo->get_vbo_option('row_clickable'),
448
    )),
449
    'type' => 'setting',
450
  );
451

  
446 452
  $form['#attached']['css'][] = drupal_get_path('module', 'views_bulk_operations') . '/css/views_bulk_operations.css';
447 453
  // Wrap the form in a div with specific classes for JS targeting and theming.
448 454
  $class = 'vbo-views-form';
......
595 601
  $operation = $form_state['operation'];
596 602
  $rows = $form_state['selection'];
597 603
  $query = drupal_get_query_parameters($_GET, array('q'));
604
  $title = t('Are you sure you want to perform %operation on the selected items?', array('%operation' => $operation->label()));
598 605
  $form = confirm_form($form,
599
    t('Are you sure you want to perform %operation on the selected items?', array('%operation' => $operation->label())),
606
    $title,
600 607
    array('path' => $view->get_url(), 'query' => $query),
601 608
    theme('views_bulk_operations_confirmation', array('rows' => $rows, 'vbo' => $vbo, 'operation' => $operation, 'select_all_pages' => $form_state['select_all_pages']))
602 609
  );
603 610
  // Add VBO's submit handler to the Confirm button added by config_form().
604 611
  $form['actions']['submit']['#submit'] = array('views_bulk_operations_form_submit');
605 612

  
613
  // We can't set the View title here as $view is just a copy of the original,
614
  // and our settings changes won't "stick" for the first page load of the
615
  // confirmation form. We also can't just call drupal_set_title() directly
616
  // because our title will be clobbered by the actual View title later. So
617
  // let's tuck the title away in the form for use later.
618
  // @see views_bulk_operations_preprocess_views_view()
619
  $form['#vbo_confirm_form_title'] = $title;
620

  
606 621
  return $form;
607 622
}
608 623

  
......
618 633
  // Load the entities from the current page, and show their titles.
619 634
  $entities = _views_bulk_operations_entity_load($entity_type, array_values($rows), $vbo->revision);
620 635
  foreach ($entities as $entity) {
621
    $items[] = check_plain(_views_bulk_operations_entity_label($entity_type, $entity));
636
    $items[] = check_plain(entity_label($entity_type, $entity));
622 637
  }
623 638
  // All rows on all pages have been selected, so show a count of additional items.
624 639
  if ($select_all_pages) {
......
631 646
  return $output;
632 647
}
633 648

  
649
/**
650
 * Implements hook_preprocess_page().
651
 *
652
 * Hide action links on the configure and confirm pages.
653
 */
654
function views_bulk_operations_preprocess_page(&$variables) {
655
  if (isset($_POST['select_all'], $_POST['operation'])) {
656
    $variables['action_links'] = array();
657
  }
658
}
659

  
660
/**
661
 * Implements hook_preprocess_views_view().
662
 */
663
function views_bulk_operations_preprocess_views_view($variables) {
664
  // If we've stored a title for the confirmation form, retrieve it here and
665
  // retitle the View.
666
  // @see views_bulk_operations_confirm_form()
667
  if (array_key_exists('rows', $variables) && is_array($variables['rows']) && array_key_exists('#vbo_confirm_form_title', $variables['rows'])) {
668
    $variables['view']->set_title($variables['rows']['#vbo_confirm_form_title']);
669
  }
670
}
671

  
634 672
/**
635 673
 * Goes through the submitted values, and returns
636 674
 * an array of selected rows, in the form of
......
871 909
      'views_row' => array(),
872 910
      'position' => array(
873 911
        'current' => ++$context['sandbox']['progress'],
874
        'total' => $view->total_rows,
912
        'total' => $context['sandbox']['max'],
875 913
      ),
876 914
    );
877 915
    // Some operations require full selected rows.
......
1042 1080
      $arguments = array(
1043 1081
        '%operation' => $operation->label(),
1044 1082
        '@type' => $entity_type,
1045
        '%title' => _views_bulk_operations_entity_label($entity_type, $entity),
1083
        '%title' => entity_label($entity_type, $entity),
1046 1084
      );
1047 1085

  
1048 1086
      if ($log) {
......
1128 1166
        $context['results']['log'][] = t('Skipped %operation on @type %title due to insufficient permissions.', array(
1129 1167
          '%operation' => $operation->label(),
1130 1168
          '@type' => $entity_type,
1131
          '%title' => _views_bulk_operations_entity_label($entity_type, $entity),
1169
          '%title' => entity_label($entity_type, $entity),
1132 1170
        ));
1133 1171
        unset($entities[$id]);
1134 1172
      }
......
1236 1274
  return $entities;
1237 1275
}
1238 1276

  
1239
/**
1240
 * Label function for entities.
1241
 * Core entities don't declare the "label" key, so entity_label() fails,
1242
 * and a fallback is needed. This function provides that fallback.
1243
 */
1244
function _views_bulk_operations_entity_label($entity_type, $entity) {
1245
  $label = entity_label($entity_type, $entity);
1246
  if (!$label) {
1247
    $entity_info = entity_get_info($entity_type);
1248
    $id_key = $entity_info['entity keys']['id'];
1249
    // Many entity types (e.g. "user") have a name which fits the label perfectly.
1250
    if (isset($entity->name)) {
1251
      $label = $entity->name;
1252
    }
1253
    elseif (isset($entity->{$id_key})) {
1254
      // Fallback to the id key.
1255
      $label = $entity->{$id_key};
1256
    }
1257
  }
1258

  
1259
  return $label;
1260
}
1261

  
1262 1277
/**
1263 1278
 * Helper function to report an error.
1264 1279
 */

Formats disponibles : Unified diff