xref: /dokuwiki/lib/plugins/config/core/Setting/SettingRenderer.php (revision 4b230b99ca279d0f160ebd0981007d2de6120995)
1<?php
2/**
3 * additional setting classes specific to these settings
4 *
5 * @author    Chris Smith <chris@jalakai.co.uk>
6 */
7
8namespace dokuwiki\plugin\config\core\Setting;
9
10/**
11 * Class setting_renderer
12 */
13class SettingRenderer extends SettingMultichoice
14{
15    protected $prompts = [];
16    protected $format;
17
18    /** @inheritdoc */
19    public function initialize($default = null, $local = null, $protected = null)
20    {
21        $format = $this->format;
22
23        foreach (plugin_list('renderer') as $plugin) {
24            $renderer = plugin_load('renderer', $plugin);
25            if (method_exists($renderer, 'canRender') && $renderer->canRender($format)) {
26                $this->choices[] = $plugin;
27
28                $info = $renderer->getInfo();
29                $this->prompts[$plugin] = $info['name'];
30            }
31        }
32
33        parent::initialize($default, $local, $protected);
34    }
35
36    /** @inheritdoc */
37    public function html(\admin_plugin_config $plugin, $echo = false)
38    {
39
40        // make some language adjustments (there must be a better way)
41        // transfer some plugin names to the config plugin
42        foreach ($this->choices as $choice) {
43            if (!$plugin->getLang($this->key . '_o_' . $choice)) {
44                if (!isset($this->prompts[$choice])) {
45                    $plugin->addLang(
46                        $this->key . '_o_' . $choice,
47                        sprintf($plugin->getLang('renderer__core'), $choice)
48                    );
49                } else {
50                    $plugin->addLang(
51                        $this->key . '_o_' . $choice,
52                        sprintf($plugin->getLang('renderer__plugin'), $this->prompts[$choice])
53                    );
54                }
55            }
56        }
57        return parent::html($plugin, $echo);
58    }
59}
60