SettingRenderer.php 1.8 KB

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