You are here

public function TempStore::getSelectors in AJAX Comments 8

Retrieve the selectors included in the form submission HTTP request.

Store the selectors in the privateTempStore so that they are available for a subsequent HTTP response (when the #lazy_builder callback runs).

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

bool $overwrite: Boolean to indicate if an existing selector should be overwritten if a different value exists in the request.

Return value

array An array of the selectors, keyed by selector name.

1 call to TempStore::getSelectors()
TempStore::getSelectorValue in src/TempStore.php
Get a single selector value, without the '#' prefix.

File

src/TempStore.php, line 90

Class

TempStore
A service to help store and retrieve data to be used across HTTP requests.

Namespace

Drupal\ajax_comments

Code

public function getSelectors(Request $request, $overwrite = FALSE) {
  $selectors = [
    'wrapper_html_id' => NULL,
    'form_html_id' => NULL,
  ];
  foreach ($selectors as $selector_name => $selector) {
    $request_value = $request->request
      ->get($selector_name);
    $existing_value = $this->privateTempStore
      ->get($selector_name);
    if (!empty($request_value) && ($overwrite || empty($existing_value))) {
      $value = '#' . $request_value;
      $this->privateTempStore
        ->set($selector_name, $value);
      $selectors[$selector_name] = $value;
    }
    else {
      $selectors[$selector_name] = $existing_value;
    }
  }
  return $selectors;
}