mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 20:38:52 +00:00
[ticket/15289] Add twig extension to generate inputs from the template
PHPBB3-15289
This commit is contained in:
parent
9fd8a6ee0f
commit
19b99a0770
5 changed files with 97 additions and 14 deletions
|
@ -28,7 +28,11 @@
|
||||||
{% for provider in PROVIDERS if provider.is_available %}
|
{% for provider in PROVIDERS if provider.is_available %}
|
||||||
<fieldset id="{{ storage.get_name }}_{{ provider.get_name }}_settings">
|
<fieldset id="{{ storage.get_name }}_{{ provider.get_name }}_settings">
|
||||||
<legend>{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }}</legend>
|
<legend>{{ lang('STORAGE_' ~ storage.get_name | upper ~ '_TITLE') }} - {{ lang('STORAGE_ADAPTER_' ~ provider.get_name | upper ~ '_NAME') }}</legend>
|
||||||
provider.get_options
|
{% for name, options in provider.get_options %}
|
||||||
|
{% set lang_name = 'STORAGE_ADAPTER_' ~ storage.get_name | upper ~ '_OPTION_' ~ name | upper %}
|
||||||
|
{% set options = options|merge({'name': storage.get_name ~ '[' ~ name ~ ']'}) %}
|
||||||
|
{{ adm_block(lang(lang_name), '', input(options)) }}
|
||||||
|
{% endfor %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,12 @@ services:
|
||||||
tags:
|
tags:
|
||||||
- { name: twig.extension }
|
- { name: twig.extension }
|
||||||
|
|
||||||
|
template.twig.extensions.form:
|
||||||
|
class: phpbb\template\twig\extension\form
|
||||||
|
arguments:
|
||||||
|
tags:
|
||||||
|
- { name: twig.extension }
|
||||||
|
|
||||||
template.twig.extensions.debug:
|
template.twig.extensions.debug:
|
||||||
class: Twig_Extension_Debug
|
class: Twig_Extension_Debug
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ $lang = array_merge($lang, array(
|
||||||
'STORAGE_AVATAR_TITLE' => 'Avatars storage',
|
'STORAGE_AVATAR_TITLE' => 'Avatars storage',
|
||||||
'STORAGE_BACKUP_TITLE' => 'Backup storage',
|
'STORAGE_BACKUP_TITLE' => 'Backup storage',
|
||||||
|
|
||||||
|
'STORAGE_ADAPTER_LOCAL_OPTION_PATH' => 'Path',
|
||||||
|
|
||||||
'STORAGE_ADAPTER_LOCAL_NAME' => 'Local',
|
'STORAGE_ADAPTER_LOCAL_NAME' => 'Local',
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
|
@ -38,7 +38,7 @@ class local implements provider_interface
|
||||||
*/
|
*/
|
||||||
public function get_options()
|
public function get_options()
|
||||||
{
|
{
|
||||||
return ['path' => array('lang' => 'PATH', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => false)];
|
return ['path' => array('type' => 'text')];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
71
phpBB/phpbb/template/twig/extension/form.php
Normal file
71
phpBB/phpbb/template/twig/extension/form.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\template\twig\extension;
|
||||||
|
|
||||||
|
// I will use this to generate forms in twig until there is something better
|
||||||
|
class form extends \Twig_Extension
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFunctions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new \Twig_SimpleFunction('input', '\\phpbb\\template\\twig\\extension\\form::generate_input'),
|
||||||
|
new \Twig_SimpleFunction('adm_block', '\\phpbb\\template\\twig\\extension\\form::generate_block'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function generate_input($options)
|
||||||
|
{
|
||||||
|
$input = '<input ';
|
||||||
|
|
||||||
|
switch ($options['type'])
|
||||||
|
{
|
||||||
|
case 'radio':
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
foreach ($options as $key => $value)
|
||||||
|
{
|
||||||
|
if (in_array($key, ['lang']))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$input .= "$key=\"$value\" ";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$input .= '>';
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function generate_block($name, $description = '', $content)
|
||||||
|
{
|
||||||
|
return <<<EOF
|
||||||
|
<dl>
|
||||||
|
<dt><label for="">$name</label><br /><span>$description</span></dt>
|
||||||
|
<dd>
|
||||||
|
$content
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
EOF;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue