You are here

public static function Newsletter::preCreate in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/Newsletter.php \Drupal\simplenews\Entity\Newsletter::preCreate()
  2. 8 src/Entity/Newsletter.php \Drupal\simplenews\Entity\Newsletter::preCreate()

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.

Overrides EntityBase::preCreate

File

src/Entity/Newsletter.php, line 157

Class

Newsletter
Defines the simplenews newsletter entity.

Namespace

Drupal\simplenews\Entity

Code

public static function preCreate(EntityStorageInterface $storage, array &$values) {
  $config = \Drupal::config('simplenews.settings');
  $values += [
    'format' => $config
      ->get('newsletter.format'),
    'priority' => $config
      ->get('newsletter.priority'),
    'receipt' => $config
      ->get('newsletter.receipt'),
    'from_name' => $config
      ->get('newsletter.from_name'),
    'from_address' => $config
      ->get('newsletter.from_address'),
  ];
  parent::preCreate($storage, $values);
}