Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Add generic types #554

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Extensions/BaseElementSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/Extensions/CMSPageAddControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/ControllerSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions src/Extensions/ErrorPageSubsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
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
{
/**
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/FileSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
/**
* Extension for the File object to add subsites support
*
* @package subsites
* @method Subsite Subsite()
*
* @extends DataExtension<File>
*/
class FileSubsites extends DataExtension
{
Expand Down
4 changes: 4 additions & 0 deletions src/Extensions/FolderFormFactoryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/GroupSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
/**
* 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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/HintsCacheKeyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* 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
{
Expand Down
11 changes: 5 additions & 6 deletions src/Extensions/LeftAndMainSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -27,7 +28,7 @@
/**
* Decorator designed to add subsites support to LeftAndMain
*
* @package subsites
* @extends LeftAndMainExtension<LeftAndMain>
*/
class LeftAndMainSubsites extends LeftAndMainExtension
{
Expand Down Expand Up @@ -66,8 +67,7 @@ public function updatePageOptions(&$fields)
* @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)
{
Expand Down Expand Up @@ -141,12 +141,11 @@ public function Subsites()
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();
Expand Down
3 changes: 3 additions & 0 deletions src/Extensions/SiteConfigSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

/**
* Extension for the SiteConfig object to add subsites support
*
* @method Subsite Subsite()
*
* @extends DataExtension<SiteConfig&static>
*/
class SiteConfigSubsites extends DataExtension
{
Expand Down
5 changes: 3 additions & 2 deletions src/Extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@

/**
* 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
{
Expand Down Expand Up @@ -187,7 +190,6 @@ public function duplicateToSubsitePrep($subsiteID, $includeChildren)
->withState(function (SubsiteState $newState) use ($subsiteID, $includeChildren) {
$newState->setSubsiteId($subsiteID);

/** @var SiteTree $page */
$page = $this->owner;

try {
Expand Down Expand Up @@ -389,7 +391,6 @@ public function canPublish($member = null)
*/
public static function contentcontrollerInit($controller)
{
/** @var Subsite $subsite */
$subsite = Subsite::currentSubsite();

if ($subsite && $subsite->Theme) {
Expand Down
3 changes: 3 additions & 0 deletions src/Extensions/SubsiteMenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Subsites\Extensions;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Extension;

/**
Expand All @@ -12,6 +13,8 @@
* 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
{
Expand Down
28 changes: 13 additions & 15 deletions src/Model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static function set_allowed_themes($themes)
/**
* Gets the subsite currently set in the session.
*
* @return DataObject The current Subsite
* @return Subsite The current Subsite
*/
public static function currentSubsite()
{
Expand Down Expand Up @@ -256,7 +256,7 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t
$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;
Expand Down Expand Up @@ -304,13 +304,13 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t
}

/**
*
* @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 = '')
{
Expand Down Expand Up @@ -371,11 +371,11 @@ public static function all_sites($includeMainSite = true, $mainSiteTitle = 'Main
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)
{
Expand Down Expand Up @@ -420,7 +420,7 @@ public static function all_accessible_sites($includeMainSite = true, $mainSiteTi
* @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,
Expand Down Expand Up @@ -466,16 +466,15 @@ public static function accessible_sites(
)
->innerJoin(
'Permission',
"\"Group\".\"ID\"=\"Permission\".\"GroupID\"
AND \"Permission\".\"Code\"
"\"Group\".\"ID\"=\"Permission\".\"GroupID\"
AND \"Permission\".\"Code\"
IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
);

if (!$subsites) {
$subsites = new ArrayList();
}

/** @var DataList $rolesSubsites */
$rolesSubsites = DataList::create(Subsite::class)
->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
Expand All @@ -491,8 +490,8 @@ public static function accessible_sites(
->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')"
);

Expand Down Expand Up @@ -925,9 +924,8 @@ public function activate()
}

/**
*
* @param array $permissionCodes
* @return DataList
* @return DataList<Member>
*/
public function getMembersByPermission($permissionCodes = ['ADMIN'])
{
Expand Down