Add typehints to form block renderers
[MAILPOET-2665]
This commit is contained in:
committed by
Jack Kitterhing
parent
268fe0f2ad
commit
f959be13dd
@ -19,7 +19,7 @@ class Base {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function getInputValidation($block, $extraRules = []) {
|
||||
public function getInputValidation(array $block, array $extraRules = []): string {
|
||||
$rules = [];
|
||||
|
||||
if ($block['id'] === 'email') {
|
||||
@ -78,7 +78,7 @@ class Base {
|
||||
return join(' ', $validation);
|
||||
}
|
||||
|
||||
public function renderLabel($block) {
|
||||
public function renderLabel(array $block): string {
|
||||
$html = '';
|
||||
if (
|
||||
isset($block['params']['hide_label'])
|
||||
@ -106,7 +106,7 @@ class Base {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function renderInputPlaceholder($block) {
|
||||
public function renderInputPlaceholder(array $block): string {
|
||||
$html = '';
|
||||
// if the label is displayed as a placeholder,
|
||||
if (
|
||||
@ -126,7 +126,7 @@ class Base {
|
||||
}
|
||||
|
||||
// return field name depending on block data
|
||||
public function getFieldName($block = []) {
|
||||
public function getFieldName(array $block = []): string {
|
||||
if ((int)$block['id'] > 0) {
|
||||
return 'cf_' . $block['id'];
|
||||
} elseif (isset($block['params']['obfuscate']) && !$block['params']['obfuscate']) {
|
||||
@ -136,7 +136,7 @@ class Base {
|
||||
}
|
||||
}
|
||||
|
||||
public function getFieldLabel($block = []) {
|
||||
public function getFieldLabel(array $block = []): string {
|
||||
return (isset($block['params']['label'])
|
||||
&& strlen(trim($block['params']['label'])) > 0)
|
||||
? trim($block['params']['label']) : '';
|
||||
@ -148,7 +148,7 @@ class Base {
|
||||
? $this->wp->escAttr(trim($block['params']['value'])) : '';
|
||||
}
|
||||
|
||||
public function getInputModifiers($block = []) {
|
||||
public function getInputModifiers(array $block = []): string {
|
||||
$modifiers = [];
|
||||
|
||||
if (isset($block['params']['readonly']) && $block['params']['readonly']) {
|
||||
|
@ -17,7 +17,7 @@ class Checkbox {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||
|
@ -11,7 +11,7 @@ class Date {
|
||||
$this->baseRenderer = $baseRenderer;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
$html .= '<p class="mailpoet_paragraph">';
|
||||
$html .= $this->baseRenderer->renderLabel($block);
|
||||
@ -21,7 +21,7 @@ class Date {
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function renderDateSelect($block = []) {
|
||||
private function renderDateSelect(array $block = []): string {
|
||||
$html = '';
|
||||
|
||||
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||
@ -73,7 +73,7 @@ class Date {
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getDateTypes() {
|
||||
public function getDateTypes(): array {
|
||||
return [
|
||||
'year_month_day' => __('Year, month, day', 'mailpoet'),
|
||||
'year_month' => __('Year, month', 'mailpoet'),
|
||||
@ -82,7 +82,7 @@ class Date {
|
||||
];
|
||||
}
|
||||
|
||||
public function getDateFormats() {
|
||||
public function getDateFormats(): array {
|
||||
return [
|
||||
'year_month_day' => ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'],
|
||||
'year_month' => ['MM/YYYY', 'YYYY/MM'],
|
||||
@ -90,14 +90,14 @@ class Date {
|
||||
'month' => ['MM'],
|
||||
];
|
||||
}
|
||||
public function getMonthNames() {
|
||||
public function getMonthNames(): array {
|
||||
return [__('January', 'mailpoet'), __('February', 'mailpoet'), __('March', 'mailpoet'), __('April', 'mailpoet'),
|
||||
__('May', 'mailpoet'), __('June', 'mailpoet'), __('July', 'mailpoet'), __('August', 'mailpoet'), __('September', 'mailpoet'),
|
||||
__('October', 'mailpoet'), __('November', 'mailpoet'), __('December', 'mailpoet'),
|
||||
];
|
||||
}
|
||||
|
||||
private function getMonths($block = []) {
|
||||
private function getMonths(array $block = []): string {
|
||||
$defaults = [
|
||||
'selected' => null,
|
||||
];
|
||||
@ -126,7 +126,7 @@ class Date {
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function getYears($block = []) {
|
||||
private function getYears(array $block = []): string {
|
||||
$defaults = [
|
||||
'selected' => null,
|
||||
'from' => (int)strftime('%Y') - 100,
|
||||
@ -155,7 +155,7 @@ class Date {
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function getDays($block = []) {
|
||||
private function getDays(array $block = []): string {
|
||||
$defaults = [
|
||||
'selected' => null,
|
||||
];
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\Form\Block;
|
||||
|
||||
class Divider {
|
||||
|
||||
public function render() {
|
||||
public function render(): string {
|
||||
return '<hr class="mailpoet_divider" />';
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace MailPoet\Form\Block;
|
||||
|
||||
class Html {
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
$text = '';
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Radio {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||
|
@ -17,7 +17,7 @@ class Segment {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||
|
@ -17,7 +17,7 @@ class Select {
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$fieldName = 'data[' . $this->baseRenderer->getFieldName($block) . ']';
|
||||
|
@ -11,7 +11,7 @@ class Submit {
|
||||
$this->baseRenderer = $baseRenderer;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$html .= '<p class="mailpoet_paragraph"><input type="submit" class="mailpoet_submit" ';
|
||||
|
@ -11,7 +11,7 @@ class Text {
|
||||
$this->baseRenderer = $baseRenderer;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$type = 'text';
|
||||
$automationId = ' ';
|
||||
if ($block['id'] === 'email') {
|
||||
|
@ -10,7 +10,7 @@ class Textarea {
|
||||
$this->baseRenderer = $baseRenderer;
|
||||
}
|
||||
|
||||
public function render($block) {
|
||||
public function render(array $block): string {
|
||||
$html = '';
|
||||
|
||||
$html .= '<p class="mailpoet_paragraph">';
|
||||
|
@ -5,7 +5,10 @@ namespace MailPoet\Form\Util;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
|
||||
class DateConverter {
|
||||
public function convertDateToDatetime($date, $dateFormat) {
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function convertDateToDatetime(string $date, string $dateFormat) {
|
||||
$datetime = false;
|
||||
if ($dateFormat === 'datetime') {
|
||||
$datetime = $date;
|
||||
|
@ -115,7 +115,7 @@ class CustomField extends Model {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && is_string($value)) {
|
||||
$value = (new DateConverter())->convertDateToDatetime($value, $dateFormat);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user