You are here

public function PathAliasStorage::createWithSampleValues in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/path_alias/src/PathAliasStorage.php \Drupal\path_alias\PathAliasStorage::createWithSampleValues()

Creates an entity with sample field values.

Parameters

string|bool $bundle: (optional) The entity bundle.

array $values: (optional) Any default values to use during generation.

Return value

\Drupal\Core\Entity\FieldableEntityInterface A fieldable content entity.

Throws

\Drupal\Core\Entity\EntityStorageException Thrown if the bundle does not exist or was needed but not specified.

Overrides ContentEntityStorageBase::createWithSampleValues

File

core/modules/path_alias/src/PathAliasStorage.php, line 44

Class

PathAliasStorage
Defines the storage handler class for path_alias entities.

Namespace

Drupal\path_alias

Code

public function createWithSampleValues($bundle = FALSE, array $values = []) {
  $entity = parent::createWithSampleValues($bundle, [
    'path' => '/<front>',
  ] + $values);

  // Ensure the alias is only 255 characters long.
  $entity
    ->set('alias', substr('/' . $entity
    ->get('alias')->value, 0, 255));
  return $entity;
}