Skip to content

Commit 0a628c0

Browse files
committed
Merge remote-tracking branch 'collective/6.x' into 7.x
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> # Conflicts: # .gitattributes # src/FormBuilder.php # src/HtmlBuilder.php # src/helpers.php # tests/FormBuilderTest.php
2 parents baefa98 + 7ec9bb0 commit 0a628c0

File tree

3 files changed

+77
-18
lines changed

3 files changed

+77
-18
lines changed

src/Concerns/Creator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ protected function getUrlAction($options): string
196196
protected function getRouteAction($options): string
197197
{
198198
if (\is_array($options)) {
199-
return $this->url->route($options[0], \array_slice($options, 1));
199+
$parameters = array_slice($options, 1);
200+
201+
if (array_keys($options) === [0, 1]) {
202+
$parameters = head($parameters);
203+
}
204+
205+
return $this->url->route($options[0], $parameters);
200206
}
201207

202208
return $this->url->route($options);

src/HtmlBuilder.php

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,13 @@ public function favicon(string $url, array $attributes = [], ?bool $secure = nul
159159
*
160160
* @return \Illuminate\Contracts\Support\Htmlable
161161
*/
162-
public function link(string $url, ?string $title = null, array $attributes = [], ?bool $secure = null, bool $escape = true): Htmlable
163-
{
162+
public function link(
163+
string $url,
164+
?string $title = null,
165+
array $attributes = [],
166+
?bool $secure = null,
167+
bool $escape = true
168+
): Htmlable {
164169
$url = $this->url->to($url, [], $secure);
165170

166171
if (\is_null($title) || $title === false) {
@@ -180,12 +185,17 @@ public function link(string $url, ?string $title = null, array $attributes = [],
180185
* @param string $url
181186
* @param string|null $title
182187
* @param array $attributes
188+
* @param bool $escape
183189
*
184190
* @return \Illuminate\Contracts\Support\Htmlable
185191
*/
186-
public function secureLink(string $url, ?string $title = null, array $attributes = []): Htmlable
187-
{
188-
return $this->link($url, $title, $attributes, true);
192+
public function secureLink(
193+
string $url,
194+
?string $title = null,
195+
array $attributes = [],
196+
bool $escape = true
197+
): Htmlable {
198+
return $this->link($url, $title, $attributes, true, $escape);
189199
}
190200

191201
/**
@@ -195,14 +205,20 @@ public function secureLink(string $url, ?string $title = null, array $attributes
195205
* @param string|null $title
196206
* @param array $attributes
197207
* @param bool|null $secure
208+
* @param bool $escape
198209
*
199210
* @return \Illuminate\Contracts\Support\Htmlable
200211
*/
201-
public function linkAsset(string $url, ?string $title = null, array $attributes = [], ?bool $secure = null): Htmlable
202-
{
212+
public function linkAsset(
213+
string $url,
214+
?string $title = null,
215+
array $attributes = [],
216+
?bool $secure = null,
217+
bool $escape = true
218+
): Htmlable {
203219
$url = $this->url->asset($url, $secure);
204220

205-
return $this->link($url, $title ?: $url, $attributes, $secure);
221+
return $this->link($url, $title ?: $url, $attributes, $secure, $escape);
206222
}
207223

208224
/**
@@ -211,12 +227,17 @@ public function linkAsset(string $url, ?string $title = null, array $attributes
211227
* @param string $url
212228
* @param string|null $title
213229
* @param array $attributes
230+
* @param bool $escape
214231
*
215232
* @return \Illuminate\Contracts\Support\Htmlable
216233
*/
217-
public function linkSecureAsset(string $url, ?string $title = null, array $attributes = []): Htmlable
218-
{
219-
return $this->linkAsset($url, $title, $attributes, true);
234+
public function linkSecureAsset(
235+
string $url,
236+
?string $title = null,
237+
array $attributes = [],
238+
bool $escape = true
239+
): Htmlable {
240+
return $this->linkAsset($url, $title, $attributes, true, $escape);
220241
}
221242

222243
/**
@@ -226,12 +247,18 @@ public function linkSecureAsset(string $url, ?string $title = null, array $attri
226247
* @param string|null $title
227248
* @param array $parameters
228249
* @param array $attributes
250+
* @param bool $escape
229251
*
230252
* @return \Illuminate\Contracts\Support\Htmlable
231253
*/
232-
public function linkRoute(string $name, ?string $title = null, array $parameters = [], array $attributes = []): Htmlable
233-
{
234-
return $this->link($this->url->route($name, $parameters), $title, $attributes);
254+
public function linkRoute(
255+
string $name,
256+
?string $title = null,
257+
array $parameters = [],
258+
array $attributes = [],
259+
bool $escape = true
260+
): Htmlable {
261+
return $this->link($this->url->route($name, $parameters), $title, $attributes, $secure, $escape);
235262
}
236263

237264
/**
@@ -241,12 +268,18 @@ public function linkRoute(string $name, ?string $title = null, array $parameters
241268
* @param string|null $title
242269
* @param array $parameters
243270
* @param array $attributes
271+
* @param bool $escape
244272
*
245273
* @return \Illuminate\Contracts\Support\Htmlable
246274
*/
247-
public function linkAction(string $action, ?string $title = null, array $parameters = [], array $attributes = []): Htmlable
248-
{
249-
return $this->link($this->url->action($action, $parameters), $title, $attributes);
275+
public function linkAction(
276+
string $action,
277+
?string $title = null,
278+
array $parameters = [],
279+
array $attributes = [],
280+
bool $escape = true
281+
): Htmlable {
282+
return $this->link($this->url->action($action, $parameters), $title, $attributes, $secure, $escape);
250283
}
251284

252285
/**

tests/FormBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Support\Collection;
1010
use Illuminate\Routing\UrlGenerator;
1111
use Illuminate\Contracts\View\Factory;
12+
use Illuminate\Http\Request;
13+
use Illuminate\Routing\Route;
1214
use Illuminate\Routing\RouteCollection;
1315

1416
class FormBuilderTest extends TestCase
@@ -130,6 +132,24 @@ public function testRequestValue()
130132
$this->assertEquals('<input name="person[surname]" type="text" value="Not Doe">', $surname);
131133
}
132134

135+
public function testFormRoute()
136+
{
137+
$routes = new RouteCollection();
138+
$routes->get('user/{id}');
139+
$routes->add(new Route(['GET'], 'user/{id}', ['as' => 'user.show']));
140+
$this->urlGenerator->setRoutes($routes);
141+
142+
$form1 = $this->formBuilder->open(['method' => 'GET', 'route' => ['user.show', 1, 'foo' => 'bar']]);
143+
$form2 = $this->formBuilder->open(['method' => 'GET', 'route' => ['user.show', 'id' => 2, 'foo' => 'bar']]);
144+
$form3 = $this->formBuilder->open(['method' => 'GET', 'route' => ['user.show', [3, 'foo' => 'bar']]]);
145+
$form4 = $this->formBuilder->open(['method' => 'GET', 'route' => ['user.show', ['id' => 4, 'foo' => 'bar']]]);
146+
147+
$this->assertEquals('<form method="GET" action="http://localhost/user/1?foo=bar" accept-charset="UTF-8">', $form1);
148+
$this->assertEquals('<form method="GET" action="http://localhost/user/2?foo=bar" accept-charset="UTF-8">', $form2);
149+
$this->assertEquals('<form method="GET" action="http://localhost/user/3?foo=bar" accept-charset="UTF-8">', $form3);
150+
$this->assertEquals('<form method="GET" action="http://localhost/user/4?foo=bar" accept-charset="UTF-8">', $form4);
151+
}
152+
133153
public function testClosingForm()
134154
{
135155
$this->assertEquals('</form>', $this->formBuilder->close());

0 commit comments

Comments
 (0)