mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
API Move subsite dropdown logic for folders into FolderFormFactoryExtension
This commit is contained in:
parent
a201e7e953
commit
1dd1f2ce6c
@ -28,6 +28,10 @@ SilverStripe\Assets\File:
|
|||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\Subsites\Extensions\FileSubsites
|
- SilverStripe\Subsites\Extensions\FileSubsites
|
||||||
|
|
||||||
|
SilverStripe\AssetAdmin\Forms\FolderFormFactory:
|
||||||
|
extensions:
|
||||||
|
- SilverStripe\Subsites\Extensions\FolderFormFactoryExtension
|
||||||
|
|
||||||
SilverStripe\ErrorPage\ErrorPage:
|
SilverStripe\ErrorPage\ErrorPage:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\Subsites\Extensions\ErrorPageSubsite
|
- SilverStripe\Subsites\Extensions\ErrorPageSubsite
|
||||||
|
@ -76,7 +76,7 @@ body.SubsiteAdmin .right form #URL .fieldgroup * {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#Root_DetailsView .subsites-move-dropdown,
|
.editor__details .subsites-move-dropdown,
|
||||||
#Form_ItemEditForm .subsites-move-dropdown {
|
#Form_fileEditorForm.subsites-move-dropdown {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Subsites\Extensions;
|
namespace SilverStripe\Subsites\Extensions;
|
||||||
|
|
||||||
use SilverStripe\Assets\Folder;
|
|
||||||
use SilverStripe\Forms\DropdownField;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
|
||||||
use SilverStripe\Forms\LiteralField;
|
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
use SilverStripe\ORM\DataQuery;
|
use SilverStripe\ORM\DataQuery;
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
@ -41,43 +37,6 @@ class FileSubsites extends DataExtension
|
|||||||
return $this->owner->Title;
|
return $this->owner->Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add subsites-specific fields to the folder editor.
|
|
||||||
* @param FieldList $fields
|
|
||||||
*/
|
|
||||||
public function updateCMSFields(FieldList $fields)
|
|
||||||
{
|
|
||||||
if ($this->owner instanceof Folder) {
|
|
||||||
$sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin');
|
|
||||||
$values = [];
|
|
||||||
$values[0] = _t(__CLASS__ . '.AllSitesDropdownOpt', 'All sites');
|
|
||||||
foreach ($sites as $site) {
|
|
||||||
$values[$site->ID] = $site->Title;
|
|
||||||
}
|
|
||||||
ksort($values);
|
|
||||||
if ($sites) {
|
|
||||||
//Dropdown needed to move folders between subsites
|
|
||||||
/** @var @skipUpgrade */
|
|
||||||
$dropdown = new DropdownField(
|
|
||||||
'SubsiteID',
|
|
||||||
_t(__CLASS__ . '.SubsiteFieldLabel', 'Subsite'),
|
|
||||||
$values
|
|
||||||
);
|
|
||||||
$dropdown->addExtraClass('subsites-move-dropdown');
|
|
||||||
$fields->push($dropdown);
|
|
||||||
$fields->push(new LiteralField(
|
|
||||||
'Message',
|
|
||||||
'<p class="message notice">' .
|
|
||||||
_t(
|
|
||||||
'ASSETADMIN.SUBSITENOTICE',
|
|
||||||
'Folders and files created in the main site are accessible by all subsites.'
|
|
||||||
)
|
|
||||||
. '</p>'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update any requests to limit the results to the current site
|
* Update any requests to limit the results to the current site
|
||||||
* @param SQLSelect $query
|
* @param SQLSelect $query
|
||||||
@ -90,7 +49,8 @@ class FileSubsites extends DataExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
|
// If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
|
||||||
//@TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice
|
// @TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and
|
||||||
|
// ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice
|
||||||
|
|
||||||
$from = $query->getFrom();
|
$from = $query->getFrom();
|
||||||
if (isset($from['SiteTree_ImageTracking']) || $query->filtersOnID()) {
|
if (isset($from['SiteTree_ImageTracking']) || $query->filtersOnID()) {
|
||||||
|
47
src/Extension/FolderFormFactoryExtension.php
Normal file
47
src/Extension/FolderFormFactoryExtension.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Subsites\Extensions;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Extension;
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Forms\LiteralField;
|
||||||
|
use SilverStripe\Subsites\Model\Subsite;
|
||||||
|
|
||||||
|
class FolderFormFactoryExtension extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Add subsites-specific fields to the folder editor.
|
||||||
|
* @param FieldList $fields
|
||||||
|
*/
|
||||||
|
public function updateFormFields(FieldList $fields)
|
||||||
|
{
|
||||||
|
$sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin');
|
||||||
|
$values = [];
|
||||||
|
$values[0] = _t(__CLASS__ . '.AllSitesDropdownOpt', 'All sites');
|
||||||
|
foreach ($sites as $site) {
|
||||||
|
$values[$site->ID] = $site->Title;
|
||||||
|
}
|
||||||
|
ksort($values);
|
||||||
|
if ($sites) {
|
||||||
|
// Dropdown needed to move folders between subsites
|
||||||
|
/** @var @skipUpgrade */
|
||||||
|
$dropdown = DropdownField::create(
|
||||||
|
'SubsiteID',
|
||||||
|
_t(__CLASS__ . '.SubsiteFieldLabel', 'Subsite'),
|
||||||
|
$values
|
||||||
|
);
|
||||||
|
$dropdown->addExtraClass('subsites-move-dropdown');
|
||||||
|
$fields->push($dropdown);
|
||||||
|
$fields->push(LiteralField::create(
|
||||||
|
'Message',
|
||||||
|
'<p class="message notice">' .
|
||||||
|
_t(
|
||||||
|
__CLASS__ . '.SUBSITENOTICE',
|
||||||
|
'Folders and files created in the main site are accessible by all subsites.'
|
||||||
|
)
|
||||||
|
. '</p>'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user