Skip to content

Commit f1c24c0

Browse files
Terzi Eduardendihunter
authored andcommitted
Add custom attributes to filters
1 parent b8b9462 commit f1c24c0

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

publishes/views/fields/image/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
'height' => 60,
77
];
88
?>
9-
{!! \admin\output\staplerImage($attachment, 'original', $attributes) !!}
9+
{!! \admin\output\staplerImage($attachment, 'original', $attributes) !!}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ('datalist' === $field->type)
2-
{!! Form::text($field->name(), $field->value(), ['id' => $field->id(), 'class' => 'form-control', 'list' => "scaffold_{$field->id()}"]) !!}
2+
{!! Form::text($field->name(), $field->value(), ['id' => $field->id(), 'list' => "scaffold_{$field->id()}"] + $attributes) !!}
33
{!! Form::datalist("scaffold_{$field->id()}", $field->options) !!}
44
@else
5-
{{ Form::select($field->name(), ($field->isArray ? [] : ['' => "—"]) + ($field->options ?? []), $field->value(), ['class' => 'form-control', 'multiple' => $field->isArray] + $attributes) }}
5+
{{ Form::select($field->name(), ($field->isArray ? [] : ['' => "—"]) + ($field->options ?? []), $field->value(), ['multiple' => $field->isArray] + $attributes) }}
66
@endif
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ Form::number($field->name(), $field->value(), ['class' => 'form-control'] + $attributes) }}
1+
{{ Form::number($field->name(), $field->value(), $attributes) }}

publishes/views/filters/text.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<div class="input-group-addon" style="padding: 0 8px;">
55
{!! Form::select($modeName, $modes, request($modeName)) !!}
66
</div>
7-
{{ Form::text($field->name(), $field->value(), ['class' => 'form-control']) }}
7+
{{ Form::text($field->name(), $field->value(), $attributes) }}
88
</div>
99
@else
10-
{{ Form::text($field->name(), $field->value(), ['class' => 'form-control']) }}
10+
{{ Form::text($field->name(), $field->value(), $attributes) }}
1111
@endif

src/Field/Field.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,6 @@ final public function render(string $page = 'index')
243243
return View::make($this->template($page, 'Key'), $data);
244244
}
245245

246-
/**
247-
* @return array
248-
*/
249-
public function getAttributes(): array
250-
{
251-
return $this->attributes;
252-
}
253-
254246
/**
255247
* @param string $page
256248
* @param string|null $field

src/Filter/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function render()
107107
{
108108
return View::make($this->template(), [
109109
'field' => $this,
110-
'attributes' => $this->attributes,
110+
'attributes' => $this->getAttributes(),
111111
] + $this->renderWith());
112112
}
113113

src/Traits/Form/HasHtmlAttributes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public function setAttributes(array $attributes)
1717
return $this;
1818
}
1919

20+
/**
21+
* @return array
22+
*/
23+
public function getAttributes(): array
24+
{
25+
return $this->attributes;
26+
}
27+
2028
/**
2129
* @param float $min
2230
* @return static

src/helpers.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/**
77
* Build a new array using a callback (Original method was deprecetad since version 5.2).
88
*
9-
* @param array $array
10-
* @param callable $callback
9+
* @param array $array
10+
* @param callable $callback
1111
* @return array
1212
*/
1313
function array_build($array, callable $callback)
@@ -101,7 +101,7 @@ function table_indexes(Model $model, $withTranslated = true)
101101
/**
102102
* Check if we are on desired connection or get the current connection name.
103103
*
104-
* @param string $name
104+
* @param string $name
105105
* @return mixed string|boolean
106106
*/
107107
function connection($name = null)
@@ -138,7 +138,7 @@ function enum_values($table, $column)
138138
/**
139139
* @param $values
140140
* @param $column
141-
* @param mixed $namespace
141+
* @param mixed $namespace
142142
* @return array
143143
*/
144144
function translated_values($values, $namespace, $column)
@@ -169,9 +169,9 @@ function translated_values($values, $namespace, $column)
169169
/**
170170
* Fetch key => value pairs from an Eloquent model.
171171
*
172-
* @param mixed $model
173-
* @param string $labelAttribute
174-
* @param string $keyAttribute
172+
* @param mixed $model
173+
* @param string $labelAttribute
174+
* @param string $keyAttribute
175175
* @return array
176176
*/
177177
function html_list($model, $labelAttribute = 'name', $keyAttribute = 'id')
@@ -189,7 +189,7 @@ function html_list($model, $labelAttribute = 'name', $keyAttribute = 'id')
189189
* Generate route with query string.
190190
*
191191
* @param $route
192-
* @param array $params
192+
* @param array $params
193193
* @return string
194194
*/
195195
function qsRoute($route = null, array $params = [])
@@ -293,7 +293,7 @@ function auto_p($value, $lineBreaks = true)
293293
* Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
294294
* converted into paragraphs or line-breaks.
295295
*
296-
* @param array|string $matches The array or string
296+
* @param array|string $matches The array or string
297297
* @return string the pre block without paragraph/line-break conversion
298298
*/
299299
function clean_pre($matches)
@@ -314,7 +314,7 @@ function clean_pre($matches)
314314
/**
315315
* Newline preservation help function for wpautop.
316316
*
317-
* @param array $matches preg_replace_callback matches array
317+
* @param array $matches preg_replace_callback matches array
318318
* @returns string
319319
* @return mixed
320320
* @since 3.1.0
@@ -350,9 +350,9 @@ function boolean($value)
350350
}
351351

352352
/**
353-
* @param string $name
353+
* @param string $name
354354
* @param $value
355-
* @param string $key
355+
* @param string $key
356356
* @return string
357357
*/
358358
function rank(string $name, $value, string $key)
@@ -361,23 +361,23 @@ function rank(string $name, $value, string $key)
361361
}
362362

363363
/**
364-
* @param string $image
365-
* @param array $attributes
364+
* @param string $image
365+
* @param array $attributes
366366
* @return string
367367
*/
368368
function image(string $image, array $attributes = [])
369369
{
370370
$attributes = \admin\helpers\html_attributes($attributes);
371371

372-
return $image ? '<img src="'.$image.'" '.$attributes.' />' : '';
372+
return $image ? '<img src="'.($image ?? asset('images/no-image.png')).'" '.$attributes.' />' : '';
373373
}
374374

375375
/**
376376
* Output image from Paperclip attachment object.
377377
*
378-
* @param null|Attachment $attachment
379-
* @param null|string $style
380-
* @param array $attributes
378+
* @param null|Attachment $attachment
379+
* @param null|string $style
380+
* @param array $attributes
381381
* @return null|string
382382
*/
383383
function staplerImage(Attachment $attachment = null, string $style = null, $attributes = [])
@@ -432,8 +432,8 @@ function staplerImage(Attachment $attachment = null, string $style = null, $attr
432432
}
433433

434434
/**
435-
* @param array $items
436-
* @param null|Closure $callback
435+
* @param array $items
436+
* @param null|Closure $callback
437437
* @return array|string
438438
*/
439439
function _prepare_collection(array $items, Closure $callback = null)
@@ -454,8 +454,8 @@ function _prepare_collection(array $items, Closure $callback = null)
454454
}
455455

456456
/**
457-
* @param string $label
458-
* @param string $class
457+
* @param string $label
458+
* @param string $class
459459
* @return string
460460
*/
461461
function label(string $label = '', string $class = 'label-success')
@@ -464,8 +464,8 @@ function label(string $label = '', string $class = 'label-success')
464464
}
465465

466466
/**
467-
* @param string $label
468-
* @param string $class
467+
* @param string $label
468+
* @param string $class
469469
* @return string
470470
*/
471471
function badge(string $label = '', string $class = 'bg-green')

0 commit comments

Comments
 (0)