add heading field

This commit is contained in:
David Remer 2020-08-14 10:09:11 +03:00
parent 13d8c61b2a
commit e24fc0d7ab
3 changed files with 31 additions and 4 deletions

View file

@ -346,8 +346,15 @@ return [
], ],
//General button styles //General button styles
'button_style_heading' => [
// General button styles 'heading' => __('General styles', 'woocommerce-paypal-commerce-gateway'),
'type' => 'ppcp-heading',
'screens' => [
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
'button_layout' => [ 'button_layout' => [
'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'), 'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'),
'type' => 'select', 'type' => 'select',

View file

@ -104,6 +104,22 @@ class SettingsRenderer
return $html; return $html;
} }
public function renderHeading($field, $key, $config, $value): string
{
if ($config['type'] !== 'ppcp-heading') {
return $field;
}
$html = sprintf(
'<h2 class="%s">%s</h2>',
esc_attr(implode(' ', $config['class'])),
esc_html($config['heading'])
);
return $html;
}
//phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType //phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
public function render() public function render()
@ -122,9 +138,11 @@ class SettingsRenderer
} }
$value = $this->settings->has($field) ? $this->settings->get($field) : null; $value = $this->settings->has($field) ? $this->settings->get($field) : null;
$id = 'ppcp[' . $field . ']'; $id = 'ppcp[' . $field . ']';
$colspan = $config['type'] !== 'ppcp-heading' ? 1 : 2;
?> ?>
<tr valign="top" id="<?php echo esc_attr('field-' . $field); ?>"> <tr valign="top" id="<?php echo esc_attr('field-' . $field); ?>">
<?php if ($config['type'] !== 'ppcp-heading') : ?>
<th> <th>
<label <label
for="<?php echo esc_attr($id); ?>" for="<?php echo esc_attr($id); ?>"
@ -137,7 +155,8 @@ class SettingsRenderer
<?php unset($config['description']); <?php unset($config['description']);
endif; ?> endif; ?>
</th> </th>
<td><?php <?php endif; ?>
<td colspan="<?php echo (int) $colspan; ?>"><?php
$config['type'] === 'ppcp-text' ? $config['type'] === 'ppcp-text' ?
$this->renderText($config) $this->renderText($config)
: woocommerce_form_field($id, $config, $value); ?></td> : woocommerce_form_field($id, $config, $value); ?></td>

View file

@ -119,7 +119,8 @@ class WcGatewayModule implements ModuleInterface
*/ */
$field = $renderer->renderMultiSelect($field, $key, $args, $value); $field = $renderer->renderMultiSelect($field, $key, $args, $value);
$field = $renderer->renderPassword($field, $key, $args, $value); $field = $renderer->renderPassword($field, $key, $args, $value);
$field = $renderer->rendrenderTextInputerMultiSelect($field, $key, $args, $value); $field = $renderer->renderTextInput($field, $key, $args, $value);
$field = $renderer->renderHeading($field, $key, $args, $value);
return $field; return $field;
}, },
10, 10,