Projet

Général

Profil

Révision 59ae487e

Ajouté par Assos Assos il y a presque 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/file_entity/views/views_handler_field_file_link_usage.inc
12 12
 */
13 13
class views_handler_field_file_link_usage extends views_handler_field_file_link {
14 14

  
15
  /**
16
   * {@inheritdoc}
17
   */
18
  function option_definition() {
19
    $options = parent::option_definition();
20
    $options['count_entities_once'] = array('default' => TRUE);
21
    return $options;
22
  }
23

  
24
  /**
25
   * {@inheritdoc}
26
   */
27
  function options_form(&$form, &$form_state) {
28
    $form['count_entities_once'] = array(
29
      '#type' => 'checkbox',
30
      '#title' => t('Count each unique entity once'),
31
      '#description' => t('Files can be used multiple times for an entity, especially when an entity is revisionable.'),
32
      '#default_value' => !empty($this->options['count_entities_once']),
33
    );
34
    parent::options_form($form, $form_state);
35
  }
36

  
15 37
  /**
16 38
   * Renders the link.
17 39
   */
......
27 49

  
28 50
    // Get total count for each file.
29 51
    $total_count = 0;
30
    foreach (file_usage_list($file) as $module => $usage) {
52
    $file_usage = file_usage_list($file);
53
    $count_entities_once = !empty($this->options['count_entities_once']);
54
    foreach ($file_usage as $module => $usage) {
31 55
      foreach ($usage as $entity_type => $entity_ids) {
32
        foreach ($entity_ids as $id => $count) {
33
          $total_count += $count;
56
        if ($count_entities_once) {
57
          // Just count each unique entity once.
58
          $total_count += count($entity_ids);
59
        }
60
        else {
61
          // Count multiple usages for each entity.
62
          foreach ($entity_ids as $id => $count) {
63
            $total_count += $count;
64
          }
34 65
        }
35 66
      }
36 67
    }

Formats disponibles : Unified diff