You are here

public function ReferenceFormBuilder::restoreFromCache in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/ReferenceFormBuilder.php \Drupal\bibcite_entity\ReferenceFormBuilder::restoreFromCache()

Get entity if stores in cache.

If we have in cache our entity, we need to apply it to ReferenceEntityFormBuilder.

Return value

bool Return entity from cache. FALSE if not in cache.

File

modules/bibcite_entity/src/ReferenceFormBuilder.php, line 28

Class

ReferenceFormBuilder
Provides reference form building and processing hotfix.

Namespace

Drupal\bibcite_entity

Code

public function restoreFromCache() {
  $request = $this->requestStack
    ->getCurrentRequest();
  $form_state = (new FormState())
    ->setFormState([]);
  $form_state
    ->setRequestMethod($request
    ->getMethod());
  $input = $form_state
    ->getUserInput();
  if (!isset($input)) {
    $input = $form_state
      ->isMethodType('get') ? $request->query
      ->all() : $request->request
      ->all();
  }
  if (isset($input['form_build_id'])) {
    $current_user_id = \Drupal::currentUser()
      ->id();
    $cid = 'bibcite_entity_populate:' . $current_user_id . ':' . $input['form_build_id'];
    if ($cache = \Drupal::cache()
      ->get($cid)) {
      \Drupal::cache()
        ->delete($cid);
      return $cache->data;
    }
  }
  return FALSE;
}