From 1dd1f2ce6c1361c197caf3ba08f534f10bbf0473 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 Jan 2018 16:03:58 +1300 Subject: [PATCH 1/5] API Move subsite dropdown logic for folders into FolderFormFactoryExtension --- _config/extensions.yml | 4 ++ css/LeftAndMain_Subsites.css | 4 +- src/Extension/FileSubsites.php | 44 +----------------- src/Extension/FolderFormFactoryExtension.php | 47 ++++++++++++++++++++ 4 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 src/Extension/FolderFormFactoryExtension.php diff --git a/_config/extensions.yml b/_config/extensions.yml index 506b59e3..960b1d30 100644 --- a/_config/extensions.yml +++ b/_config/extensions.yml @@ -28,6 +28,10 @@ SilverStripe\Assets\File: extensions: - SilverStripe\Subsites\Extensions\FileSubsites +SilverStripe\AssetAdmin\Forms\FolderFormFactory: + extensions: + - SilverStripe\Subsites\Extensions\FolderFormFactoryExtension + SilverStripe\ErrorPage\ErrorPage: extensions: - SilverStripe\Subsites\Extensions\ErrorPageSubsite diff --git a/css/LeftAndMain_Subsites.css b/css/LeftAndMain_Subsites.css index d123ff2e..7b66c2a1 100644 --- a/css/LeftAndMain_Subsites.css +++ b/css/LeftAndMain_Subsites.css @@ -76,7 +76,7 @@ body.SubsiteAdmin .right form #URL .fieldgroup * { display: none; } -#Root_DetailsView .subsites-move-dropdown, -#Form_ItemEditForm .subsites-move-dropdown { +.editor__details .subsites-move-dropdown, +#Form_fileEditorForm.subsites-move-dropdown { display: block; } diff --git a/src/Extension/FileSubsites.php b/src/Extension/FileSubsites.php index fbaa5f70..2ca796a1 100644 --- a/src/Extension/FileSubsites.php +++ b/src/Extension/FileSubsites.php @@ -2,10 +2,6 @@ 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\DataQuery; use SilverStripe\ORM\Queries\SQLSelect; @@ -41,43 +37,6 @@ public function alternateTreeTitle() 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', - '

' . - _t( - 'ASSETADMIN.SUBSITENOTICE', - 'Folders and files created in the main site are accessible by all subsites.' - ) - . '

' - )); - } - } - } - /** * Update any requests to limit the results to the current site * @param SQLSelect $query @@ -90,7 +49,8 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) } // 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(); if (isset($from['SiteTree_ImageTracking']) || $query->filtersOnID()) { diff --git a/src/Extension/FolderFormFactoryExtension.php b/src/Extension/FolderFormFactoryExtension.php new file mode 100644 index 00000000..4fcb03ad --- /dev/null +++ b/src/Extension/FolderFormFactoryExtension.php @@ -0,0 +1,47 @@ +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', + '

' . + _t( + __CLASS__ . '.SUBSITENOTICE', + 'Folders and files created in the main site are accessible by all subsites.' + ) + . '

' + )); + } + } +} From a0836bed794ef64b65fd7814675faa094dbf056f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 Jan 2018 16:04:09 +1300 Subject: [PATCH 2/5] NEW Add PHP 7.2 to Travis build matrix --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68957d54..5f97e5cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ matrix: include: - php: 5.6 env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 - - php: 7.0 - env: DB=PGSQL PHPUNIT_TEST=1 - php: 7.1 + env: DB=PGSQL PHPUNIT_TEST=1 + - php: 7.2 env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 - php: 7.0 env: DB=MYSQL BEHAT_TEST=1 From 4f174ffd6e0a2e4a705090f47df90801363ea91b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 Jan 2018 16:22:35 +1300 Subject: [PATCH 3/5] NEW Add test for FolderFormFactoryExtension with a separate fixture --- .../FolderFormFactoryExtensionTest.php | 34 +++++++++++++++++++ .../FolderFormFactoryExtensionTest.yml | 11 ++++++ tests/php/FileSubsitesTest.php | 32 ----------------- 3 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 tests/php/Extensions/FolderFormFactoryExtensionTest.php create mode 100644 tests/php/Extensions/FolderFormFactoryExtensionTest.yml diff --git a/tests/php/Extensions/FolderFormFactoryExtensionTest.php b/tests/php/Extensions/FolderFormFactoryExtensionTest.php new file mode 100644 index 00000000..ebb55740 --- /dev/null +++ b/tests/php/Extensions/FolderFormFactoryExtensionTest.php @@ -0,0 +1,34 @@ +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); + } +} diff --git a/tests/php/Extensions/FolderFormFactoryExtensionTest.yml b/tests/php/Extensions/FolderFormFactoryExtensionTest.yml new file mode 100644 index 00000000..369c1994 --- /dev/null +++ b/tests/php/Extensions/FolderFormFactoryExtensionTest.yml @@ -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 diff --git a/tests/php/FileSubsitesTest.php b/tests/php/FileSubsitesTest.php index c59839e5..b3484faf 100644 --- a/tests/php/FileSubsitesTest.php +++ b/tests/php/FileSubsitesTest.php @@ -12,15 +12,6 @@ class FileSubsitesTest extends BaseSubsiteTest { protected static $fixture_file = 'SubsiteTest.yml'; - /** - * Disable other file extensions - * - * @var array - */ - protected static $illegal_extensions = [ - SiteTree::class => ['Translatable'], // @todo implement namespace for Translatable - ]; - public function testTrivialFeatures() { $this->assertTrue(is_array(singleton(FileSubsites::class)->extraStatics())); @@ -73,27 +64,4 @@ public function testWritingSubsiteID() $file->onAfterUpload(); $this->assertEquals($folder->SubsiteID, $file->SubsiteID); } - - public function testSubsitesFolderDropdown() - { - $this->logInAs('admin'); - - $file = new Folder(); - - $source = array_values($file->getCMSFields()->dataFieldByName('SubsiteID')->getSource()); - asort($source); - - $this->assertEquals([ - 'Main site', - 'Subsite1 Template', - 'Subsite2 Template', - 'Template', - 'Test 1', - 'Test 2', - 'Test 3', - 'Test Non-SSL', - 'Test SSL', - 'Test Vagrant VM on port 8080' - ], array_values($source)); - } } From ace068b93d9eb3f3ed99fa904a2ffaa176c32b4e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 Jan 2018 16:23:11 +1300 Subject: [PATCH 4/5] FIX Move extensions to correct folder location for PSR-4 compatibility --- src/{Extension => Extensions}/CMSPageAddControllerExtension.php | 0 src/{Extension => Extensions}/ControllerSubsites.php | 0 src/{Extension => Extensions}/ErrorPageSubsite.php | 0 src/{Extension => Extensions}/FileSubsites.php | 0 src/{Extension => Extensions}/FolderFormFactoryExtension.php | 0 src/{Extension => Extensions}/GroupSubsites.php | 0 src/{Extension => Extensions}/LeftAndMainSubsites.php | 0 src/{Extension => Extensions}/SiteConfigSubsites.php | 0 src/{Extension => Extensions}/SiteTreeSubsites.php | 0 src/{Extension => Extensions}/SubsiteMenuExtension.php | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename src/{Extension => Extensions}/CMSPageAddControllerExtension.php (100%) rename src/{Extension => Extensions}/ControllerSubsites.php (100%) rename src/{Extension => Extensions}/ErrorPageSubsite.php (100%) rename src/{Extension => Extensions}/FileSubsites.php (100%) rename src/{Extension => Extensions}/FolderFormFactoryExtension.php (100%) rename src/{Extension => Extensions}/GroupSubsites.php (100%) rename src/{Extension => Extensions}/LeftAndMainSubsites.php (100%) rename src/{Extension => Extensions}/SiteConfigSubsites.php (100%) rename src/{Extension => Extensions}/SiteTreeSubsites.php (100%) rename src/{Extension => Extensions}/SubsiteMenuExtension.php (100%) diff --git a/src/Extension/CMSPageAddControllerExtension.php b/src/Extensions/CMSPageAddControllerExtension.php similarity index 100% rename from src/Extension/CMSPageAddControllerExtension.php rename to src/Extensions/CMSPageAddControllerExtension.php diff --git a/src/Extension/ControllerSubsites.php b/src/Extensions/ControllerSubsites.php similarity index 100% rename from src/Extension/ControllerSubsites.php rename to src/Extensions/ControllerSubsites.php diff --git a/src/Extension/ErrorPageSubsite.php b/src/Extensions/ErrorPageSubsite.php similarity index 100% rename from src/Extension/ErrorPageSubsite.php rename to src/Extensions/ErrorPageSubsite.php diff --git a/src/Extension/FileSubsites.php b/src/Extensions/FileSubsites.php similarity index 100% rename from src/Extension/FileSubsites.php rename to src/Extensions/FileSubsites.php diff --git a/src/Extension/FolderFormFactoryExtension.php b/src/Extensions/FolderFormFactoryExtension.php similarity index 100% rename from src/Extension/FolderFormFactoryExtension.php rename to src/Extensions/FolderFormFactoryExtension.php diff --git a/src/Extension/GroupSubsites.php b/src/Extensions/GroupSubsites.php similarity index 100% rename from src/Extension/GroupSubsites.php rename to src/Extensions/GroupSubsites.php diff --git a/src/Extension/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php similarity index 100% rename from src/Extension/LeftAndMainSubsites.php rename to src/Extensions/LeftAndMainSubsites.php diff --git a/src/Extension/SiteConfigSubsites.php b/src/Extensions/SiteConfigSubsites.php similarity index 100% rename from src/Extension/SiteConfigSubsites.php rename to src/Extensions/SiteConfigSubsites.php diff --git a/src/Extension/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php similarity index 100% rename from src/Extension/SiteTreeSubsites.php rename to src/Extensions/SiteTreeSubsites.php diff --git a/src/Extension/SubsiteMenuExtension.php b/src/Extensions/SubsiteMenuExtension.php similarity index 100% rename from src/Extension/SubsiteMenuExtension.php rename to src/Extensions/SubsiteMenuExtension.php From a88ac5d05d4e93de320739add6633fd8125efa4b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 18 Jan 2018 16:27:00 +1300 Subject: [PATCH 5/5] Switch from precise to trusty in Travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f97e5cd..2b7c460d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ language: php addons: firefox: "31.0" -# Required for Behat, currently -dist: precise +dist: trusty env: global: