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.");
    }
  }
}
doc_Drupal
2016-10-29 08:52:38
Comments
Leave a Comment

Please login to continue.