-
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 Allow developers to exclude LinkText field #215
NEW Allow developers to exclude LinkText field #215
Conversation
private bool $excludeLinkTextField = false; | ||
|
||
public function setExcludeLinkTextField(bool $include): static | ||
{ | ||
$this->excludeLinkTextField = $include; | ||
return $this; | ||
} | ||
|
||
public function getExcludeLinkTextField(): bool | ||
{ | ||
return $this->excludeLinkTextField; | ||
} |
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 didn't want to create a whole separate trait just for this, nor did I want to duplicate code by putting it into each field.
I've added a note to #78 to consider combining the traits into an abstract class instead - assuming that is done, it doesn't matter too much where this code goes for this PR since it'll all end up in the same place anyway.
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.
Add a unit test on LinkFieldController that passing an 'excludeLinkTextField' get param will result in a schema without a LinkText field
@@ -88,7 +88,7 @@ public function linkForm(): Form | |||
} | |||
$operation = 'create'; | |||
} | |||
return $this->createLinkForm($link, $operation); | |||
return $this->createLinkForm($link, $operation, (bool) $this->getRequest()->getVar('excludeTextField')); |
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.
Bit messy having this one on line, create an intermediate variable.
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'd argue having the intermediate variable is unnecessary 😅 Gotta love subjective code styles.
I've made the change.
@@ -52,6 +52,7 @@ const LinkField = ({ | |||
ownerID, | |||
ownerClass, | |||
ownerRelation, | |||
excludeTextField = false, |
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.
excludeTextField = false, | |
excludeLinkTextField = false, |
It's really confusing omitting the Link
from this variable, especially since in other places it's not omitted. It's a specific field we want to remove, not just a generic 'textfield'
Update all variables through including the ones passed to jquery as an element attribute e.g. 'data-exclude-textfield' should be 'data-exclude-linktext-field
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.
Done
55cff9d
to
4ebc84d
Compare
Done |
use SilverStripe\CMS\Model\SiteTree; | ||
use ReflectionMethod; | ||
use SilverStripe\Dev\FunctionalTest; | ||
use SilverStripe\LinkField\Tests\Controllers\LinkFieldControllerTest\TestPhoneLink; | ||
use SilverStripe\Core\Config\Config; |
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.
use
statements that were removed are unrelated refactoring - those were not in use.
4ebc84d
to
48b195e
Compare
client/src/entwine/LinkField.js
Outdated
@@ -51,6 +51,7 @@ jQuery.entwine('ss', ($) => { | |||
ownerID: inputField.data('owner-id'), | |||
ownerClass: inputField.data('owner-class'), | |||
ownerRelation: inputField.data('owner-relation'), | |||
excludeLinkTextField: inputField.data('exclude-textfield'), |
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.
excludeLinkTextField: inputField.data('exclude-textfield'), | |
excludeLinkTextField: inputField.data('exclude-linktext-field'), |
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.
Oh yeah oops. Fixed.
src/Form/LinkField.php
Outdated
@@ -51,6 +51,7 @@ protected function getDefaultAttributes(): array | |||
$attributes['data-owner-id'] = $ownerFields['ID']; | |||
$attributes['data-owner-class'] = $ownerFields['Class']; | |||
$attributes['data-owner-relation'] = $ownerFields['Relation']; | |||
$attributes['data-exclude-textfield'] = $this->getExcludeLinkTextField(); |
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.
$attributes['data-exclude-textfield'] = $this->getExcludeLinkTextField(); | |
$attributes['data-exclude-linktext-field'] = $this->getExcludeLinkTextField(); |
src/Form/MultiLinkField.php
Outdated
@@ -70,6 +71,7 @@ protected function getDefaultAttributes(): array | |||
$attributes['data-owner-id'] = $ownerFields['ID']; | |||
$attributes['data-owner-class'] = $ownerFields['Class']; | |||
$attributes['data-owner-relation'] = $ownerFields['Relation']; | |||
$attributes['data-exclude-textfield'] = $this->getExcludeLinkTextField(); |
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.
$attributes['data-exclude-textfield'] = $this->getExcludeLinkTextField(); | |
$attributes['data-exclude-linktext-field'] = $this->getExcludeLinkTextField(); |
48b195e
to
1522f56
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.
Tested locally works good
Because this gets passed from PHP through to JS, back to PHP for the controller, and then finally through to JS again for the form modal, I think the only way to adequately test this is through behat tests. There's a card in progress right now to create behat tests, so I'm not going to duplicate efforts creating a behat setup in this PR.
If the reviewer agrees, I'll create a separate card to add behat tests for this scenario, which can be blocked on the existing behat card.
Issue