class ReferenceFormBuilder in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/ReferenceFormBuilder.php \Drupal\bibcite_entity\ReferenceFormBuilder
Provides reference form building and processing hotfix.
Hierarchy
- class \Drupal\Core\Form\FormBuilder implements FormBuilderInterface, FormCacheInterface, FormSubmitterInterface, FormValidatorInterface, TrustedCallbackInterface
- class \Drupal\bibcite_entity\ReferenceFormBuilder
Expanded class hierarchy of ReferenceFormBuilder
See also
https://www.drupal.org/project/bibcite/issues/2930990
1 string reference to 'ReferenceFormBuilder'
- bibcite_entity.services.yml in modules/
bibcite_entity/ bibcite_entity.services.yml - modules/bibcite_entity/bibcite_entity.services.yml
1 service uses ReferenceFormBuilder
- reference.form_builder in modules/
bibcite_entity/ bibcite_entity.services.yml - Drupal\bibcite_entity\ReferenceFormBuilder
File
- modules/
bibcite_entity/ src/ ReferenceFormBuilder.php, line 17
Namespace
Drupal\bibcite_entityView source
class ReferenceFormBuilder extends FormBuilder {
/**
* Get entity if stores in cache.
*
* If we have in cache our entity,
* we need to apply it to ReferenceEntityFormBuilder.
*
* @return bool
* Return entity from cache. FALSE if not in cache.
*/
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;
}
/**
* {@inheritdoc}
*/
public function buildForm($form_id, FormStateInterface &$form_state) {
$form = parent::buildForm($form_id, $form_state);
$form_id = $this
->getFormId($form_id, $form_state);
$input = $form_state
->getUserInput();
$check_cache = isset($input['form_id']) && $input['form_id'] == $form_id && !empty($input['form_build_id']);
if (!$check_cache) {
// If it is first form build (form not cached),
// we need to save entity for second form build.
$info = $form_state
->getBuildInfo();
$callback_object = $info['callback_object'];
$entity = $callback_object
->getEntity();
$current_user_id = \Drupal::currentUser()
->id();
\Drupal::cache()
->set('bibcite_entity_populate:' . $current_user_id . ':' . $form['#build_id'], $entity, \Drupal::time()
->getRequestTime() + 3600);
}
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormBuilder:: |
protected | property | The class resolver. | |
FormBuilder:: |
protected | property | The CSRF token generator to validate the form token. | |
FormBuilder:: |
protected | property | The current user. | |
FormBuilder:: |
protected | property | The element info manager. | |
FormBuilder:: |
protected | property | The event dispatcher. | |
FormBuilder:: |
protected | property | The form cache. | |
FormBuilder:: |
protected | property | The form submitter. | |
FormBuilder:: |
protected | property | The form validator. | |
FormBuilder:: |
protected | property | The module handler. | |
FormBuilder:: |
protected | property | The request stack. | |
FormBuilder:: |
protected | property | Defines element value callables which are safe to run even when the form state has an invalid CSRF token. | |
FormBuilder:: |
protected | property | The theme manager. | |
FormBuilder:: |
protected | function | Builds the $form['#action']. | |
FormBuilder:: |
protected | function | Determines if a given button triggered the form submission. | |
FormBuilder:: |
protected | function | Gets the current active user. | |
FormBuilder:: |
public | function |
Deletes a form in the cache. Overrides FormCacheInterface:: |
|
FormBuilder:: |
public | function |
Builds and processes all elements in the structured form array. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Handles the submitted form, executing callbacks and processing responses. Overrides FormSubmitterInterface:: |
|
FormBuilder:: |
protected | function | Detects if an element triggered the form submission via Ajax. | |
FormBuilder:: |
public | function |
Executes custom submission handlers for a given form. Overrides FormSubmitterInterface:: |
|
FormBuilder:: |
public | function |
Executes custom validation handlers for a given form. Overrides FormValidatorInterface:: |
|
FormBuilder:: |
public | function |
Fetches a form from the cache. Overrides FormCacheInterface:: |
|
FormBuilder:: |
protected | function | Wraps file_upload_max_size(). | |
FormBuilder:: |
public | function |
Gets a renderable form array. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Determines the ID of a form. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
protected | function | Adds the #name and #value properties of an input element before rendering. | |
FormBuilder:: |
public | function |
Prepares a structured form array. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Processes a form submission. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Constructs a new $form from the information in $form_state. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Redirects the user to a URL after a form has been processed. Overrides FormSubmitterInterface:: |
|
FormBuilder:: |
public | function | Renders the form CSRF token. It's a #lazy_builder callback. | |
FormBuilder:: |
public | function | Renders a form action URL. It's a #lazy_builder callback. | |
FormBuilder:: |
public | function |
Retrieves the structured array that defines a given form. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public | function |
Stores a form in the cache. Overrides FormCacheInterface:: |
|
FormBuilder:: |
public | function |
Sets a form_token error on the given form state. Overrides FormValidatorInterface:: |
|
FormBuilder:: |
public | function |
Retrieves, populates, and processes a form. Overrides FormBuilderInterface:: |
|
FormBuilder:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
FormBuilder:: |
public | function |
Validates user-submitted form data in the $form_state. Overrides FormValidatorInterface:: |
|
FormBuilder:: |
protected | function | Helper function to normalize the different callable formats. | |
FormBuilder:: |
public | function | Constructs a new FormBuilder. | |
FormBuilderInterface:: |
constant | Request key for AJAX forms that submit to the form's original route. | ||
ReferenceFormBuilder:: |
public | function |
Builds and processes a form for a given form ID. Overrides FormBuilder:: |
|
ReferenceFormBuilder:: |
public | function | Get entity if stores in cache. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |