|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package net.nehmer.static |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use midcom\datamanager\datamanager; |
|
10
|
|
|
use midcom\datamanager\controller; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* n.n.static create page handler |
|
15
|
|
|
* |
|
16
|
|
|
* @package net.nehmer.static |
|
17
|
|
|
*/ |
|
18
|
|
|
class net_nehmer_static_handler_create extends midcom_baseclasses_components_handler |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* The article which has been created |
|
22
|
|
|
* |
|
23
|
|
|
* @var midcom_db_article |
|
24
|
|
|
*/ |
|
25
|
|
|
private $article; |
|
26
|
|
|
|
|
27
|
2 |
|
private function load_controller(string $schemaname, array $defaults) : controller |
|
28
|
|
|
{ |
|
29
|
2 |
|
if ($this->_config->get('simple_name_handling')) { |
|
30
|
2 |
|
$this->_request_data['schemadb']->get($schemaname)->get_field('name')['hidden'] = true; |
|
31
|
|
|
} |
|
32
|
2 |
|
$dm = new datamanager($this->_request_data['schemadb']); |
|
33
|
|
|
|
|
34
|
|
|
return $dm |
|
35
|
2 |
|
->set_defaults($defaults) |
|
36
|
2 |
|
->set_storage($this->article, $schemaname) |
|
37
|
2 |
|
->get_controller(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Displays an article create view. |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function _handler_create(Request $request, string $handler_id, array $args) |
|
44
|
|
|
{ |
|
45
|
2 |
|
$this->_topic->require_do('midgard:create'); |
|
46
|
2 |
|
$this->article = new midcom_db_article(); |
|
47
|
2 |
|
$this->article->topic = $this->_topic->id; |
|
48
|
|
|
|
|
49
|
2 |
|
$defaults = []; |
|
50
|
2 |
|
if ($handler_id == 'createindex') { |
|
51
|
1 |
|
$defaults['name'] = 'index'; |
|
52
|
|
|
} |
|
53
|
2 |
|
$controller = $this->load_controller($args[0], $defaults); |
|
54
|
|
|
|
|
55
|
2 |
|
$title = sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($controller->get_datamanager()->get_schema()->get('description'))); |
|
56
|
2 |
|
midcom::get()->head->set_pagetitle($title); |
|
57
|
|
|
|
|
58
|
2 |
|
$workflow = $this->get_workflow('datamanager', [ |
|
59
|
2 |
|
'controller' => $controller, |
|
60
|
2 |
|
'save_callback' => [$this, 'save_callback'] |
|
61
|
|
|
]); |
|
62
|
2 |
|
return $workflow->run($request); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function save_callback(controller $controller) |
|
66
|
|
|
{ |
|
67
|
|
|
// Reindex the article |
|
68
|
|
|
$indexer = midcom::get()->indexer; |
|
69
|
|
|
net_nehmer_static_viewer::index($controller->get_datamanager(), $indexer, $this->_topic); |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
if ($callback = $this->_config->get('callback_function')) { |
|
73
|
|
|
call_user_func($callback, $this->article, $this->_topic); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ($this->article->name == 'index') { |
|
77
|
|
|
return ''; |
|
78
|
|
|
} |
|
79
|
|
|
return $this->article->name . '/'; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|