You are here

public function YamlForm::preSave in YAML Form 8

Acts on an entity before the presave hook is invoked.

Used before the entity is saved and before invoking the presave hook.

Ensure that config entities which are bundles of other entities cannot have their ID changed.

Parameters

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

Throws

\Drupal\Core\Config\ConfigNameException Thrown when attempting to rename a bundle entity.

Overrides ConfigEntityBundleBase::preSave

File

src/Entity/YamlForm.php, line 1177

Class

YamlForm
Defines the form entity.

Namespace

Drupal\yamlform\Entity

Code

public function preSave(EntityStorageInterface $storage) {

  // Always unpublish templates.
  if ($this
    ->isTemplate()) {
    $this
      ->setStatus(FALSE);
  }

  // Serialize elements array to YAML.
  if (is_array($this->elements)) {
    $this->elements = Yaml::encode($this->elements);
  }
  parent::preSave($storage);
}