You are here

public function SearchApiSolrAcquiaConnector::buildConfigurationForm in Acquia Search 3.x

Same name and namespace in other branches
  1. 2.x src/Plugin/SolrConnector/SearchApiSolrAcquiaConnector.php \Drupal\acquia_search\Plugin\SolrConnector\SearchApiSolrAcquiaConnector::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides SolrConnectorPluginBase::buildConfigurationForm

File

src/Plugin/SolrConnector/SearchApiSolrAcquiaConnector.php, line 196

Class

SearchApiSolrAcquiaConnector
Class SearchApiSolrAcquiaConnector.

Namespace

Drupal\acquia_search\Plugin\SolrConnector

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  if ($this->storage
    ->isReadOnly()) {
    $form['readonly']['#markup'] = Messages::getReadOnlyModeWarning();
  }

  // If acquia connector is enabled, use the settings from there instead.
  $connector = \Drupal::moduleHandler()
    ->moduleExists('acquia_connector');
  if ($connector) {
    $form['connector']['#markup'] = $this
      ->t('Search settings are being automatically set by your <a href=":connector">Acquia Connector</a> subscription.', [
      ':connector' => base_path() . Url::fromRoute('acquia_connector.settings')
        ->getInternalPath(),
    ]);
    $subscription = \Drupal::state()
      ->get('acquia_subscription_data');
    $form['identifier'] = [
      '#type' => 'value',
      '#value' => \Drupal::state()
        ->get('acquia_connector.identifier') ?? '',
    ];
    $form['api_key'] = [
      '#type' => 'value',
      '#value' => \Drupal::state()
        ->get('acquia_connector.key') ?? '',
    ];
    $form['uuid'] = [
      '#type' => 'value',
      '#value' => $subscription['uuid'] ?? '',
    ];
  }
  else {
    $form['manual']['#markup'] = $this
      ->t('Enter your product keys from the "Product Keys" section of the <a href=":cloud">Acquia Cloud UI</a> to connect your site to Acquia Search. You can also automatically set these details by enabling the Acquia Connector.', [
      ':cloud' => Url::fromUri('https://cloud.acquia.com')
        ->getUri(),
    ]);
    $form['identifier'] = [
      '#title' => $this
        ->t('Acquia Subscription identifier'),
      '#type' => 'textfield',
      '#default_value' => $this->storage
        ->getIdentifier(),
      '#required' => TRUE,
      '#description' => $this
        ->t('Obtain this from the "Product Keys" section of the Acquia Cloud UI. Example: ABCD-12345'),
    ];
    $form['api_key'] = [
      '#title' => $this
        ->t('Acquia Connector key'),
      '#type' => 'password',
      '#description' => !empty($this->storage
        ->getApiKey()) ? $this
        ->t('Value already provided.') : $this
        ->t('Obtain this from the "Product Keys" section of the Acquia Cloud UI.'),
      '#required' => empty($this->storage
        ->getApiKey()),
    ];
    $form['uuid'] = [
      '#title' => $this
        ->t('Acquia Application UUID'),
      '#type' => 'textfield',
      '#default_value' => $this->storage
        ->getUuid(),
      '#required' => TRUE,
      '#description' => $this
        ->t('Obtain this from the "Product Keys" section of the Acquia Cloud UI.'),
    ];
  }
  $form['api_host'] = [
    '#title' => $this
      ->t('Acquia Search API hostname'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('API endpoint domain or URL. Default value is "https://api.sr-prod02.acquia.com".'),
    '#default_value' => $this->storage
      ->getApiHost(),
    '#required' => TRUE,
  ];
  $form['acquia_search_cores'] = [
    '#title' => $this
      ->t('Solr core(s) currently available for your application'),
    '#type' => 'fieldset',
    '#tree' => FALSE,
    'cores' => $this
      ->getAcquiaSearchCores(),
  ];
  return $form;
}