2015-10-29 23:13:51 +01:00
|
|
|
# Configuring Blog for large user bases
|
|
|
|
|
|
|
|
By default the blog module user and author selection form fields include all users in your website as
|
|
|
|
candidates for writers, editors and contributors. Additionally, when adding a blog post, again all users are selectable.
|
2017-09-20 02:15:19 +02:00
|
|
|
This can cause issues with websites that store a large number of users in the database.
|
2015-10-29 23:13:51 +01:00
|
|
|
|
2017-09-20 02:15:19 +02:00
|
|
|
In this case you may need to restrict the number of user accounts that are eligible for selection.
|
|
|
|
This module has some useful configuration options for this that can be added to your projects config.yml
|
2015-10-29 23:13:51 +01:00
|
|
|
|
|
|
|
## Restricting blog managers to a permission setting
|
|
|
|
Default is to list all users and when one is selected, they are added to a `blog-users` group with `CMS_ACCESS_CMSMain` permissions.
|
|
|
|
To only include those already having these permissions you can set in your `config.yml`:
|
|
|
|
|
|
|
|
```yaml
|
2017-09-20 02:15:19 +02:00
|
|
|
SilverStripe\Blog\Model\Blog:
|
2015-10-29 23:13:51 +01:00
|
|
|
grant_user_access: false
|
|
|
|
```
|
|
|
|
|
2017-09-20 23:05:07 +02:00
|
|
|
Note: depending on the inclusion order of your config.yml you may need to clear the config setting
|
2017-09-20 02:15:19 +02:00
|
|
|
before updating it. In this case use the following in your `mysite/_config.php`:
|
2015-10-29 23:13:51 +01:00
|
|
|
|
|
|
|
```php
|
2017-09-20 23:05:07 +02:00
|
|
|
SilverStripe\Core\Config\Config::modify()->remove(SilverStripe\Blog\Model\Blog::class, 'grant_user_access');
|
2015-10-29 23:13:51 +01:00
|
|
|
```
|
|
|
|
|
2017-09-20 02:15:19 +02:00
|
|
|
If you create your own permissions and want to ensure the pool of possible selectable users includes
|
2015-10-29 23:13:51 +01:00
|
|
|
those with this permission you can set the checked permission in `config.yml` with:
|
|
|
|
|
|
|
|
```yaml
|
2017-09-20 02:15:19 +02:00
|
|
|
SilverStripe\Blog\Model\Blog:
|
|
|
|
grant_user_permission: SOME_PERMISSION_HERE
|
2015-10-29 23:13:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Restricting blog post authors selection to a known group
|
|
|
|
In a blog post when selecting an author it will default to you (the logged in person creating the post),
|
2017-09-20 02:15:19 +02:00
|
|
|
however you may be posting on behalf of another person. In this case the selection form field will offer
|
2015-10-29 23:13:51 +01:00
|
|
|
all users as potential blog authors. Again for large websites with many thousands of users this can cause
|
|
|
|
the site to be slow or non-responsive. We can turn on a filter so that authors need to be in a defined
|
|
|
|
user group to be able to be selected as an author.
|
|
|
|
|
|
|
|
Enable this in your `config.yml` by adding a group code:
|
|
|
|
|
|
|
|
```yaml
|
2017-09-20 02:15:19 +02:00
|
|
|
SilverStripe\Blog\Model\BlogPost:
|
2015-10-29 23:13:51 +01:00
|
|
|
restrict_authors_to_group: 'group_code'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Extension points in Blog and BlogPost users and how to use
|
|
|
|
Both Blog and BlogPost have methods which return the list of candidate users or authors. If the previously
|
2017-09-20 02:15:19 +02:00
|
|
|
mentioned methods of reducing this list are not suitable or you wish to roll your own, you can utilise a
|
2017-09-20 23:05:07 +02:00
|
|
|
DataExtension to get the control you require.
|
2015-10-29 23:13:51 +01:00
|
|
|
|
|
|
|
For example in BlogPost:
|
|
|
|
|
|
|
|
```php
|
2017-09-20 02:15:19 +02:00
|
|
|
protected function getCandidateAuthors()
|
|
|
|
{
|
|
|
|
if ($restrictedGroup = $this->config()->get('restrict_authors_to_group')) {
|
2017-09-20 23:05:07 +02:00
|
|
|
if ($group = Group::get()->filter('Code', $restrictedGroup)->first()) {
|
2017-09-20 02:15:19 +02:00
|
|
|
return $group->Members();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$list = Member::get();
|
|
|
|
$this->extend('updateCandidateAuthors', $list);
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 23:13:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Note the line `$this->extend('updateCandidateAuthors', $list);` which allows you to call a
|
2017-09-20 02:15:19 +02:00
|
|
|
`updateCandidateAuthors` method in a DataExtension to the Blog Post class if you have not set a
|
2017-09-20 23:05:07 +02:00
|
|
|
`restrict_authors_to_group` config, further filters the passed
|
2015-10-29 23:13:51 +01:00
|
|
|
in Member list before it gets sent back to the form field.
|
|
|
|
|
|
|
|
See the documentation on [DataExtension](https://docs.silverstripe.org/en/developer_guides/extending/extensions/) for further implementation notes.
|
|
|
|
|