1 layout.admin.inc layout_content_form($form, &$form_state, Layout $layout, $renderer_name = NULL)

Form callback; Main form for editing a layout's content.

No validation function is necessary, as all 'validation' is handled either in the lead-up to form rendering (through the selection of specified content types) or by the validation functions specific to the ajax modals & content types.

Related topics

File

core/modules/layout/layout.admin.inc, line 1162
Admin page callbacks for the Layout module.

Code

function layout_content_form($form, &$form_state, Layout $layout, $renderer_name = NULL) {
  $path = isset($layout->menu_item->path) ? '(' . $layout->menu_item->path . ')' : NULL;
  backdrop_set_title(t('!layout !path', array('!layout' => $layout->title, '!path' => $path)));
  if (!isset($form_state['layout'])) {
    $form_state['layout'] = $layout;
  }
  if ($renderer_name) {
    $renderer = layout_create_renderer($renderer_name, $layout);
  }
  else {
    $renderer = layout_create_renderer('editor', $layout);
  }

  if (!isset($form_state['renderer'])) {
    $form_state['renderer'] = $renderer;
  }

  /* @var Layout $layout */
  $layout = $form_state['layout'];
  /* @var LayoutRendererStandard $renderer */
  $renderer = $form_state['renderer'];

  // Although layout is already set in $form_state, we need this to make it
  // available to the theme layer.
  $form['#layout'] = $layout;

  $form['#attached'] = array(
    'library' => array(
      array('system', 'backdrop.ajax'),
      array('system', 'backdrop.announce'),
    ),
  );

  $form['messages'] = array(
    '#markup' => $layout->locked ? '<div class="messages warning">' . layout_locked_message($layout, 'layout') . '</div>' : '',
    '#weight' => -100,
    // Prefix/suffix used to identify in AJAX requests.
    '#prefix' => '<div id="layout-messages">',
    '#suffix' => '</div>',
  );

  // Add a link to preview the page.
  $link_path = $layout->getPath();
  // A null path returns the site root.
  // See https://github.com/backdrop/backdrop-issues/issues/4383
  if (!is_null($link_path) && backdrop_valid_path($link_path)) {
    $form['top']['#theme_wrappers'] = array('container');
    $form['top']['#attributes']['class'] = array('edit-layout-top', 'clearfix');

    $form['top']['button'] = array(
      '#type' => 'dropbutton',
    );
    $form['top']['button']['#links'] = array(
      array(
        'title' => t('View page'),
        'href' => $link_path,
      ),
    );
  }

  $form['content'] = array('#tree' => TRUE);
  $form['content']['block'] = array('#tree' => TRUE);

  $form['content']['display'] = array(
    '#markup' => $renderer->render(),
  );

  foreach ($renderer->layout_info['regions'] as $region_id => $title) {
    // Make sure we at least have an empty array for all possible locations.
    if (!isset($layout->positions[$region_id])) {
      $layout->positions[$region_id] = array();
    }

    $form['content']['positions'][$region_id] = array(
      // Use 'hidden' instead of 'value' so the JS can access it.
      '#type' => 'hidden',
      '#default_value' => implode(',', $layout->positions[$region_id]),
    );
  }

  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save layout'),
    '#id' => 'layout-edit-save',
    '#submit' => array('layout_content_form_submit'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#validate' => array(),
    '#limit_validation_errors' => array(array('actions', 'reset')),
    '#submit' => array('layout_settings_form_reset'),
  );

  return $form;
}