Skip to main content
Became Hot Network Question
removed "Drupal" from the title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Override Drupal'sthe default rules for private file access

Situation:

  • My private files directory is outside the document root.
  • A content type chapter includes a file field pdf that stores its files in the private files directory.
  • When a given chapter node is published, its pdf file is accessible to users via mysite/system/files/filename.pdf. This is expected; it's the way private file access works in Drupal.
  • If a given chapter node is unpublished, its pdf file is not accessible to non-priviledged users. They get an access denied page. Again, this is expected.

Problem:In the site I am developing, the private files directory is outside the document root.
I have a content type (Chapter) with a file field that stores its files in the private files directory. When a Chapter node is published, its file is accessible to users, but when the node is unpublished, its file is not accessible to users. They get an access denied page.

  • I want to control access to the pdf file for a chapter node based on values in certain fields of the node as well as on user permissions and other conditions.

Question:How can I control the access to the attached file and allow users to access the attached file when the node is unpublished, in a custom module?

  • Using a custom module, how can I override the default handling of private files to control when a file is accessible? I can write the code to make the checks; I don't know how to override the default handler. Since some aspects of file handling have changed in Drupal 9, I'll mention that this is the version I'm using, in case it matters.

Override Drupal's default rules for private file access

Situation:

  • My private files directory is outside the document root.
  • A content type chapter includes a file field pdf that stores its files in the private files directory.
  • When a given chapter node is published, its pdf file is accessible to users via mysite/system/files/filename.pdf. This is expected; it's the way private file access works in Drupal.
  • If a given chapter node is unpublished, its pdf file is not accessible to non-priviledged users. They get an access denied page. Again, this is expected.

Problem:

  • I want to control access to the pdf file for a chapter node based on values in certain fields of the node as well as on user permissions and other conditions.

Question:

  • Using a custom module, how can I override the default handling of private files to control when a file is accessible? I can write the code to make the checks; I don't know how to override the default handler. Since some aspects of file handling have changed in Drupal 9, I'll mention that this is the version I'm using, in case it matters.

Override the default private file access

In the site I am developing, the private files directory is outside the document root.
I have a content type (Chapter) with a file field that stores its files in the private files directory. When a Chapter node is published, its file is accessible to users, but when the node is unpublished, its file is not accessible to users. They get an access denied page.

How can I control the access to the attached file and allow users to access the attached file when the node is unpublished, in a custom module?

Source Link

Override Drupal's default rules for private file access

Situation:

  • My private files directory is outside the document root.
  • A content type chapter includes a file field pdf that stores its files in the private files directory.
  • When a given chapter node is published, its pdf file is accessible to users via mysite/system/files/filename.pdf. This is expected; it's the way private file access works in Drupal.
  • If a given chapter node is unpublished, its pdf file is not accessible to non-priviledged users. They get an access denied page. Again, this is expected.

Problem:

  • I want to control access to the pdf file for a chapter node based on values in certain fields of the node as well as on user permissions and other conditions.

Question:

  • Using a custom module, how can I override the default handling of private files to control when a file is accessible? I can write the code to make the checks; I don't know how to override the default handler. Since some aspects of file handling have changed in Drupal 9, I'll mention that this is the version I'm using, in case it matters.