function Block::preSave

Same name in other branches
  1. 9 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::preSave()
  2. 8.9.x core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::preSave()
  3. 10 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::preSave()

Overrides ConfigEntityBase::preSave

File

core/modules/block/src/Entity/Block.php, line 348

Class

Block
Defines a Block configuration entity class.

Namespace

Drupal\block\Entity

Code

public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    if (!is_int($this->weight)) {
        @trigger_error('Saving a block with a non-integer weight is deprecated in drupal:11.1.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3462474', E_USER_DEPRECATED);
        $this->setWeight((int) $this->weight);
    }
    // Ensure the region is valid to mirror the behavior of block_rebuild().
    // This is done primarily for backwards compatibility support of
    // \Drupal\block\BlockInterface::BLOCK_REGION_NONE.
    $regions = system_region_list($this->theme);
    if (!isset($regions[$this->region]) && $this->status()) {
        $this->setRegion(system_default_region($this->theme))
            ->disable();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.