Compare commits

...
17 Commits
Author SHA1 Message Date
Tortue Torche 818efc2e16 [5.6] Form method of hidden input '_method' is preserved on next request (#486)
* Form method of hidden input '_method' is preserved on next request

E.G. When you submitted data across a form with a 'PATCH' method and then in a second submit you use a form with a 'DELETE' method, the FormBuilder::getValueAttribute() method use the previous value of the hidden input '_method'.
So the value is replaced by 'PATCH' instead of the 'DELETE' value.

* Drop PHP 7.1 and add PHP 7.2 in Travis CI config

Because Laravel 5.6 require at least PHP 7.1.3

* Fix PHP 7.2 Warning with count()

Otherwise a PHP Warning is thrown:
count(): Parameter must be an array or an object that implements Countable

See http://php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types

* Bump Mockery version to support PHP 7.2
2018-02-08 10:38:44 -08:00
Max Mitschke e6496328af Added Laravel 5.6 stable support (#484)
* Laravel 5.6 stable support

* fixed bug where opt group attributes where passed to option, added opt group attributes to opt group

* dropped php 7.0 because Laravel minimum requirement is now php 7.1.3
2018-02-08 08:16:30 -08:00
Vendin 137a2efcf1 Getting relation data for model accessor (#474) 2018-02-05 08:22:47 -07:00
Tom Shafer 32c27a54cd Merge branch 'master' of github.com:LaravelCollective/html 2018-02-05 08:09:36 -07:00
Tom Shafer f9deb1da6f Merge branch '5.5' of github.com:LaravelCollective/html 2018-02-05 08:09:29 -07:00
ThunderbirdsX3 5feb06537d Fix placeholder not hide in select list. (#473)
* Update test.

* Fix place holder show in select list.
2018-02-05 07:59:23 -07:00
Vendin e1318fcfdd Getting data for a form from a relation (#472) 2018-02-05 07:58:09 -07:00
Lluís Bayer Soler cecb65626c Nested optgroups (#470)
* fix optionGroup and added a function to handle recursively the arrays

* simplify recursively

* fix codestyle

* fix codestyle

* add new parameter annotation
2018-02-05 07:04:30 -07:00
Tom Shafer a5f7464ee6 Merge pull request #469 from crishoj/5.5
Proposal: Escape HTML entities in `src`-attribute
2018-02-05 06:41:39 -07:00
Tom Shafer cd71ed1538 Merge branch '5.5'
# Conflicts:
#	src/FormBuilder.php
2018-02-04 15:06:18 -07:00
Tom Shafer 2dfc110b6c Merge pull request #416 from djh101/master
Added $optgroupsAttributes parameter to select method.
2018-02-04 14:59:15 -07:00
Tom Shafer 8997f1209d Merge branch '5.5' 2018-02-04 14:46:24 -07:00
Drew b4c0a3e26d Style fixes. Replaced == with ===. 2017-09-18 16:28:31 -07:00
Christian Rishøj 1810274c8a escape HTML entities in src-attribute 2017-09-14 11:42:34 +07:00
Drew f380cdc14d Added $optgroupsAttributes parameter to select method. 2017-09-08 21:20:14 -07:00
Matt Lantz 0ac9642ebb Merge branch '5.5' 2017-08-31 10:47:12 -04:00
Matt Lantz b9322c703d 5.6 Prep 2017-08-31 10:38:54 -04:00
7 changed files with 52 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -1,8 +1,8 @@
language: php
php:
- 7.0
- 7.1
- 7.2
sudo: false
+8 -8
View File
@@ -18,16 +18,16 @@
}
],
"require": {
"php": ">=7.0.0",
"illuminate/http": "5.6.x-dev",
"illuminate/routing": "5.6.x-dev",
"illuminate/session": "5.6.x-dev",
"illuminate/support": "5.6.x-dev",
"illuminate/view": "5.6.x-dev"
"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.6.x-dev",
"mockery/mockery": "~0.9.4",
"illuminate/database": "5.6.*",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~5.4"
},
"autoload": {
+3 -3
View File
@@ -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);
+14 -11
View File
@@ -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>');
}
/**
@@ -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("&nbsp;", $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>');
}
/**
@@ -1181,7 +1184,7 @@ class FormBuilder
}
$request = $this->request($name);
if (! is_null($request)) {
if (! is_null($request) && $name != '_method') {
return $request;
}
@@ -1265,7 +1268,7 @@ class FormBuilder
*/
public function oldInputIsEmpty()
{
return (isset($this->session) && count($this->session->getOldInput()) === 0);
return (isset($this->session) && count((array) $this->session->getOldInput()) === 0);
}
/**
+2 -2
View File
@@ -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) . '"';
}
}
+21
View File
@@ -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;
}
}
+3 -3
View File
@@ -510,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',
@@ -519,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',
@@ -528,7 +528,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select the &nbsp;']
);
$this->assertEquals($select,
'<select name="encoded_html"><option selected="selected" value="">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
'<select name="encoded_html"><option selected="selected" value="" hidden="hidden">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
);
}