mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge branch '3.4' into 3
This commit is contained in:
commit
8db2e681a2
13
docs/en/configuring-featured-images.md
Normal file
13
docs/en/configuring-featured-images.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
## Configuring featured images
|
||||||
|
|
||||||
|
By default, featured images for the blog are uploaded to the default SilverStripe location.
|
||||||
|
If you prefer, you can specify a directory into which featured images will be uploaded by adding the following to your project's config:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
SilverStripe\Blog\Model\BlogPost:
|
||||||
|
featured_images_directory: 'blog-images'
|
||||||
|
```
|
||||||
|
|
||||||
|
replacing 'blog-images' with the name of the directory you wish to use.
|
@ -5,6 +5,7 @@
|
|||||||
* [Configuring blog when on large websites](configuring-large-websites.md)
|
* [Configuring blog when on large websites](configuring-large-websites.md)
|
||||||
* [Configuring widgets](configuring-widgets.md)
|
* [Configuring widgets](configuring-widgets.md)
|
||||||
* [Configuring pagination](configuring-pagination.md)
|
* [Configuring pagination](configuring-pagination.md)
|
||||||
|
* [Configuring featured image uploads](configuring-featured-images.md)
|
||||||
|
|
||||||
## CMS user help
|
## CMS user help
|
||||||
* [User guide](userguide/index.md)
|
* [User guide](userguide/index.md)
|
||||||
|
@ -37,6 +37,13 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
*/
|
*/
|
||||||
protected $dataObjectField = 'Title';
|
protected $dataObjectField = 'Title';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name for the buttons displayed in the CMS
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $buttonName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a text field and add button which allows the user to directly create a new
|
* Creates a text field and add button which allows the user to directly create a new
|
||||||
* DataObject by just entering the title.
|
* DataObject by just entering the title.
|
||||||
@ -142,6 +149,19 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
return $this->dataObjectField;
|
return $this->dataObjectField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the button name
|
||||||
|
*
|
||||||
|
* @param $name string
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setButtonName($name)
|
||||||
|
{
|
||||||
|
$this->buttonName = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the database field.
|
* Set the database field.
|
||||||
*
|
*
|
||||||
@ -188,6 +208,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
->setAttribute('placeholder', $obj->fieldLabel($dbField))
|
->setAttribute('placeholder', $obj->fieldLabel($dbField))
|
||||||
->addExtraClass('no-change-track');
|
->addExtraClass('no-change-track');
|
||||||
|
|
||||||
|
if (!$this->buttonName) {
|
||||||
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
||||||
|
$objectName = $obj->i18n_singular_name();
|
||||||
|
$this->buttonName = _t(__CLASS__ . '.ButtonName', '{name}', ['name' => $objectName]);
|
||||||
|
}
|
||||||
|
|
||||||
$addAction = GridField_FormAction::create(
|
$addAction = GridField_FormAction::create(
|
||||||
$gridField,
|
$gridField,
|
||||||
'add',
|
'add',
|
||||||
@ -195,7 +221,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
|||||||
__CLASS__ . '.Add',
|
__CLASS__ . '.Add',
|
||||||
'Add {name}',
|
'Add {name}',
|
||||||
'Add button text',
|
'Add button text',
|
||||||
['name' => $obj->i18n_singular_name()]
|
['name' => $this->buttonName]
|
||||||
),
|
),
|
||||||
'add',
|
'add',
|
||||||
'add'
|
'add'
|
||||||
|
@ -170,6 +170,14 @@ class BlogPost extends Page
|
|||||||
*/
|
*/
|
||||||
private static $minutes_to_read_wpm = 200;
|
private static $minutes_to_read_wpm = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the upload directory for featured images to help keep your files organised
|
||||||
|
*
|
||||||
|
* @config
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $featured_images_directory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the role of the given member.
|
* Determine the role of the given member.
|
||||||
*
|
*
|
||||||
@ -236,6 +244,11 @@ class BlogPost extends Page
|
|||||||
$uploadField = UploadField::create('FeaturedImage', _t(__CLASS__ . '.FeaturedImage', 'Featured Image'));
|
$uploadField = UploadField::create('FeaturedImage', _t(__CLASS__ . '.FeaturedImage', 'Featured Image'));
|
||||||
$uploadField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
|
$uploadField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
|
||||||
|
|
||||||
|
$uploadDirectory = $this->config()->get('featured_images_directory');
|
||||||
|
if ($uploadDirectory != '') {
|
||||||
|
$uploadField->setFolderName($uploadDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var FieldList $fields
|
* @var FieldList $fields
|
||||||
*/
|
*/
|
||||||
|
@ -160,7 +160,7 @@ class BlogPostTest extends SapphireTest
|
|||||||
|
|
||||||
$archiveLink = $blogPost->getMonthlyArchiveLink($type);
|
$archiveLink = $blogPost->getMonthlyArchiveLink($type);
|
||||||
$this->assertContains('archive/', $archiveLink);
|
$this->assertContains('archive/', $archiveLink);
|
||||||
$this->assertContains($expected, $archiveLink);
|
$this->assertStringEndsWith($expected, $archiveLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,6 +182,6 @@ class BlogPostTest extends SapphireTest
|
|||||||
|
|
||||||
$archiveLink = $blogPost->getYearlyArchiveLink();
|
$archiveLink = $blogPost->getYearlyArchiveLink();
|
||||||
$this->assertContains('archive/', $archiveLink);
|
$this->assertContains('archive/', $archiveLink);
|
||||||
$this->assertContains('/2013', $archiveLink);
|
$this->assertStringEndsWith('/2013', $archiveLink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user