1 layout.admin.inc layout_settings_form_update_layout($form, &$form_state)

Submit handler for layout_settings_form() that saves in-progress values.

File

core/modules/layout/layout.admin.inc, line 573
Administrative functions for Layout module.

Code

function layout_settings_form_update_layout($form, &$form_state) {
  /* @var Layout $layout */
  $layout = $form_state['layout'];

  // Keep track of the original name.
  if (isset($form_state['values']['name'])) {
    if ($form_state['values']['name'] !== $layout->name && !isset($layout->original_name)) {
      $layout->original_name = $layout->name;
    }
  }

  // Update main properties.
  if (isset($form_state['values']['title'])) {
    $layout->title = $form_state['values']['title'];
  }
  if (isset($form_state['values']['name'])) {
    $layout->name = $form_state['values']['name'];
  }
  if (isset($form_state['values']['layout_template'])) {
    $new = $form_state['values']['layout_template'];
    $region_mapping = layout_get_legacy_region_mapping($layout->layout_template, $new);
    $layout->setLayoutTemplate($form_state['values']['layout_template'], $region_mapping);
    if (!empty($layout->orphaned_blocks)) {
      $orphaned_blocks_titles = array();
      $layout_template_info = layout_get_layout_template_info($form_state['values']['layout_template']);
      foreach ($layout->orphaned_blocks as $uuid) {
        $orphaned_blocks_titles[] = $layout->content[$uuid]->getAdminTitle();
      }
      $message = t('The following blocks have been reassigned to the %new_region region. The regions they were placed in previously do not exist in the new layout template. You can move them to more appropriate regions:', array(
        '%new_region' => $layout_template_info['regions'][$layout->refuge_region]));
      $message .= theme('item_list', array('items' => $orphaned_blocks_titles));
      backdrop_set_message($message, 'warning');
    }
  }
  if (isset($form_state['values']['path'])) {
    $layout->setPath($form_state['values']['path']);
  }

  // Update contexts.
  // @todo: Provide methods/API for setting menu item arguments.
  if ($layout->menu_item && isset($form_state['values']['context'])) {
    $plugin_counts = array();
    $arguments = array();

    foreach ($layout->getContexts() as $position => $layout_context) {
      if (isset($form_state['values']['context']['required'][$position])) {
        $argument_config = $form_state['values']['context']['required'][$position];
        $plugin = $argument_config['plugin'];
      }
      else {
        $plugin = $layout_context->plugin;
      }

      // Keep track of all utilized plugins, both required and locked.
      $plugin_counts[$plugin] = isset($plugin_counts[$plugin]) ? $plugin_counts[$plugin] + 1 : 1;

      // Locked contexts are forced to be at this path, so they do not need to
      // be saved in the menu item's argument configuration.
      if ($layout_context->locked) {
        continue;
      }

      // Give an automatically generated name such as "node" or "string2".
      $name = $plugin . (($plugin_counts[$plugin] === 1) ? '' : $plugin_counts[$plugin]);

      // Persist machine names if they already exists for this argument.
      if (isset($layout->menu_item->arguments[$position])) {
        $existing_argument = $layout->menu_item->arguments[$position];
        if ($existing_argument['plugin'] === $plugin) {
          $name = $existing_argument['name'];
        }
      }

      $arguments[$position] = array(
        'plugin' => $plugin,
        'name' => $name,
        'position' => $position,
      );
    }
    $layout->menu_item->arguments = $arguments;
  }

  if (!empty($layout->is_new)) {
    $_SESSION['layout_new_name'] = $layout->name;
  }
  else {
    if ($form_state['values']['name'] !== $layout->name) {
      $layout->original_name = $form_state['values']['name'];
    }
  }
  layout_set_layout_tempstore($layout);
}