ENH Add generic types (#554)

This commit is contained in:
Guy Sartorelli 2024-01-23 13:20:03 +13:00 committed by GitHub
parent f8ecce28ab
commit 11a941f637
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 50 additions and 27 deletions

View File

@ -2,11 +2,14 @@
namespace SilverStripe\Subsites\Extensions;
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Control\HTTP;
use SilverStripe\ORM\DataExtension;
/**
* Extension for the BaseElement object to add subsites support for CMS previews
*
* @extends DataExtension<BaseElement>
*/
class BaseElementSubsites extends DataExtension
{

View File

@ -2,11 +2,15 @@
namespace SilverStripe\Subsites\Extensions;
use SilverStripe\CMS\Controllers\CMSPageAddController;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Subsites\State\SubsiteState;
/**
* @extends Extension<CMSPageAddController>
*/
class CMSPageAddControllerExtension extends Extension
{
public function updatePageOptions(FieldList $fields)

View File

@ -2,12 +2,13 @@
namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Extension;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer;
/**
* @package subsites
* @extends Extension<Controller>
*/
class ControllerSubsites extends Extension
{

View File

@ -5,10 +5,14 @@ namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Assets\FileNameFilter;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\ErrorPage\ErrorPage;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Model\Subsite;
/**
* @extends DataExtension<ErrorPage>
*/
class ErrorPageSubsite extends DataExtension
{
/**

View File

@ -13,8 +13,9 @@ use SilverStripe\Subsites\State\SubsiteState;
/**
* Extension for the File object to add subsites support
*
* @package subsites
* @method Subsite Subsite()
*
* @extends DataExtension<File>
*/
class FileSubsites extends DataExtension
{

View File

@ -2,12 +2,16 @@
namespace SilverStripe\Subsites\Extensions;
use SilverStripe\AssetAdmin\Forms\FolderFormFactory;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Subsites\Model\Subsite;
/**
* @extends Extension<FolderFormFactory>
*/
class FolderFormFactoryExtension extends Extension
{
/**

View File

@ -21,8 +21,9 @@ use SilverStripe\Subsites\State\SubsiteState;
/**
* Extension for the Group object to add subsites support
*
* @package subsites
* @method SilverStripe\ORM\ManyManyList<Subsite> Subsites()
*
* @extends DataExtension<Group&static>
*/
class GroupSubsites extends DataExtension implements PermissionProvider
{

View File

@ -10,8 +10,9 @@ use SilverStripe\Subsites\State\SubsiteState;
* This extension adds the current Subsite ID as an additional factor to the Hints Cßache Key, which is used to cache
* the Site Tree Hints (which include allowed pagetypes).
*
* @package SilverStripe\Subsites\Extensions
* @see CMSMain::generateHintsCacheKey()
*
* @extends Extension<CMSMain>
*/
class HintsCacheKeyExtension extends Extension
{

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\CMSMenu;
use SilverStripe\Admin\CMSProfileController;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\LeftAndMainExtension;
use SilverStripe\CMS\Controllers\CMSPagesController;
use SilverStripe\CMS\Model\SiteTree;
@ -27,7 +28,7 @@ use SilverStripe\View\Requirements;
/**
* Decorator designed to add subsites support to LeftAndMain
*
* @package subsites
* @extends LeftAndMainExtension<LeftAndMain>
*/
class LeftAndMainSubsites extends LeftAndMainExtension
{
@ -66,8 +67,7 @@ class LeftAndMainSubsites extends LeftAndMainExtension
* @param bool $includeMainSite
* @param string $mainSiteTitle
* @param null $member
* @return ArrayList of <a href='psi_element://Subsite'>Subsite</a> instances.
* instances.
* @return ArrayList<Subsite> of Subsite instances.
*/
public function sectionSites($includeMainSite = true, $mainSiteTitle = 'Main site', $member = null)
{
@ -141,12 +141,11 @@ class LeftAndMainSubsites extends LeftAndMainExtension
return Subsite::all_accessible_sites();
}
/*
/**
* Generates a list of subsites with the data needed to
* produce a dropdown site switcher
* @return ArrayList
* @return ArrayList<Subsite>
*/
public function ListSubsites()
{
$list = $this->Subsites();

View File

@ -13,7 +13,10 @@ use SilverStripe\Subsites\State\SubsiteState;
/**
* Extension for the SiteConfig object to add subsites support
*
* @method Subsite Subsite()
*
* @extends DataExtension<SiteConfig&static>
*/
class SiteConfigSubsites extends DataExtension
{

View File

@ -32,8 +32,11 @@ use SilverStripe\VersionedAdmin\Controllers\HistoryViewerController;
/**
* Extension for the SiteTree object to add subsites support
*
* @method SilverStripe\ORM\ManyManyList<SiteTree> CrossSubsiteLinkTracking()
* @method Subsite Subsite()
*
* @extends DataExtension<SiteTree&static>
*/
class SiteTreeSubsites extends DataExtension
{
@ -187,7 +190,6 @@ class SiteTreeSubsites extends DataExtension
->withState(function (SubsiteState $newState) use ($subsiteID, $includeChildren) {
$newState->setSubsiteId($subsiteID);
/** @var SiteTree $page */
$page = $this->owner;
try {
@ -389,7 +391,6 @@ class SiteTreeSubsites extends DataExtension
*/
public static function contentcontrollerInit($controller)
{
/** @var Subsite $subsite */
$subsite = Subsite::currentSubsite();
if ($subsite && $subsite->Theme) {

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Extension;
/**
@ -12,6 +13,8 @@ use SilverStripe\Core\Extension;
* MyAdmin::add_extension('SubsiteMenuExtension');
*
* Or you can include the subsiteCMSShowInMenu function in your admin class and have it return true
*
* @extends Extension<LeftAndMain>
*/
class SubsiteMenuExtension extends Extension
{

View File

@ -178,7 +178,7 @@ class Subsite extends DataObject
/**
* Gets the subsite currently set in the session.
*
* @return DataObject The current Subsite
* @return Subsite The current Subsite
*/
public static function currentSubsite()
{
@ -256,7 +256,7 @@ class Subsite extends DataObject
$schema = DataObject::getSchema();
$domainTableName = $schema->tableName(SubsiteDomain::class);
if (!DB::get_schema()->hasTable($domainTableName)) {
// Table hasn't been created yet. Might be a dev/build, skip.
return 0;
@ -304,13 +304,13 @@ class Subsite extends DataObject
}
/**
*
* @param string $className
* @template T of DataObject
* @param class-string<T> $className
* @param string $filter
* @param string $sort
* @param string $join
* @param string $limit
* @return DataList
* @return DataList<T>
*/
public static function get_from_all_subsites($className, $filter = '', $sort = '', $join = '', $limit = '')
{
@ -371,11 +371,11 @@ class Subsite extends DataObject
return $subsites;
}
/*
/**
* Returns an ArrayList of the subsites accessible to the current user.
* It's enough for any section to be accessible for the site to be included.
*
* @return ArrayList of {@link Subsite} instances.
* @return ArrayList<Subsite> of {@link Subsite} instances.
*/
public static function all_accessible_sites($includeMainSite = true, $mainSiteTitle = 'Main site', $member = null)
{
@ -420,7 +420,7 @@ class Subsite extends DataObject
* @param $includeMainSite bool If true, the main site will be included if appropriate.
* @param $mainSiteTitle string The label to give to the main site
* @param $member int|Member The member attempting to access the sites
* @return DataList|ArrayList of {@link Subsite} instances
* @return DataList<Subsite>|ArrayList<Subsite> of {@link Subsite} instances
*/
public static function accessible_sites(
$permCode,
@ -466,8 +466,8 @@ class Subsite extends DataObject
)
->innerJoin(
'Permission',
"\"Group\".\"ID\"=\"Permission\".\"GroupID\"
AND \"Permission\".\"Code\"
"\"Group\".\"ID\"=\"Permission\".\"GroupID\"
AND \"Permission\".\"Code\"
IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
);
@ -475,7 +475,6 @@ class Subsite extends DataObject
$subsites = new ArrayList();
}
/** @var DataList $rolesSubsites */
$rolesSubsites = DataList::create(Subsite::class)
->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
@ -491,8 +490,8 @@ class Subsite extends DataObject
->innerJoin('PermissionRole', '"Group_Roles"."PermissionRoleID"="PermissionRole"."ID"')
->innerJoin(
'PermissionRoleCode',
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"
AND \"PermissionRoleCode\".\"Code\"
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"
AND \"PermissionRoleCode\".\"Code\"
IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
);
@ -925,9 +924,8 @@ JS;
}
/**
*
* @param array $permissionCodes
* @return DataList
* @return DataList<Member>
*/
public function getMembersByPermission($permissionCodes = ['ADMIN'])
{