Skip to content

Commit

Permalink
Merge pull request #536 from CleanTalk/ref-psalm-l3
Browse files Browse the repository at this point in the history
Upd. Code. Refactoring to compatible with psalm L3.
  • Loading branch information
svfcode authored Jan 9, 2025
2 parents 7913b0d + 909ab6f commit b5e0503
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 240 deletions.
37 changes: 23 additions & 14 deletions lib/Cleantalk/ApbctWP/FormDecorator/FormDecoratorSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,36 @@ public static function filterSelectorParams($params, $disabled, $popup)
{
$params['nest_label_and_description_after_select'] = true;

$select = '<select'
. ' id="apbct_setting_' . $params['name'] . '"'
. " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
. ' name="cleantalk_settings[' . $params['name'] . ']' . ($params['multiple'] ? '[]"' : '"')
. ($params['multiple'] ? ' size="' . count($params['options']) . '""' : '')
. ($params['multiple'] ? ' multiple="multiple"' : '')
. $disabled
. ($params['required'] ? ' required="required"' : '')
. ' style="margin-right: 5px;">';
$data = array(
'name' => isset($params['name']) ? $params['name'] : '',
'type' => isset($params['type']) ? $params['type'] : '',
'multiple' => isset($params['multiple']) && $params['multiple'],
'size' => isset($params['multiple'], $params['options']) && $params['multiple'] ? 'size="' . count($params['options']) . '"' : '',
'multiple_attr' => isset($params['multiple']) && $params['multiple'] ? ' multiple="multiple"' : '',
'required_attr' => isset($params['required']) && $params['required'] ? ' required="required"' : '',
'disabled' => $disabled,
);

$select_layout = '<select id="apbct_setting_{{name}}" class="apbct_setting_{{type}} apbct_setting---{{name}}"
name="cleantalk_settings[{{name}}]{{multiple}}" {{size}} {{multiple_attr}} {{disabled}} {{required_attr}}
style="margin-right: 5px;">';

$select = $select_layout;
foreach ($data as $key => $value) {
$select = str_replace('{{' . $key . '}}', (string) $value, $select);
}
$params['custom_select_element'] = $select;

if (isset($params['title'])) {
$params['custom_select_title'] = '<label for="apbct_setting_' . $params['name'] . '" class="apbct_setting-field_title--' . $params['type'] . '">'
. $params['title'] . $popup
. '</label>';
$params['custom_select_title'] = '<label for="apbct_setting_' . $data['name'] . '" class="apbct_setting-field_title--' . $data['type'] . '">'
. $params['title'] . $popup
. '</label>';
}

if (isset($params['description'])) {
$params['custom_select_description'] = '<div class="apbct_settings-field_description">'
. $params['description']
. '</div>';
. $params['description']
. '</div>';
}

return $params;
Expand Down
Loading

0 comments on commit b5e0503

Please sign in to comment.