Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some 'undefined array key' warnings #4121

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function render(Varien_Data_Form_Element_Abstract $element)
$defTextArr = [];
foreach ($options as $k => $v) {
if ($isMultiple) {
if (is_array($v['value']) && in_array($k, $v['value'])) {
if (array_key_exists('value', $v) && is_array($v['value']) && in_array($k, $v['value'])) {
$defTextArr[] = $v['label'];
}
} elseif (isset($v['value'])) {
} elseif (is_array($v) && array_key_exists('value', $v)) {
if ($v['value'] == $defText) {
$defTextArr[] = $v['label'];
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ protected function _getOptions()
*/
protected function _renderOption($option, $value)
{
$selected = (($option['value'] == $value && (!is_null($value))) ? ' selected="selected"' : '');
if (!array_key_exists('value', $option)) {
if (!array_key_exists('label', $option)) {
return '';
}

$lbl = $this->escapeHtml($option['label']); // or just empty as well?
return '<option value="' . $lbl . '">' . $lbl . '</option>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for setting label (instead of empty string) to option value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it, so each option has a different / its own value, what the 'value' key in the map was supposed to provide.
If you think that's not required, we can leave the value attribute of the tag empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer an empty string.

Maybe you can share the extension that causes the problem, to reproduce it?

Copy link
Contributor Author

@alexh-swdev alexh-swdev Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll change it to empty string then.
It's an Amazon Pay add-on from creative style. I hope I can provide it in the next days

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

$selected = (!is_null($value) && ($option['value'] == $value)) ? ' selected="selected"' : '';
return '<option value="' . $this->escapeHtml($option['value']) . '"' . $selected . '>' . $this->escapeHtml($option['label']) . '</option>';
}

Expand All @@ -66,7 +75,7 @@ public function getHtml()
$html = '<select name="' . $this->_getHtmlName() . '" id="' . $this->_getHtmlId() . '" class="no-changes">';
$value = $this->getValue();
foreach ($this->_getOptions() as $option) {
if (is_array($option['value'])) {
if (array_key_exists('value', $option) && is_array($option['value'])) {
$html .= '<optgroup label="' . $this->escapeHtml($option['label']) . '">';
foreach ($option['value'] as $subOption) {
$html .= $this->_renderOption($subOption, $value);
Expand Down
Loading