Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6496328af | ||
|
|
137a2efcf1 | ||
|
|
32c27a54cd | ||
|
|
f9deb1da6f | ||
|
|
5feb06537d | ||
|
|
e1318fcfdd | ||
|
|
cecb65626c | ||
|
|
a5f7464ee6 | ||
|
|
cd71ed1538 | ||
|
|
2dfc110b6c | ||
|
|
8997f1209d | ||
|
|
b4c0a3e26d | ||
|
|
1810274c8a | ||
|
|
f380cdc14d | ||
|
|
0ac9642ebb | ||
|
|
b9322c703d |
No files matched your search
@@ -1,7 +1,6 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
sudo: false
|
||||
|
||||
+8
-8
@@ -18,15 +18,15 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"illuminate/http": "5.5.*",
|
||||
"illuminate/routing": "5.5.*",
|
||||
"illuminate/session": "5.5.*",
|
||||
"illuminate/support": "5.5.*",
|
||||
"illuminate/view": "5.5.*"
|
||||
"php": ">=7.1.3",
|
||||
"illuminate/http": "5.6.*",
|
||||
"illuminate/routing": "5.6.*",
|
||||
"illuminate/session": "5.6.*",
|
||||
"illuminate/support": "5.6.*",
|
||||
"illuminate/view": "5.6.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/database": "5.5.*",
|
||||
"illuminate/database": "5.6.*",
|
||||
"mockery/mockery": "~0.9.4",
|
||||
"phpunit/phpunit": "~5.4"
|
||||
},
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.5-dev"
|
||||
"dev-master": "5.6-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
|
||||
@@ -49,11 +49,11 @@ trait FormAccessible
|
||||
unset($keys[0]);
|
||||
$key = implode('.', $keys);
|
||||
|
||||
if ($this->hasFormMutator($key)) {
|
||||
if (method_exists($relatedModel, 'hasFormMutator') && $key !== '' && $relatedModel->hasFormMutator($key)) {
|
||||
return $relatedModel->getFormValue($key);
|
||||
}
|
||||
|
||||
return data_get($relatedModel, $key);
|
||||
return data_get($relatedModel, empty($key)? null: $key);
|
||||
}
|
||||
|
||||
// No form mutator, let the model resolve this
|
||||
@@ -81,7 +81,7 @@ trait FormAccessible
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasFormMutator($key)
|
||||
public function hasFormMutator($key)
|
||||
{
|
||||
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
|
||||
+15
-14
@@ -527,7 +527,7 @@ class FormBuilder
|
||||
// the element. Then we'll create the final textarea elements HTML for us.
|
||||
$options = $this->html->attributes($options);
|
||||
|
||||
return $this->toHtmlString('<textarea' . $options . '>' . e($value). '</textarea>');
|
||||
return $this->toHtmlString('<textarea' . $options . '>' . e($value, false). '</textarea>');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -572,7 +572,7 @@ class FormBuilder
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $list
|
||||
* @param string|bool $selected
|
||||
* @param string $selected
|
||||
* @param array $selectAttributes
|
||||
* @param array $optionsAttributes
|
||||
* @param array $optgroupsAttributes
|
||||
@@ -709,20 +709,23 @@ class FormBuilder
|
||||
* @param string $selected
|
||||
* @param array $attributes
|
||||
* @param array $optionsAttributes
|
||||
* @param integer $level
|
||||
*
|
||||
* @return \Illuminate\Support\HtmlString
|
||||
*/
|
||||
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [])
|
||||
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0)
|
||||
{
|
||||
$html = [];
|
||||
|
||||
$space = str_repeat(" ", $level);
|
||||
foreach ($list as $value => $display) {
|
||||
$optionAttributes = $optionsAttributes[$value] ?? [];
|
||||
|
||||
$html[] = $this->option($display, $value, $selected, $optionAttributes);
|
||||
if (is_array($display)) {
|
||||
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5);
|
||||
} else {
|
||||
$html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->toHtmlString('<optgroup label="' . e($label) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
|
||||
return $this->toHtmlString('<optgroup label="' . e($space.$label, false) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -743,7 +746,7 @@ class FormBuilder
|
||||
|
||||
$string = '<option' . $this->html->attributes($options) . '>';
|
||||
if ($display !== null) {
|
||||
$string .= e($display) . '</option>';
|
||||
$string .= e($display, false) . '</option>';
|
||||
}
|
||||
|
||||
return $this->toHtmlString($string);
|
||||
@@ -766,7 +769,7 @@ class FormBuilder
|
||||
'value' => '',
|
||||
];
|
||||
|
||||
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>');
|
||||
return $this->toHtmlString('<option' . $this->html->attributes($options) . ' hidden="hidden">' . e($display, false) . '</option>');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -784,9 +787,7 @@ class FormBuilder
|
||||
} elseif ($selected instanceof Collection) {
|
||||
return $selected->contains($value) ? 'selected' : null;
|
||||
}
|
||||
if (is_int($value) && is_bool($selected)) {
|
||||
return (bool)$value === $selected;
|
||||
}
|
||||
|
||||
return ((string) $value === (string) $selected) ? 'selected' : null;
|
||||
}
|
||||
|
||||
@@ -1183,7 +1184,7 @@ class FormBuilder
|
||||
}
|
||||
|
||||
$request = $this->request($name);
|
||||
if (! is_null($request) && $name !== '_method') {
|
||||
if (! is_null($request)) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -387,7 +387,7 @@ class HtmlBuilder
|
||||
if (is_array($value)) {
|
||||
return $this->nestedListing($key, $type, $value);
|
||||
} else {
|
||||
return '<li>' . e($value) . '</li>';
|
||||
return '<li>' . e($value, false) . '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ class HtmlBuilder
|
||||
}
|
||||
|
||||
if (! is_null($value)) {
|
||||
return $key . '="' . e($value) . '"';
|
||||
return $key . '="' . e($value, false) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,16 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
|
||||
public function testItCanMutateValuesForForms()
|
||||
{
|
||||
$model = new ModelThatUsesForms($this->modelData);
|
||||
$user = new User(['name' => 'Anton']);
|
||||
$model->setRelation('user', $user);
|
||||
$this->formBuilder->setModel($model);
|
||||
|
||||
$this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba');
|
||||
$this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp);
|
||||
|
||||
$this->assertEquals($user, $model->getFormValue('user'));
|
||||
$this->assertEquals('Get name: Anton', $model->getFormValue('user')->name);
|
||||
$this->assertEquals('Get name for form: Anton', $model->getFormValue('user.name'));
|
||||
}
|
||||
|
||||
public function testItCanMutateRelatedValuesForForms()
|
||||
@@ -159,3 +165,18 @@ class ModelThatDoesntUseForms extends Model
|
||||
return '1 second ago';
|
||||
}
|
||||
}
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
use FormAccessible;
|
||||
|
||||
public function formNameAttribute($value)
|
||||
{
|
||||
return 'Get name for form: ' . $value;
|
||||
}
|
||||
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
return 'Get name: ' . $value;
|
||||
}
|
||||
}
|
||||
@@ -464,12 +464,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
|
||||
'<select name="countries"><option value="1" selected="selected">L</option><option value="2">M</option></select>',
|
||||
$result
|
||||
);
|
||||
|
||||
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
|
||||
$this->assertEquals(
|
||||
'<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
|
||||
$select
|
||||
);
|
||||
}
|
||||
|
||||
public function testSelectCollection()
|
||||
@@ -516,7 +510,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
|
||||
['placeholder' => 'Select One...']
|
||||
);
|
||||
$this->assertEquals($select,
|
||||
'<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
|
||||
'<select name="size"><option selected="selected" value="" hidden="hidden">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
|
||||
|
||||
$select = $this->formBuilder->select(
|
||||
'size',
|
||||
@@ -525,7 +519,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
|
||||
['placeholder' => 'Select One...']
|
||||
);
|
||||
$this->assertEquals($select,
|
||||
'<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||
'<select name="size"><option value="" hidden="hidden">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||
|
||||
$select = $this->formBuilder->select(
|
||||
'encoded_html',
|
||||
@@ -534,7 +528,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
|
||||
['placeholder' => 'Select the ']
|
||||
);
|
||||
$this->assertEquals($select,
|
||||
'<select name="encoded_html"><option selected="selected" value="">Select the </option><option value="no_break_space"> </option><option value="ampersand">&</option><option value="lower_than"><</option></select>'
|
||||
'<select name="encoded_html"><option selected="selected" value="" hidden="hidden">Select the </option><option value="no_break_space"> </option><option value="ampersand">&</option><option value="lower_than"><</option></select>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user