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