用户友好的分类选择器在Silverstripe CMS中的帖子选项中

huangapple go评论95阅读模式
英文:

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

&lt;?php

namespace App\Extension;

use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;

class BlogPostExtension extends Extension
{
    public function updateCMSFields(FieldList $fields)
    {
        $fields-&gt;dataFieldByName(&#39;Categories&#39;)-&gt;setShouldLazyLoad(false);
    }
}

You might want to do the same for the Tags field while you're at it.

huangapple
  • 本文由 发表于 2023年3月8日 18:21:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定