public function ConfigEntityBundleBase::preSave

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.");
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!ConfigEntityBundleBase.php/function/ConfigEntityBundleBase::preSave/8.1.x