-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from creative-commoners/pulls/2.0/fix-file-su…
…bsites API Move subsite dropdown logic for folders into FolderFormFactoryExtension
- Loading branch information
Showing
16 changed files
with
103 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>' | ||
)); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Subsites\Tests\Extensions; | ||
|
||
use SilverStripe\AssetAdmin\Forms\FolderFormFactory; | ||
use SilverStripe\Assets\Folder; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\FormFactory; | ||
|
||
class FolderFormFactoryExtensionTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'FolderFormFactoryExtensionTest.yml'; | ||
|
||
public function testSubsitesFolderDropdown() | ||
{ | ||
$this->logInWithPermission('ADMIN'); | ||
|
||
/** @var Folder $folder */ | ||
$folder = $this->objFromFixture(Folder::class, 'folder_a'); | ||
|
||
/** @var Form $folderForm */ | ||
$folderForm = FolderFormFactory::create()->getForm(null, FormFactory::DEFAULT_NAME, [ | ||
'Record' => $folder | ||
]); | ||
|
||
$source = array_values($folderForm->Fields()->fieldByName('SubsiteID')->getSource()); | ||
$result = array_values($source); | ||
|
||
$this->assertContains('Main site', $result); | ||
$this->assertContains('Subsite A', $result); | ||
$this->assertContains('Subsite B', $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SilverStripe\Subsites\Model\Subsite: | ||
main: | ||
Title: Template | ||
subsite_a: | ||
Title: Subsite A | ||
subsite_b: | ||
Title: Subsite B | ||
|
||
SilverStripe\Assets\Folder: | ||
folder_a: | ||
Title: Folder A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters