You are here

public function NetlifyFrontendEnvironment::getAdditionalDeployFormElements in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x modules/build_hooks_netlify/src/Plugin/FrontendEnvironment/NetlifyFrontendEnvironment.php \Drupal\build_hooks_netlify\Plugin\FrontendEnvironment\NetlifyFrontendEnvironment::getAdditionalDeployFormElements()

Allows the plugin to add elements to the deployment form.

Parameters

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

Return value

array A form array to add to the deployment form.

Overrides FrontendEnvironmentInterface::getAdditionalDeployFormElements

File

modules/build_hooks_netlify/src/Plugin/FrontendEnvironment/NetlifyFrontendEnvironment.php, line 125

Class

NetlifyFrontendEnvironment
Provides a 'Netlify' frontend environment type.

Namespace

Drupal\build_hooks_netlify\Plugin\FrontendEnvironment

Code

public function getAdditionalDeployFormElements(FormStateInterface $form_state) {

  // This plugin adds to the deployment form a fieldset displaying the
  // latest deployments:
  $form = [];
  $form['latestNetlifyDeployments'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Recent deployments'),
    '#description' => $this
      ->t('Here you can see the details for the latest deployments for this environment.'),
    '#open' => TRUE,
  ];
  try {
    $form['latestNetlifyDeployments']['table'] = $this
      ->getLastNetlifyDeploymentsTable($this
      ->getConfiguration());
    $form['latestNetlifyDeployments']['refresher'] = [
      '#type' => 'button',
      '#ajax' => [
        'callback' => [
          NetlifyFrontendEnvironment::class,
          'refreshDeploymentTable',
        ],
        'wrapper' => 'ajax-replace-table',
        'effect' => 'fade',
        'progress' => [
          'type' => 'throbber',
          'message' => $this
            ->t('Refreshing deployment status...'),
        ],
      ],
      '#value' => $this
        ->t('Refresh'),
    ];
  } catch (GuzzleException $e) {
    $this
      ->messenger()
      ->addError('Unable to retrieve information about the last deployments for this environment. Check configuration.');
  }
  return $form;
}