system_default_region example

block_rebuild();

    // Reload block entities.     $block1 = Block::load($block1->id());
    $block2 = Block::load($block2->id());

    $messages = \Drupal::messenger()->all();
    \Drupal::messenger()->deleteAll();
    $expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block1->id(), '%region' => 'INVALID'])]];
    $this->assertEquals($expected$messages);

    $default_region = system_default_region('stark');
    $this->assertSame($default_region$block1->getRegion());
    $this->assertFalse($block1->status());
    $this->assertSame($default_region$block2->getRegion());
    $this->assertFalse($block2->status());
  }

}

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

    // 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();
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.