Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 9 Module Development

You're reading from   Drupal 9 Module Development Get up and running with building powerful Drupal modules and applications

Arrow left icon
Product type Paperback
Published in Aug 2020
Publisher Packt
ISBN-13 9781800204621
Length 626 pages
Edition 3rd Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Daniel Sipos Daniel Sipos
Author Profile Icon Daniel Sipos
Daniel Sipos
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Chapter 1: Developing for Drupal 9 2. Chapter 2: Creating Your First Module FREE CHAPTER 3. Chapter 3: Logging and Mailing 4. Chapter 4: Theming 5. Chapter 5: Menus and Menu Links 6. Chapter 6: Data Modeling and Storage 7. Chapter 7: Your Own Custom Entity and Plugin Types 8. Chapter 8: The Database API 9. Chapter 9: Custom Fields 10. Chapter 10: Access Control 11. Chapter 11: Caching 12. Chapter 12: JavaScript and the Ajax API 13. Chapter 13: Internationalization and Languages 14. Chapter 14: Batches, Queues, and Cron 15. Chapter 15: Views 16. Chapter 16: Working with Files and Images 17. Chapter 17: Automated Testing 18. Chapter 18: Drupal Security 19. Other Books You May Enjoy

Working with unmanaged files

Working with unmanaged files is actually pretty similar to doing so with managed files, except that they are not tracked in the database using the File entity type. There is a set of helper functions similar to what we've seen for managed files that can be accessed through the FileSystem service I mentioned earlier. Let's see some examples.

To save a new file, we do almost like we did before with managed files:

$image = file_get_contents('products://tv.jpg'); 
// Load the service statically for quick demonstration. 
$file_system = \Drupal::service('file_system'); 
$path = $file_system->saveData($image, 'public://tv.jpg', FileSystemInterface::EXISTS_REPLACE);

We load the file data from wherever and use the saveData() method on the service the same way as we did file_save_data(). The difference is that the file is going to be saved but no database record is created. So the only way to use it is to rely on...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime