RequestSetter.php
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace ACP\Bookmark\Controller;
use AC\Request;
use AC\Table\TableFormView;
use ACP\Bookmark;
use ACP\Sorting;
/**
* Fill the $_GET and $_REQUEST params with the preferred segment query parameters.
*/
class RequestSetter {
/**
* @var Bookmark\Setting\PreferredSegment
*/
private $setting;
public function __construct( Bookmark\Setting\PreferredSegment $setting ) {
$this->setting = $setting;
}
public function handle( Request $request ) {
// Ignore when switching to another segment or when the filter form is submitted.
if ( $request->filter( 'ac-segment' ) || null !== $request->get( TableFormView::PARAM_ACTION ) ) {
return;
}
$segment = $this->setting->get_segment();
if ( ! $segment ) {
return;
}
$params = $segment->get_url_parameters();
$ignored_params = [
Sorting\Request\Sort::PARAM_ORDERBY,
Sorting\Request\Sort::PARAM_ORDER,
'layout',
'ac-rules',
'ac-rules-raw',
];
foreach ( $params as $key => $value ) {
if ( in_array( $key, $ignored_params, true ) ) {
continue;
}
if ( isset( $_GET[ $key ], $_REQUEST[ $key ] ) ) {
continue;
}
$_REQUEST[ $key ] = $_GET[ $key ] = $value;
}
}
}