Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 domain support for the main site. #473
ENH Add domain support for the main site. #473
Changes from all commits
f52b857
0b7a63e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this check? If $this->owner->SubsiteID == 0 then this will cause an exception i.e.
(null)->domain()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm about 60% sure
$this->owner->Subsite()
would give a new Subsite object with no ID - but that would need to be checked if someone picks this PR up again. If that's not the case, then another mechanism will need to be added here to get the main site Domain where no subsite is set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm 100% sure.
https://github.com/silverstripe/silverstripe-framework/blob/6d90eec0c883a69a87e0ad31d0e8ba617b809057/src/ORM/DataObject.php#L1890
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now seeing the method this is in and the not-in-db check... is there a better/different place this could go to? Alternatively, can we get more explanation why it's here and why we need to check it's not in the db?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be
if (!$this->ID) {
.This is for situations like
SiteTreeSubsites::alternateAbsoluteLink
(inline below for convenience) where we calldomain
(which callsgetPrimarySubsiteDomain
) on the relationship directly from thehas_one
relation object.If the page has no
SubiteID
(i.e. it belongs to the main site), the relation object will still be an instantiatedSubsite
object which has no ID and which returnsfalse
fromisInDB
- so we end up getting the main site domain.I can't think of somewhere else to put the call, since the intention is to distinguish between a main site or subsite
Subsite
object (where a main siteSubsite
object is anySubsite
object without an ID, effectively) when fetching the domain.This allows project-specific code or code from other modules to remain the same (if they don't have the "if there is a subsite ID" check in place - in that case there's still only a very minor change required) and now get the added benefit of automagically fetching the correct main site domain as well.
silverstripe-subsites/src/Extensions/SiteTreeSubsites.php
Lines 410 to 417 in 0b7a63e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised I didn't explicitly say why we need to check for the main site vs an actual subsite there - the main site domains aren't stored on the Domains relation of any subsite object, so we can't just use
$this->Domains()
for the main site.