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