You are here

public function GatsbyAdminForm::buildForm in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x src/Form/GatsbyAdminForm.php \Drupal\gatsby\Form\GatsbyAdminForm::buildForm()

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

1 call to GatsbyAdminForm::buildForm()
GatsbyInstantPreviewAdminForm::buildForm in modules/gatsby_instantpreview/src/Form/GatsbyInstantPreviewAdminForm.php
Form constructor.
1 method overrides GatsbyAdminForm::buildForm()
GatsbyInstantPreviewAdminForm::buildForm in modules/gatsby_instantpreview/src/Form/GatsbyInstantPreviewAdminForm.php
Form constructor.

File

src/Form/GatsbyAdminForm.php, line 86

Class

GatsbyAdminForm
Defines a config form to store Gatsby configuration.

Namespace

Drupal\gatsby\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('gatsby.settings');
  $form['server_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Gatsby Preview Server URL'),
    '#description' => $this
      ->t('The URL to the Gatsby preview server (with port number if needed). Separate multiple values with a comma.'),
    '#default_value' => $config
      ->get('server_url'),
    '#required' => TRUE,
    '#maxlength' => 250,
    '#weight' => 0,
  ];
  $form['preview_callback_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Gatsby Preview Callback URL'),
    '#description' => $this
      ->t('The URL to the Gatsby preview build webhook (if running locally, it\'s "localhost:8000/__refresh"). Separate multiple values with a comma.'),
    '#default_value' => $config
      ->get('preview_callback_url'),
    '#required' => TRUE,
    '#maxlength' => 250,
    '#weight' => 0,
  ];
  $form['path_mapping'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Preview Server Path Mapping'),
    '#description' => $this
      ->t('If you do any path manipulation in your Gatsby
        site you may need to map the preview iframe and preview button to this
        correct path. For instance, you may have a /home path in Drupal that
        maps to / on your Gatsby site. Enter the Drupal path on the left
        (starting with a "/") and the Gatsby path on the right (starting with
        a "/") separated by a "|" character. For example: "/home|/". Enter one
        path mapping per line.'),
    '#default_value' => $config
      ->get('path_mapping'),
  ];
  $build_title = $this
    ->t("Build Server Callback Hook(s)");
  $build_description = $this
    ->t('The Callback URL to trigger the Gatsby Build. Multiple build server URLS can be separated by commas. Note: Incremental builds are currently only supported with JSON:API and gatsby-source-drupal.');
  if ($this->moduleHandler
    ->moduleExists('jsonapi_extras')) {
    $build_title = $this
      ->t("Incremental Build Server Callback Hook(s)");
    $build_description = $this
      ->t('The Callback URL to the Gatsby incremental builds server. Multiple build server URLS can be separated by commas.');
  }
  $form['incrementalbuild_url'] = [
    '#type' => 'textfield',
    '#title' => $build_title,
    '#description' => $build_description,
    '#default_value' => $config
      ->get('incrementalbuild_url'),
    '#maxlength' => 250,
    '#weight' => 1,
  ];
  $form['build_published'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Only trigger builds for published content'),
    '#description' => $this
      ->t('Depending on your content workflow, you may only
        want builds to be triggered for published content. By checking this box
        only published content will trigger a build. This means additional entities
        such as Media or Files will not trigger a rebuild until the content it\'s
        attached to is published. The downside is that this will
        only allow content entities to trigger a rebuild.'),
    '#default_value' => $config
      ->get('build_published') !== NULL ? $config
      ->get('build_published') : TRUE,
    '#weight' => 2,
  ];
  $form['preview_entity_types'] = [
    '#type' => 'checkboxes',
    '#options' => $this
      ->getContentEntityTypes(),
    '#default_value' => $config
      ->get('preview_entity_types') ?: [],
    '#title' => $this
      ->t('Entity types to send to Gatsby Preview and Build Server'),
    '#description' => $this
      ->t('What entities should be sent to the Gatsby Preview and Build Server?'),
    '#weight' => 10,
  ];
  return parent::buildForm($form, $form_state);
}