You are here

public function RLayoutFormController::save in Layout 8

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

File

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

Class

RLayoutFormController
Form controller for the layout edit/add forms.

Namespace

Drupal\rlayout

Code

public function save(array $form, array &$form_state) {
  $layout = $this
    ->getEntity($form_state);
  $default_regions = region_load_all();
  $new_layout_settings = drupal_json_decode($form_state['values']['layout_regions']);
  if (!empty($new_layout_settings)) {
    $layout->regions = array();
    foreach ($new_layout_settings['regions'] as $region) {
      $layout->regions[] = $region['id'];

      /*/ Save region in common regions list in case it is new.
        if (!isset($default_regions[$region['id']])) {
          $region = (object) array(
            'id' => $region['id'],
            'label' => $region['label'],
          );
          region_save($region);
        }*/
    }
    $layout->overrides = $new_layout_settings['overrides'];
  }
  $layout
    ->save();
  watchdog('layout', 'Layout @label saved.', array(
    '@label' => $layout
      ->label(),
  ), WATCHDOG_NOTICE);
  drupal_set_message(t('Layout %label saved.', array(
    '%label' => $layout
      ->label(),
  )));
  $form_state['redirect'] = 'admin/structure/layouts';
}