-
Notifications
You must be signed in to change notification settings - Fork 15
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
NEW Allowed link types #137
NEW Allowed link types #137
Conversation
4dd66d5
to
7368ff8
Compare
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.
That's a good solid first pass. I tested it locally and it works great.
There wasn't an explicit AC for this, but I think logically we should have an exception thrown if you try to save a link of a type that is disallowed for the field. e.g. Your LinkField is configured to only allow EmailLink, but you do a manual AJAX query to save a SiteTreeLink into it.
*/ | ||
public function setDisabledTypes(array $types): static | ||
{ | ||
if (is_array($types) || !empty($types)) { |
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.
if (is_array($types) || !empty($types)) { | |
if (!empty($types)) { |
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.
Updated
421a198
to
5a2c284
Compare
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.
My biggest concern is that this won't work with Elemental.
I left a link to how to react props so it works with Elemental. If it doesn't make sense let me know, and we can go through it together.
9605dfe
to
4df1552
Compare
#137 (comment) |
6d0cae5
to
6981fb6
Compare
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.
It's almost there. Just a few ambiguities left to address.
src/Models/Link.php
Outdated
*/ | ||
public function getShortCode(): string | ||
{ | ||
return strtolower(str_replace([' ', 'Link'], '', ClassInfo::shortName($this))) ?? ''; |
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.
This is a minor tweak.
ClassInfo::shortName
won't return spaces, so you don't need to remove spaces.- It would a bit safer to only remove the
Link
part if it's at the end of the class name. So usingrtrim
would be a bit safer here.
return strtolower(str_replace([' ', 'Link'], '', ClassInfo::shortName($this))) ?? ''; | |
return strtolower(rtrim(ClassInfo::shortName($this), 'Link')) ?? ''; |
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.
Updated
* Set allowed types for LinkField | ||
* @param string[] $types | ||
*/ | ||
public function setAllowedTypes(array $types): static |
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.
What's our thinking when an empty array is passed to this method?
- Do we want to throw an exception?
- Do we want to unset any restriction and go back to allowing all Link types?
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 put my comment here #137 (comment).
I think an empty array is invalid argument.
@@ -1,2 +1,2 @@ | |||
<input $AttributesHTML /> | |||
<div data-field-id="$ID" data-schema-component="$SchemaComponent" class="entwine-linkfield"></div> | |||
<div data-field-id="$ID" data-schema-component="$SchemaComponent" class="entwine-linkfield" data-types="$TypesProps"></div> |
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.
That doesn't need to be handle here and now, but we'll probably want to pass all our props in a single attribute here. Otherwise, every time we'll need to make our bootstrapping logic more complex to handle things like read only state.
That's more of a comment. Nothing to action at this moment.
} | ||
|
||
/** | ||
* @dataProvider allLinkTypesDataProvider |
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.
If you have only one test case, you shouldn't be using a data provider.
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.
Updated
6981fb6
to
84824c7
Compare
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.
Happiness has been achieved.
Description
AllowedLinkClassesTrait
that adds methods to set available link types or exclude them.Registry::class
has been removed.Parent issue