1 http_response_code_layout_access.inc public HttpResponseCodeLayoutAccess::form(&$form, &$form_state)

Settings form for configuring this access item.

Overrides LayoutAccessNegatable::form

File

core/modules/layout/plugins/access/http_response_code_layout_access.inc, line 10
Plugin to provide access control by the server HTTP response code.

Class

HttpResponseCodeLayoutAccess
@file Plugin to provide access control by the server HTTP response code.

Code

public function form(&$form, &$form_state) {
  parent::form($form, $form_state);
  $response_codes = isset($this->settings['http_response_codes']) ? $this->settings['http_response_codes'] : array();

  $checkboxes_description = '';
  $negate_description = '';
  if (isset($form_state['block'])) {
    $checkboxes_description = t('Shows the block on pages with any matching response code.');
    $negate_description = t('Hides the block on pages with any matching response code selected from the options above.');
  }
  elseif (isset($form_state['layout'])) {
    $checkboxes_description = t('This layout will apply on pages with any matching response code.');
    $negate_description = t('This layout will apply on all pages, except those with any matching response code selected from the options above.');
  }
  $form['http_response_codes'] = array(
    '#type' => 'checkboxes',
    '#title' => t('HTTP response status code'),
    '#options' => array(
      200 => t('Success (200)'),
      403 => t('Access denied (403)'),
      404 => t('Page not found (404)'),
    ),
    '#required' => TRUE,
    '#default_value' => $response_codes,
    '#description' => $checkboxes_description,
  );
  $form['negate']['#description'] = $negate_description;
  // Do not tick the negation checkbox if no status code has been selected.
  $form['negate']['#default_value'] = empty($response_codes) ? 0 : $this->settings['negate'];
  // Negation option should only be available if at least one status code has
  // been selected.
  $form['negate']['#states'] = array(
    'enabled' => array(
      array(':input[name="http_response_codes[200]"]' => array('checked' => TRUE)),
      array(':input[name="http_response_codes[403]"]' => array('checked' => TRUE)),
      array(':input[name="http_response_codes[404]"]' => array('checked' => TRUE)),
    ),
  );
}