Skip to content

Commit fba2806

Browse files
committedOct 25, 2024··
add disabled() method to Inputs
1 parent 38e4162 commit fba2806

8 files changed

+23
-8
lines changed
 

‎src/ApiOptions/Input.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ abstract class Input
88
protected static ?string $globalWrapperClass = null;
99
protected static ?string $globalLabelClass = null;
1010
protected static ?string $globalInputClass = null;
11-
protected string $id = '';
11+
protected string $id = '';
1212
protected ?string $wrapper = null;
1313
protected ?string $wrapperClass = null;
1414
protected ?string $inputClass = null;
1515
protected ?string $labelClass = null;
1616
protected array $data = [];
17+
protected bool $disabled = false;
1718

1819
/**
1920
* Sets a global wrapper element for all input elements created by this class.
@@ -161,6 +162,12 @@ public function data(array $data): Input
161162
return $this;
162163
}
163164

165+
public function disabled(): Input
166+
{
167+
$this->disabled = true;
168+
return $this;
169+
}
170+
164171
/**
165172
* Converts the data array into a string of data-* attributes.
166173
*

‎src/ApiOptions/Input/AcceptHeader.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public function get(): string
109109
? self::$globalWrapper
110110
: null);
111111

112+
$disabled = $this->disabled ? ' disabled' : '';
113+
112114
$returnTypeParamContents = <<<OPTIONS
113115
<option value="JSON">JSON</option>
114116
<option value="XML">XML</option>
@@ -125,7 +127,7 @@ public function get(): string
125127
$labelText = $this->as_return_type_param ? 'return_type' : 'accept header';
126128

127129
$data = $this->getData();
128-
$input = "<select{$this->id}{$inputClass}{$data}>$inputContents</select>";
130+
$input = "<select{$this->id}{$inputClass}{$data}{$disabled}>$inputContents</select>";
129131
$html .= $wrapper !== null ? "<{$wrapper}{$wrapperClass}>" : '';
130132
$html .= "<label{$labelClass}>{$labelText}{$labelAfter}</label>";
131133
$html .= $input;

‎src/ApiOptions/Input/Ascension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function get(): string
6060
: (self::$globalWrapper !== null
6161
? self::$globalWrapper
6262
: null);
63+
$disabled = $this->disabled ? ' disabled' : '';
6364

6465
$data = $this->getData();
6566
$today = new DateTime();
@@ -76,7 +77,7 @@ public function get(): string
7677
$nextSunday = $today->modify('next Sunday');
7778
$Sunday = $formatter->format($nextSunday);
7879
$input = <<<ELEMENT
79-
<select{$this->id}{$inputClass}{$data}>
80+
<select{$this->id}{$inputClass}{$data}{$disabled}>
8081
<option value="">--</option>
8182
<option value="THURSDAY">{$Thursday}</option>
8283
<option value="SUNDAY">{$Sunday}</option>

‎src/ApiOptions/Input/CorpusChristi.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function get(): string
5959
: (self::$globalWrapper !== null
6060
? self::$globalWrapper
6161
: null);
62+
$disabled = $this->disabled ? ' disabled' : '';
6263

6364
$data = $this->getData();
6465
$today = new DateTime();
@@ -75,7 +76,7 @@ public function get(): string
7576
$nextSunday = $today->modify('next Sunday');
7677
$Sunday = $formatter->format($nextSunday);
7778
$input = <<<ELEMENT
78-
<select{$this->id}{$inputClass}{$data}>
79+
<select{$this->id}{$inputClass}{$data}{$disabled}>
7980
<option value="">--</option>
8081
<option value="THURSDAY">{$Thursday}</option>
8182
<option value="SUNDAY">{$Sunday}</option>

‎src/ApiOptions/Input/Epiphany.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function get(): string
6060
: (self::$globalWrapper !== null
6161
? self::$globalWrapper
6262
: null);
63+
$disabled = $this->disabled ? ' disabled' : '';
6364

6465
$data = $this->getData();
6566
$Jan6 = '';
@@ -80,7 +81,7 @@ public function get(): string
8081
}
8182
$SundayJan2Jan8 = dgettext('litcompphp', 'Sunday between January 2nd and 8th');
8283
$input = <<<ELEMENT
83-
<select{$this->id}{$inputClass}{$data}>
84+
<select{$this->id}{$inputClass}{$data}{$disabled}>
8485
<option value="">--</option>
8586
<option value="JAN6">{$Jan6}</option>
8687
<option value="SUNDAY_JAN2_JAN8">{$SundayJan2Jan8}</option>

‎src/ApiOptions/Input/EternalHighPriest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ public function get(): string
5555
: (self::$globalWrapper !== null
5656
? self::$globalWrapper
5757
: null);
58+
$disabled = $this->disabled ? ' disabled' : '';
5859

5960
$data = $this->getData();
6061
$true = dgettext('litcompphp', 'true');
6162
$false = dgettext('litcompphp', 'false');
6263
$input = <<<ELEMENT
63-
<select{$this->id}{$inputClass}{$data}>
64+
<select{$this->id}{$inputClass}{$data}{$disabled}>
6465
<option value="">--</option>
6566
<option value="true">{$true}</option>
6667
<option value="false">{$false}</option>

‎src/ApiOptions/Input/Locale.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ public function get(): string
115115
: (self::$globalWrapper !== null
116116
? self::$globalWrapper
117117
: null);
118+
$disabled = $this->disabled ? ' disabled' : '';
118119

119120
$data = $this->getData();
120121
$localesOptions = array_map(fn(string $k, string $v) => "<option value=\"{$k}\"" . ($k === 'la' ? ' selected' : '') . ">{$k} ({$v})</option>", array_keys(self::$apiLocalesDisplay[ApiOptions::$locale]), array_values(self::$apiLocalesDisplay[ApiOptions::$locale]));
121122
$localesHtml = implode("\n", $localesOptions);
122123
$html .= $wrapper !== null ? "<{$wrapper}{$wrapperClass}>" : '';
123124
$html .= "<label{$labelClass}>locale{$labelAfter}</label>";
124-
$html .= "<select{$this->id}{$inputClass}{$data}>{$localesHtml}</select>";
125+
$html .= "<select{$this->id}{$inputClass}{$data}{$disabled}>{$localesHtml}</select>";
125126
$html .= $wrapper !== null ? "</{$wrapper}>" : '';
126127
return $html;
127128
}

‎src/ApiOptions/Input/YearType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ public function get(): string
5757
: (self::$globalWrapper !== null
5858
? self::$globalWrapper
5959
: null);
60+
$disabled = $this->disabled ? ' disabled' : '';
6061

6162
$data = $this->getData();
6263
$input = <<<ELEMENT
63-
<select{$this->id}{$inputClass}{$data}>
64+
<select{$this->id}{$inputClass}{$data}{$disabled}>
6465
<option value="LITURGICAL">LITURGICAL</option>
6566
<option value="CIVIL">CIVIL</option>
6667
</select>

0 commit comments

Comments
 (0)
Please sign in to comment.