8.3.x ConfigEntityBundleBase.php public ConfigEntityBundleBase::preSave(EntityStorageInterface $storage)
8.0.x ConfigEntityBundleBase.php public ConfigEntityBundleBase::preSave(EntityStorageInterface $storage)
8.1.x ConfigEntityBundleBase.php public ConfigEntityBundleBase::preSave(EntityStorageInterface $storage)
8.2.x ConfigEntityBundleBase.php public ConfigEntityBundleBase::preSave(EntityStorageInterface $storage)
8.4.x ConfigEntityBundleBase.php public ConfigEntityBundleBase::preSave(EntityStorageInterface $storage)

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 ConfigEntityBase::preSave

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php, line 82

Class

ConfigEntityBundleBase
A base class for config entity types that act as bundles.

Namespace

Drupal\Core\Config\Entity

Code

public function preSave(EntityStorageInterface $storage) {
  parent::preSave($storage);

  // Only handle renames, not creations.
  if (!$this->isNew() && $this->getOriginalId() !== $this->id()) {
    $bundle_type = $this->getEntityType();
    $bundle_of = $bundle_type->getBundleOf();
    if (!empty($bundle_of)) {
      throw new ConfigNameException("The machine name of the '{$bundle_type->getLabel()}' bundle cannot be changed.");
    }
  }
}