$this->query->addField(NULL, 'file_download_count', 'file_download_count') $this->query->addRelationship('download_data', $join, 'file_managed') $join = \Drupal::service('')->createInstance('standard', $joinDefinition) Create a join object and create a relationship between the main query and the subquery. Add the subquery to as a component of a join. $subQuery->groupBy("download_count.fid") $subQuery->addExpression("COUNT(fid)", 'file_download_count') $subQuery->addField('download_count', 'fid') select('download_count', 'download_count') The full file path to my plugin is my_module/src/Plugin/views/field/FileDownloadCount.php. It's the annotation at the class level that let's Views know about this field, so that bit is quite important. The following is a class called FileDownloadCount that extends the default NumericField Views field. To create a field handler plugin you need to create a class at the location my_module/src/Plugin/views/field. The best way to do this is to create a View field handler that will create a subquery as part of the field setup. After some investigation I knew that I needed to create a subquery to inject the value of the download count into the output of the View. Whilst it does come with some Views integration, I had a couple of other relationships added that caused the download count to be incorrect. This module records the action of a user downloading a file on your site. I had this problem in a View I was working on the other day that incorporated data from the Download Count module. Ultimately, you need to remove this join, but you really need that data included in your results.Ĭreating a subquery can allow you to pull out data from a specific field without adding another join that would cause the results to be out. After looking at the generated SQL query you see that there is a problem with one of the joins which causes your counts to be off a little. A Drupal View you are working on looks great and has all the data and fields you need, but when you look a little closer at the results you realise that something is off. To count downloads of an attachment from node or media page, select File with Download Statistics recorded as Format in Manage Display tab for a particular entity type.įinally, set the necessary permissions so that the counter is visible to the users.You've probably been there before. To use the enabled download counter on a particular Views page or block display, select File URI with Download Count as URI Formatter type in Views UI. On the same settings page you can clear the file downloads table if desired. To enable/disable the file downloads count, navigate to Download Statistics Settings page at /admin/config/system/download-statistics. Once you setup your files to go to a private directory, you can use the block from the module or you can build your own block with the views to show the attachments and their downloads right on a node page. If the upload destination is "Public files", the web server sends the file to client browser directly, bypassing Drupal code, and counting downloads is impossible. The private directory has to be configured in settings.php. In the "Field settings" tab of the file upload field definition, make sure you select Upload destination: Private files. The important configuration step for this module to be able to count downloads - as for any other module that controls or monitors files access - is to setup the "private" directory for the uploaded files. The module provides extensive Views support: the views fields for Total File Downloads count, File Downloads Today count and Most Recent File Download timestamp. The block can be added to any region of your theme and it allows to configure the number of most recent downloaded files to display, the number of all time downloads to display and the number of day's top downloads to display. It provides a customisable "Popular file downloads" block that displays the most downloaded files today and for all time, and the last files downloaded. The file download statistics are useful in determining which files visitors most often download from your site. The Download Statistics module extends functionality of the core Statistics module and provides for Drupal 8/9 some file download statistics functionality that was available in Drupal 7 through Download Count module.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |