function FileSelection::createNewEntity

Same name in other branches
  1. 8.9.x core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php \Drupal\file\Plugin\EntityReferenceSelection\FileSelection::createNewEntity()
  2. 10 core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php \Drupal\file\Plugin\EntityReferenceSelection\FileSelection::createNewEntity()
  3. 11.x core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php \Drupal\file\Plugin\EntityReferenceSelection\FileSelection::createNewEntity()

Overrides DefaultSelection::createNewEntity

File

core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php, line 40

Class

FileSelection
Provides specific access control for the file entity type.

Namespace

Drupal\file\Plugin\EntityReferenceSelection

Code

public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
    $file = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
    // In order to create a referenceable file, it needs to have a "permanent"
    // status.
    
    /** @var \Drupal\file\FileInterface $file */
    $file->setPermanent();
    return $file;
}

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