public function ConfigEntityBundleBase::preSave in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php \Drupal\Core\Config\Entity\ConfigEntityBundleBase::preSave()
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\EntityCode
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.");
}
}
}