You are here

public function CorsAdminForm::buildForm in CORS 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/CorsAdminForm.php, line 35
Contains \Drupal\cors\Form\CorsAdminForm.

Class

CorsAdminForm
Form for CORS settings.

Namespace

Drupal\cors\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cors_domains = '';
  $domains = $this
    ->config('cors.settings')
    ->get('domains');
  foreach ($domains as $path => $domain) {
    $cors_domains .= $path . '|' . $domain . "\n";
  }
  $form['cors_domains'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Domains'),
    '#description' => $this
      ->t('A list of paths and corresponding domains to enable for CORS. Multiple entries should be separated by a comma. Enter one value per line separated by a pipe, in this order:
        <ul>
         <li>Internal path</li>
         <li>Access-Control-Allow-Origin. Use &lt;mirror&gt; to echo back the Origin header.</li>
         <li>Access-Control-Allow-Methods</li>
         <li>Access-Control-Allow-Headers</li>
         <li>Access-Control-Allow-Credentials</li>
        </ul>
        Examples:
        <ul>
          <li>*|http://example.com</li>
          <li>api|http://example.com:8080 http://example.com</li>
          <li>api/*|&lt;mirror&gt;,https://example.com</li>
          <li>api/*|&lt;mirror&gt;|POST|Content-Type,Authorization|true</li>
        </ul>'),
    '#default_value' => $cors_domains,
    '#rows' => 10,
  );
  return parent::buildForm($form, $form_state);
}