Elgg  Version 6.1
ActionMiddleware.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
12 
16  protected $request;
17 
21  protected $form_name;
22 
31  public function __invoke(\Elgg\Request $request): void {
32  $this->request = $request;
33 
34  $route = $request->getRoute();
35  list(, $action) = explode(':', $route, 2);
36 
37  // save sticky form values
38  $this->prepareStickyForm();
39 
40  $result = $request->elgg()->events->triggerResults('action:validate', $action, ['request' => $request], true);
41  if ($result === false) {
42  throw new ValidationException(elgg_echo('ValidationException'));
43  }
44 
45  // set the maximum execution time for actions
46  $action_timeout = $request->elgg()->config->action_time_limit;
47  if (isset($action_timeout)) {
48  set_time_limit($action_timeout);
49  }
50  }
51 
58  protected function prepareStickyForm(): void {
59  $this->form_name = $this->request->getParam('_elgg_sticky_form_name');
60 
61  if (empty($this->form_name)) {
62  return;
63  }
64 
65  // add user and system ignored fields
66  $ignored_fields = (string) $this->request->getParam('_elgg_sticky_ignored_fields');
67  $ignored_fields = elgg_string_to_array($ignored_fields);
68 
69  _elgg_services()->stickyForms->makeStickyForm($this->form_name, $ignored_fields);
70 
71  // register sticky value cleanup
72  $this->request->elgg()->events->registerHandler('response', 'all', [$this, 'cleanupStickyValues']);
73  }
74 
83  public function cleanupStickyValues(\Elgg\Event $event): void {
84  $response = $event->getValue();
85  if (!$response instanceof OkResponse) {
86  return;
87  }
88 
89  _elgg_services()->stickyForms->clearStickyForm($this->form_name);
90  }
91 }
cleanupStickyValues(\Elgg\Event $event)
Automatically cleanup sticky form values after a successfull action.
$response
Definition: content.php:10
__invoke(\Elgg\Request $request)
Pre-action logic.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
prepareStickyForm()
Save the action input in sticky form values.
elgg_string_to_array(string $string)
Takes in a comma-separated string and returns an array of uniquely trimmed and stripped strings...
Definition: input.php:220
Some logic implemented before action is executed.
$action
Definition: subscribe.php:11
Request container.
Definition: Request.php:12
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
OK response builder.
Definition: OkResponse.php:8
Models an event passed to event handlers.
Definition: Event.php:11