Completed
Push — 4.3 ( 41dc92...731ef0 )
by Maxime
36s queued 17s
created

AttributeStore::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace SilverStripe\Forms\GridField\FormAction;
3
4
/**
5
 * Stores GridField action state on an attribute on the action and then analyses request parameters to load it back
6
 */
7
class AttributeStore extends AbstractRequestAwareStore
8
{
9
    /**
10
     * Save the given state against the given ID returning an associative array to be added as attributes on the form
11
     * action
12
     *
13
     * @param string $id
14
     * @param array $state
15
     * @return array
16
     */
17
    public function save($id, array $state)
18
    {
19
        // Just save the state in the attributes of the action
20
        return [
21
            'data-action-state' => json_encode($state),
22
        ];
23
    }
24
25
    /**
26
     * Load state for a given ID
27
     *
28
     * @param string $id
29
     * @return array
30
     */
31
    public function load($id)
32
    {
33
        // Check the request
34
        return (array) json_decode((string) $this->getRequest()->requestVar('ActionState'), true);
35
    }
36
}
37