Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Fixing the HtmlString labels in latest versions of PHP #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"illuminate/config": "~8.0|^9.0",
"illuminate/session": "~8.0|^9.0",
"illuminate/support": "~8.0|^9.0",
Expand Down
46 changes: 23 additions & 23 deletions src/BootstrapForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function horizontal(array $options = []): string
/**
* Create a Bootstrap static field.
*/
public function staticField(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function staticField(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
$options = array_merge(['class' => 'form-control-static'], $options);

Expand All @@ -218,79 +218,79 @@ public function staticField(string $name, ?string $label = null, ?string $value
/**
* Create a Bootstrap text field input.
*/
public function text(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function text(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('text', $name, $label, $value, $options);
}

/**
* Create a Bootstrap email field input.
*/
public function email(string $name = 'email', ?string $label = null, ?string $value = null, array $options = []): string
public function email(string $name = 'email', null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('email', $name, $label, $value, $options);
}

/**
* Create a Bootstrap URL field input.
*/
public function url(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function url(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('url', $name, $label, $value, $options);
}

/**
* Create a Bootstrap tel field input.
*/
public function tel(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function tel(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('tel', $name, $label, $value, $options);
}

/**
* Create a Bootstrap number field input.
*/
public function number(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function number(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('number', $name, $label, $value, $options);
}

/**
* Create a Bootstrap date field input.
*/
public function date(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function date(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('date', $name, $label, $value, $options);
}

/**
* Create a Bootstrap time field input.
*/
public function time(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function time(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('time', $name, $label, $value, $options);
}

/**
* Create a Bootstrap textarea field input.
*/
public function textarea(string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function textarea(string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
return $this->input('textarea', $name, $label, $value, $options);
}

/**
* Create a Bootstrap password field input.
*/
public function password(string $name = 'password', ?string $label = null, array $options = []): string
public function password(string $name = 'password', null|string|HtmlString $label = null, array $options = []): string
{
return $this->input('password', $name, $label, null, $options);
}

/**
* Create a Bootstrap checkbox input.
*/
public function checkbox(string $name, ?string $label = null, string $value = '1', ?bool $checked = null, array $options = []): string
public function checkbox(string $name, null|string|HtmlString $label = null, string $value = '1', ?bool $checked = null, array $options = []): string
{
$inputElement = $this->checkboxElement($name, $label, $value, $checked, false, $options);

Expand All @@ -303,7 +303,7 @@ public function checkbox(string $name, ?string $label = null, string $value = '1
/**
* Create a single Bootstrap checkbox element.
*/
public function checkboxElement(string $name, ?string $label = null, string $value = '1', ?bool $checked = null, bool $inline = false, array $options = []): string
public function checkboxElement(string $name, null|string|HtmlString $label = null, string $value = '1', ?bool $checked = null, bool $inline = false, array $options = []): string
{
$label = $label === false ? null : $this->getLabelTitle($label, $name);

Expand All @@ -317,7 +317,7 @@ public function checkboxElement(string $name, ?string $label = null, string $val
/**
* Create a collection of Bootstrap checkboxes.
*/
public function checkboxes(string $name, ?string $label = null, array $choices = [], array $checkedValues = [], bool $inline = false, array $options = []): string
public function checkboxes(string $name, null|string|HtmlString $label = null, array $choices = [], array $checkedValues = [], bool $inline = false, array $options = []): string
{
$elements = '';

Expand All @@ -336,7 +336,7 @@ public function checkboxes(string $name, ?string $label = null, array $choices =
/**
* Create a Bootstrap radio input.
*/
public function radio(string $name, ?string $label = null, ?string $value = null, ?bool $checked = null, array $options = []): string
public function radio(string $name, null|string|HtmlString $label = null, ?string $value = null, ?bool $checked = null, array $options = []): string
{
$inputElement = $this->radioElement($name, $label, $value, $checked, false, $options);

Expand All @@ -349,7 +349,7 @@ public function radio(string $name, ?string $label = null, ?string $value = null
/**
* Create a single Bootstrap radio input.
*/
public function radioElement(string $name, ?string $label = null, ?string $value = null, ?bool $checked = null, bool $inline = false, array $options = []): string
public function radioElement(string $name, null|string|HtmlString $label = null, ?string $value = null, ?bool $checked = null, bool $inline = false, array $options = []): string
{
$label = $label === false ? null : $this->getLabelTitle($label, $name);

Expand All @@ -366,7 +366,7 @@ public function radioElement(string $name, ?string $label = null, ?string $value
/**
* Create a collection of Bootstrap radio inputs.
*/
public function radios(string $name, ?string $label = null, array $choices = [], ?string $checkedValue = null, bool $inline = false, array $options = []): string
public function radios(string $name, null|string|HtmlString $label = null, array $choices = [], ?string $checkedValue = null, bool $inline = false, array $options = []): string
{
$elements = '';

Expand All @@ -385,7 +385,7 @@ public function radios(string $name, ?string $label = null, array $choices = []
/**
* Create a Bootstrap label.
*/
public function label(string $name, ?string $value = null, array $options = []): string
public function label(string $name, null|HtmlString|string $value = null, array $options = []): string
{
$options = $this->getLabelOptions($options);

Expand Down Expand Up @@ -435,7 +435,7 @@ public function button(?string $value = null, array $options = []): string
/**
* Create a Boostrap file upload button.
*/
public function file(string $name, ?string $label = null, array $options = []): string
public function file(string $name, null|string|HtmlString $label = null, array $options = []): string
{
$label = $this->getLabelTitle($label, $name);

Expand All @@ -453,7 +453,7 @@ public function file(string $name, ?string $label = null, array $options = []):
/**
* Create the input group for an element with the correct classes for errors.
*/
public function input(string $type, string $name, ?string $label = null, ?string $value = null, array $options = []): string
public function input(string $type, string $name, null|string|HtmlString $label = null, ?string $value = null, array $options = []): string
{
$label = $this->getLabelTitle($label, $name);

Expand Down Expand Up @@ -524,7 +524,7 @@ public function hidden(string $name, ?string $value = null, array $options = [])
/**
* Create a select box field.
*/
public function select(string $name, ?string $label = null, array $list = [], ?string $selected = null, array $options = []): string
public function select(string $name, null|string|HtmlString $label = null, array $list = [], ?string $selected = null, array $options = []): string
{
$label = $this->getLabelTitle($label, $name);

Expand Down Expand Up @@ -593,7 +593,7 @@ protected function getFormGroupWithoutLabel(?string $name, ?string $element): Ht
/**
* Get a form group comprised of a label, form element and errors.
*/
protected function getFormGroupWithLabel(?string $name, ?string $value, ?string $element): HtmlString
protected function getFormGroupWithLabel(?string $name, null|HtmlString|string $value, ?string $element): HtmlString
{
$options = $this->getFormGroupOptions($name);

Expand All @@ -603,9 +603,9 @@ protected function getFormGroupWithLabel(?string $name, ?string $value, ?string
/**
* Get a form group with or without a label.
*/
public function getFormGroup(?string $name = null, ?string $label = null, ?string $wrapper = null): string
public function getFormGroup(?string $name = null, null|string|HtmlString $label = null, ?string $wrapper = null): string
{
if (is_null($label)) {
if (!$label) {
return $this->getFormGroupWithoutLabel($name, $wrapper);
}

Expand Down