0

I'm working on a Drupal 9 website displaying custom table data and I need to provide CSV/XLS export links for it.
For the moment, I've defined a view consuming the custom table data thanks to the Views Custom Table module and it works fine. I've installed the Views Data Export module and configured a display to export data as CSV. This display is attached to the base display.
The CSV button is show on the view, and when I'm logged in as admin, everything works fine. When I'm just an authenticated user, and I click on the button, the display attached to the CSV export is rendered and exported in CSV (so there is all the HTML in the file).

I think it is a permission issue: Export uses REST core module and this one is performing permission check on the entity (for example, user is able to access the entity). In my view, there is no entity because data comes from the View Custom Table module (through hook_data()).

I'm not sure if there is a simple solution, or if I need to define my own endpoint (and find a solution to keep exposed filters). Moreover, the Views Data Export PHPExcel module is not available for Drupal 8 and Drupal 9.

1 Answer 1

1

If what you have done works when logged in as user 1 (Adminstrator), then that sounds like you need to tweak certain permissions and clear cache for it to take effect for the other "users" or "roles".

To test it out, i would create a test user and a role called "test role". Then make sure, you assign the test user to the test role. Then make sure, you give the "test role" what the module requires.... i see below in docs of view export table

You can also check if authenticated user/role has the following checked for it, if you don't want create the test user/role(/admin/people/permissions).

The below permissions come with the module, i suppose and you will see if after module install and cache clear etc.

  • Configure user permissions in Administration » People » Permissions:

    • Add custom table in views

      Give user access to add his custom table to the system.

    • Administer all custom table in views

      Give user access to administer all the custom tables, added by all the users

    • Administer own custom table in views

      Give user access to administer own custom tables

  • Manage custom tables in Administration » Structure » Views » View Custom Table men

Also, double check you have this configs for the data export module (specially #8)

Finally, login as the "test user" and check out out.

Check the logs if certain steps are not working (admin/reports/dblog)

3
  • Thanks for your help @salah-1 ! The permissions of Views Custom Table only deal with custom tables definition in the backoffice, not with the export. But to be sure, I've done what you said and checked every permissions for an authenticated user. But the problem is still there (after clearing the cache) :/ When I check the logs, I see a notice : Notice : Undefined index: #content_type dans Drupal\views_data_export\Plugin\views\display\DataExport::buildStandard() (/home/a-adamezyk/dev/orange-cmu/web/modules/contrib/views_data_export/src/Plugin/views/display/DataExport.php ligne 190)
    – Aurel
    May 13 at 7:52
  • Do you have some kind of array? the error is pointing to undefined array index. Did you write that code? /home/a-adamezyk/dev/orange-cmu/web/modules/contrib/views_data_export/src/Plugin/views/display/DataExport.php? if so look at line 190. If you didn't write that code, then look closely as the content type or fields you defined.
    – salah-1
    May 13 at 21:26
  • I have an array. For the admin, it contains the content_type + csv data. For authenticated user, no content_type and no csv data. I did not write this code, it is from views data export module. In this module, I see that a line is returning the good data for the admin, but not for other roles : $output = (string) $renderer->renderRoot($build); But I'm not able to understand why...
    – Aurel
    May 16 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.