You are here

public function EntityFormWizardBase::initValues in Chaos Tool Suite (ctools) 8.3

Initialize wizard values.

Return mixed.

Overrides FormWizardBase::initValues

File

src/Wizard/EntityFormWizardBase.php, line 72

Class

EntityFormWizardBase
The base class for all entity form wizards.

Namespace

Drupal\ctools\Wizard

Code

public function initValues() {
  $storage = $this->entityTypeManager
    ->getStorage($this
    ->getEntityType());
  if ($this
    ->getMachineName()) {
    $values = $this
      ->getTempstore()
      ->get($this
      ->getMachineName());
    if (!$values) {
      $entity = $storage
        ->load($this
        ->getMachineName());
      $values[$this
        ->getEntityType()] = $entity;
      $values['id'] = $entity
        ->id();
      $values['label'] = $entity
        ->label();
    }
  }
  else {
    $entity = $storage
      ->create([]);
    $values[$this
      ->getEntityType()] = $entity;
  }
  $event = new WizardEvent($this, $values);
  $this->dispatcher
    ->dispatch(FormWizardInterface::LOAD_VALUES, $event);
  return $event
    ->getValues();
}