英文:
User firendly category selector in post options in Silverstripe cms
问题
我想要更改在Silverstripe CMS中的"帖子选项"中选择"帖子类别"的选择框的行为。目前,只有当我事先知道它们时,才能找到并选择类别。也就是说,当我输入一个字母时,它开始使用包含该字母的类别填充选择框。
我想要默认情况下用所有类别填充选择框,并仍然保留多选选项。这个选项是否已经考虑过,还是我应该开发自定义类别选择器?
英文:
I would like to change the behaviour of the select box for selecting Post categories within the Post Options in Silverstripe cms. Currently I can find and select the categories only if I know them beforehand. That is the when I enter a letter it starts to populate the select box with the categories that contain that letter.
I would like to populate the select box with all categories by default. And still maintain multi select option. Has this option been considered yet or should I develop my custom category selector?
答案1
得分: 1
这似乎是指的是 silverstripe/blog 模块。
Categories 字段是来自 silverstripe/tagfield 模块的 TagField。在 BlogPost 类中,该字段被设置为延迟加载:
https://github.com/silverstripe/silverstripe-blog/blob/0f8aefb0920812f4f9cc03bba5a0ed4b7b6df205/src/Model/BlogPost.php#L350
您可以在您的项目中通过将扩展应用于 BlogPost 并关闭该字段的延迟加载来覆盖它:
app/_config/extensions.yml
SilverStripe\Blog\Model\BlogPost:
extensions:
- App\Extension\BlogPostExtension
app/src/Extension/BlogPostExtension.php
<?php
namespace App\Extension;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
class BlogPostExtension extends Extension
{
public function updateCMSFields(FieldList $fields)
{
$fields->dataFieldByName('Categories')->setShouldLazyLoad(false);
}
}
您可能也想在处理 Tags 字段时执行相同操作。
英文:
It sounds like you're specifically referring to the silverstripe/blog module.
The categories field is a TagField from the silverstripe/tagfield module. In the BlogPost class, the field is set to lazy load:
https://github.com/silverstripe/silverstripe-blog/blob/0f8aefb0920812f4f9cc03bba5a0ed4b7b6df205/src/Model/BlogPost.php#L350
You can override that in your project by applying an extension to BlogPost and turn lazyloading off for that field:
app/_config/extensions.yml
SilverStripe\Blog\Model\BlogPost:
extensions:
- App\Extension\BlogPostExtension
app/src/Extension/BlogPostExtension.php
<?php
namespace App\Extension;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
class BlogPostExtension extends Extension
{
public function updateCMSFields(FieldList $fields)
{
$fields->dataFieldByName('Categories')->setShouldLazyLoad(false);
}
}
You might want to do the same for the Tags field while you're at it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论