Skip to content

Commit 9c2106a

Browse files
committed
Allow dashed id's in field types, and sanitize the type on getter.
1 parent b82a886 commit 9c2106a

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/Api/SettingField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ public function setType(string $type): self
313313

314314
/**
315315
* Get the Fields type.
316+
* @since 2.8.1 Replace "_" & "-". Example: Type=datetime-local, Method=datetimeLocal().
316317
* @return string
317318
*/
318319
public function getType(): string
319320
{
320-
return $this->type;
321+
return str_replace(['_', '-'], '', lcfirst(ucwords($this->type, '_-')));
321322
}
322323

323324
/**

src/Settings/FieldTypes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FieldTypes
2727
public const FIELD_TYPE_TEXT = 'text';
2828
public const FIELD_TYPE_URL = 'url';
2929
public const FIELD_TYPE_DATE = 'date';
30-
public const FIELD_TYPE_DATETIME = 'datetime';
30+
public const FIELD_TYPE_DATETIME = 'datetime-local';
3131
public const FIELD_TYPE_EMAIL = 'email';
3232
public const FIELD_TYPE_COLOR = 'color';
3333
public const FIELD_TYPE_COLOR_ALPHA = 'coloralpha';
@@ -129,10 +129,10 @@ public function date(array $args): void
129129
* Renders an input datetime-local field.
130130
* @param array $args Array of Field object parameters
131131
*/
132-
public function datetime(array $args): void
132+
public function datetimeLocal(array $args): void
133133
{
134134
$field = $this->getSettingFieldObject($args);
135-
$args[SettingField::TYPE] = sprintf('%s-local', FieldTypes::FIELD_TYPE_DATETIME);
135+
$args[SettingField::TYPE] = FieldTypes::FIELD_TYPE_DATETIME;
136136
$field->setAttributes(
137137
array_merge(
138138
$field->getAttributes(),

0 commit comments

Comments
 (0)