=== modifié fichier sites/all/modules/VIEWS/views_field_view/views_field_view.info
--- sites/all/modules/VIEWS/views_field_view/views_field_view.info	2013-06-06 15:28:33 +0000
+++ sites/all/modules/VIEWS/views_field_view/views_field_view.info	2013-07-04 15:14:05 +0000
@@ -7,6 +7,7 @@
 dependencies[] = views
 
 files[] = views_field_view_handler_field_view.inc
+files[] = views_field_view_handler_field_view_count.inc
 files[] = tests/views_field_view.test
 ; Information added by drupal.org packaging script on 2013-05-25
 version = "7.x-1.1"

=== modifié fichier sites/all/modules/VIEWS/views_field_view/views_field_view.views.inc
--- sites/all/modules/VIEWS/views_field_view/views_field_view.views.inc	2012-06-19 09:56:42 +0000
+++ sites/all/modules/VIEWS/views_field_view/views_field_view.views.inc	2013-07-04 14:57:57 +0000
@@ -14,6 +14,11 @@
     'help' => t('Embed a view as a field. This can cause slow performance, so enable some caching.'),
     'handler' => 'views_field_view_handler_field_view',
   );
+  $data['views']['count']['field'] = array(
+    'title' => t('Count'),
+    'help' => t('Embed a view results count as a field. This can cause slow performance, so enable some caching.'),
+    'handler' => 'views_field_view_handler_field_view_count',
+  );
   $data['views']['view_field'] = array(
     'title' => t('View (Views field view)'),
     'help' => t('Embed a view in an area. This can cause slow performance, so enable some caching.'),

=== ajouté(e) fichier sites/all/modules/VIEWS/views_field_view/views_field_view_handler_field_view_count.inc
--- sites/all/modules/VIEWS/views_field_view/views_field_view_handler_field_view_count.inc	1970-01-01 00:00:00 +0000
+++ sites/all/modules/VIEWS/views_field_view/views_field_view_handler_field_view_count.inc	2013-07-08 10:00:44 +0000
@@ -1,0 +1,102 @@
+<?php
+
+/**
+ * @file
+ * Views field view count field handler class.
+ */
+
+class views_field_view_handler_field_view_count extends views_field_view_handler_field_view {
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['suffix'] = array(
+      'default' => '',
+      'translatable' => TRUE,
+    );
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    $form['suffix'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Suffix'),
+      '#default_value' => $this->options['suffix'],
+      '#description' => t('Text to put after the count.'),
+    );
+    parent::options_form($form, $form_state);
+
+    // Not sure we'll able to aggregate count queries easily, so remove that 
+    // feature for now.
+    unset($form['query_aggregation']);
+  }
+
+  function render($values) {
+    // Most of the code is from the parent class' function.
+    $output = NULL;
+    // If it's not a field handler and there are no values
+    // Get the first result row from the view and use that.
+    if (($this->handler_type !== 'field') && empty($values) && isset($this->view->result)) {
+      $values = reset($this->view->result);
+    }
+
+    static $running = array();
+    // Protect against the evil / recursion.
+    // Set the variable for yourself, this is not for the normal "user".
+    if (empty($running[$this->options['view']][$this->options['display']]) || variable_get('views_field_view_evil', FALSE)) {
+      if ($this->options['view'] && !$this->options['query_aggregation']) {
+        $running[$this->options['view']][$this->options['display']] = TRUE;
+        $args = array();
+
+        // Only perform this loop if there are actually arguments present.
+        if (!empty($this->options['arguments'])) {
+          // Create array of tokens.
+          foreach ($this->split_tokens($this->options['arguments']) as $token) {
+            $args[] = $this->get_token_value($token, $values, $this->view);
+          }
+        }
+
+        // get view etc… and execute.
+        $view = views_get_view($this->options['view']);
+
+        // Only execute and render the view if the user has access.
+        if ($view->access($this->options['display'])) {
+          $view->set_display($this->options['display']);
+          $view->pre_execute($args);
+          
+          // Here's the code to get the result count.
+          $view->build($this->options['display']);
+          // ATM we only handle the default views query backend.
+          if (!is_a($view->query, 'views_plugin_query_default')) {
+            $output = t('Sorry, unsupported query backend.');
+          }
+          else {
+            // Some of these lines might be useless.
+            $view->query->build($view);
+            $count_query = $view->build_info['count_query'];
+            $count_query->addMetaData('view', $view);
+            $count_query->preExecute();
+            $count_query = $count_query->countQuery();
+            $count = $count_query->execute()->fetchField();
+            $output = ($count ? $count . $this->sanitize_value($this->options['suffix'], 'xss') : '');
+          }
+        }
+
+        $running[$this->options['view']][$this->options['display']] = FALSE;
+      }
+    }
+    else {
+      $output = t('Recursion, stop!');
+    }
+
+    // We only add the output to the $values object for field handlers. Area
+    // handlers will not use this.
+    if (($this->handler_type == 'field') && !empty($output)) {
+      // Add the rendered output back to the $values object so it is available
+      // in $view->result objects.
+      $values->{'views_field_view_' . $this->options['id']} = $output;
+    }
+
+    return $output;
+  }
+
+} // views_field_view_handler_field_view_count.

