You are here

protected function RLayoutFormController::prepareEntity in Layout 8

Overrides Drupal\Core\Entity\EntityFormController::prepareEntity().

Prepares the layout object filling in a few default values.

File

lib/Drupal/rlayout/RLayoutFormController.php, line 24
Definition of Drupal\rlayout\RLayoutFormController.

Class

RLayoutFormController
Form controller for the layout edit/add forms.

Namespace

Drupal\rlayout

Code

protected function prepareEntity(EntityInterface $layout) {
  if (empty($layout->regions)) {
    if ($default = rlayout_load('default')) {

      // Attempt to clone the default layout if available.
      $layout->regions = $default->regions;
      $layout->overrides = $default->overrides;
    }
    else {

      // If the default cannot be cloned, set some defaults.
      $layout->regions = array();
      $default_regions = region_load_all();
      foreach ($default_regions as $region) {
        $layout->regions[] = $region
          ->id();
      }
      $layout->overrides = array();
    }
  }
}