Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

主题启用后,添加复选框选项无效 #1590

Closed
liaocp666 opened this issue Jun 11, 2023 · 2 comments
Closed

主题启用后,添加复选框选项无效 #1590

liaocp666 opened this issue Jun 11, 2023 · 2 comments

Comments

@liaocp666
Copy link
Contributor

liaocp666 commented Jun 11, 2023

1. 该问题的重现步骤是什么?

以默认主题为例

  1. 启用主题
  2. 在主题的文件中,添加复选框代码,例如下面代码:
    $testBlock = new \Typecho\Widget\Helper\Form\Element\Checkbox(
        'testBlock',
        [
            'test'    => _t('测试'),
        ],
        ['test'],
        _t('测试复选框')
    );

    $form->addInput($testBlock->multiMode());
  1. 刷新主题选项页面,点击保存设置

2. 你期待的结果是什么?实际看到的又是什么?

期望结果测试被勾上,实际勾选无效

3. 问题出现的环境

  • 操作系统版本:OpenSUSE tw
  • Apache/NGINX 版本:docker:joyqi/typecho:nightly-php7.4
  • 数据库版本:docker:mysql5.7
  • PHP 版本:docker:joyqi/typecho:nightly-php7.4
  • Typecho 版本:docker:joyqi/typecho:nightly-php7.4
  • 浏览器版本:google-chrome 114.0.5735.106

Peek 2023-06-11 10-56

4. 问题出现原因

$form->getInput($key)->value($this->options->{$key});

上面这行代码中,从 options 中拿值,但是因为测试复选框新加入的,options 中并没有对应的值,导致给了一个空的值给测试复选框 $this->getInput('testBlock')

当主题选项保存的时候,is_array 中的数据是从 $this->getInput('testBlock') 拿 value,但前面程序已经设置为空值,所以在收集提交选项数据时候,以下代码判断不通过,返回 null ,最终导致保存勾选无效

$result[$param] = $request->get($param, is_array($this->getInput($param)->value) ? [] : null);

上面是我排查的原因,我认为 Config.php#L74 应该增加判断是有内容,稍后我将提个 PR 。

@liaocp666
Copy link
Contributor Author

@joyqi

@yyaghoobmallahi52
Copy link

$testBlock = new \Typecho\Widget\Helper\Form\Element\Checkbox(
'testBlock',
[
'test' => _t('测试'),
],
['test'],
_t('测试复选框')
);

$form->addInput($testBlock->multiMode());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants