1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 use ICanBoogie\Errors;
15 use ICanBoogie\Exception;
16 use ICanBoogie\Operation;
17
18 19 20
21 class ChangeOperation extends Operation
22 {
23 protected function get_controls()
24 {
25 return array
26 (
27 self::CONTROL_AUTHENTICATION => true
28 )
29
30 + parent::get_controls();
31 }
32
33 protected function validate(Errors $errors)
34 {
35 $request = $this->request;
36
37 if (!$this->key)
38 {
39 $errors['editor_id'] = $errors->format('The %property is required.', array('property' => 'editor_id'));
40 }
41
42 if (empty($request['selector_name']))
43 {
44 $errors['selector_name'] = $errors->format('The %property is required.', array('property' => 'selector_name'));
45 }
46
47 if (empty($request['contents_name']))
48 {
49 $errors['contents_name'] = $errors->format('The %property is required.', array('property' => 'contents_name'));
50 }
51
52 return !$errors->count();
53 }
54
55 protected function process()
56 {
57 global $core;
58
59 $request = $this->request;
60
61 $editor = (string) new MultiEditorElement
62 (
63 $this->key, array
64 (
65 MultiEditorElement::SELECTOR_NAME => $request['selector_name'],
66
67 'name' => $request['contents_name'],
68 'value' => $request['contents']
69 )
70 );
71
72 $this->response['assets'] = $core->document->assets;
73
74 return $editor;
75 }
76 }