-
-
Notifications
You must be signed in to change notification settings - Fork 228
Fix url form field #1439
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
Open
mjauvin
wants to merge
4
commits into
develop
Choose a base branch
from
fix-url-field
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−20
Open
Fix url form field #1439
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
90ac018
add magic methods to allow dynamic field configs
mjauvin 0b94f81
do not set $size="large" for all fields
mjauvin 6c2773e
remove attributes already set by FormField getAttributes()
mjauvin a85b087
be more strict before adding attributes
mjauvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,9 +91,9 @@ class FormField | |
| public $span = 'full'; | ||
|
|
||
| /** | ||
| * @var string Specifies a size. Possible values: tiny, small, large, huge, giant. | ||
| * @var string|int Specifies a size. Possible values for textarea: tiny, small, large, huge, giant. | ||
| */ | ||
| public $size = 'large'; | ||
| public $size; | ||
|
|
||
| /** | ||
| * @var string Specifies contextual visibility of this form field. | ||
|
|
@@ -211,7 +211,7 @@ public function span($value = 'full') | |
| } | ||
|
|
||
| /** | ||
| * Sets a side of the field on a form. | ||
| * Sets the size of the field on a form. | ||
| * @param string $value Specifies a size. Possible values: tiny, small, large, huge, giant | ||
| */ | ||
| public function size($value = 'large') | ||
|
|
@@ -259,6 +259,11 @@ public function options($value = null) | |
| */ | ||
| public function displayAs($type, $config = []) | ||
| { | ||
| if (in_array($type, ['textarea', 'widget'])) { | ||
| // defaults to 'large' | ||
| $this->size = 'large'; | ||
| } | ||
|
|
||
| $this->type = strtolower($type) ?: $this->type; | ||
| $this->config = $this->evalConfig($config); | ||
|
|
||
|
|
@@ -281,18 +286,18 @@ protected function evalConfig($config) | |
| */ | ||
| $applyConfigValues = [ | ||
| 'commentHtml', | ||
| 'placeholder', | ||
| 'context', | ||
| 'cssClass', | ||
| 'dependsOn', | ||
| 'required', | ||
| 'readOnly', | ||
| 'disabled', | ||
| 'cssClass', | ||
| 'stretch', | ||
| 'context', | ||
| 'hidden', | ||
| 'trigger', | ||
| 'preset', | ||
| 'path', | ||
| 'placeholder', | ||
| 'preset', | ||
| 'readOnly', | ||
| 'required', | ||
| 'stretch', | ||
| 'trigger', | ||
| ]; | ||
|
|
||
| foreach ($applyConfigValues as $value) { | ||
|
|
@@ -729,4 +734,31 @@ protected function getFieldNameFromData($fieldName, $data, $default = null) | |
|
|
||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Implements the getter functionality. | ||
| * @param string $name | ||
| */ | ||
| public function __get($name) | ||
| { | ||
| if (array_key_exists($name, $this->config)) { | ||
| return array_get($this->config, $name); | ||
| } | ||
| if (property_exists($this, $name)) { | ||
| return $this->{$name}; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Determine if an attribute exists on the object. | ||
| * @param string $name | ||
| */ | ||
| public function __isset($name) | ||
| { | ||
| if (array_key_exists($name, $this->config)) { | ||
| return true; | ||
| } | ||
| return property_exists($this, $name) && !is_null($this->{$name}); | ||
| } | ||
|
Comment on lines
+757
to
+763
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same null-safety issue in This method has the same 🐛 Proposed fix public function __isset($name)
{
- if (array_key_exists($name, $this->config)) {
+ if (is_array($this->config) && array_key_exists($name, $this->config)) {
return true;
}
return property_exists($this, $name) && !is_null($this->{$name});
}🤖 Prompt for AI Agents |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
TypeError when
$this->configis null.array_key_exists()throws aTypeErrorin PHP 8+ if the second argument isnull. Since$configis not initialized in the constructor and only set whendisplayAs()is called, accessing dynamic properties on a field that hasn't been fully configured will crash.🐛 Proposed fix
public function __get($name) { - if (array_key_exists($name, $this->config)) { + if (is_array($this->config) && array_key_exists($name, $this->config)) { return array_get($this->config, $name); } if (property_exists($this, $name)) { return $this->{$name}; } return null; }🤖 Prompt for AI Agents