You are here

public function FileSelection::createNewEntity in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php \Drupal\file\Plugin\EntityReferenceSelection\FileSelection::createNewEntity()

Creates a new entity object that can be used as a valid reference.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle name.

string $label: The entity label.

int $uid: The entity owner ID, if the entity type supports it.

Return value

\Drupal\Core\Entity\EntityInterface An unsaved entity object.

Overrides DefaultSelection::createNewEntity

File

core/modules/file/src/Plugin/EntityReferenceSelection/FileSelection.php, line 44
Contains \Drupal\file\Plugin\EntityReferenceSelection\FileSelection.

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;
}