function FileUsageBase::add

Same name in other branches
  1. 9 core/modules/file/src/FileUsage/FileUsageBase.php \Drupal\file\FileUsage\FileUsageBase::add()
  2. 10 core/modules/file/src/FileUsage/FileUsageBase.php \Drupal\file\FileUsage\FileUsageBase::add()
  3. 11.x core/modules/file/src/FileUsage/FileUsageBase.php \Drupal\file\FileUsage\FileUsageBase::add()

Overrides FileUsageInterface::add

1 call to FileUsageBase::add()
DatabaseFileUsageBackend::add in core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php
Records that a module is using a file.
3 methods override FileUsageBase::add()
DatabaseFileUsageBackend::add in core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php
Records that a module is using a file.
TestFileUsage::add in core/modules/file/tests/src/Unit/LegacyFileTest.php
Records that a module is using a file.
TestFileUsage::add in core/modules/system/tests/modules/service_provider_test/src/TestFileUsage.php
Records that a module is using a file.

File

core/modules/file/src/FileUsage/FileUsageBase.php, line 45

Class

FileUsageBase
Defines the base class for database file usage backend.

Namespace

Drupal\file\FileUsage

Code

public function add(FileInterface $file, $module, $type, $id, $count = 1) {
    // Make sure that a used file is permanent.
    if (!$file->isPermanent()) {
        $file->setPermanent();
        $file->save();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.