@@ -15,7 +15,7 @@ class AllowedIps extends \Magento\Framework\App\Config\Value
15
15
/**
16
16
* @var \Magento\Framework\Message\ManagerInterface
17
17
*/
18
- protected $ messageManager ;
18
+ private $ messageManager ;
19
19
20
20
/**
21
21
* Constructor
@@ -48,33 +48,33 @@ public function __construct(
48
48
*/
49
49
public function beforeSave ()
50
50
{
51
- parent ::beforeSave ();
52
- $ fieldSetData = $ this ->getFieldsetDataValue ('allow_ips ' );
53
- $ noticeMsg = '' ;
54
- $ allowedIps = '' ;
51
+ $ allowedIpsRaw = $ this ->getFieldsetDataValue ('allow_ips ' );
52
+ $ noticeMsgArray = [];
53
+ $ allowedIpsArray = [];
55
54
56
- if (empty ($ fieldSetData )) {
57
- return $ this ;
55
+ if (empty ($ allowedIpsRaw )) {
56
+ return parent :: beforeSave () ;
58
57
}
59
58
60
- $ dataArray = preg_split ('#\s*,\s*# ' , $ fieldSetData , null , PREG_SPLIT_NO_EMPTY );
59
+ $ dataArray = preg_split ('#\s*,\s*# ' , $ allowedIpsRaw , null , PREG_SPLIT_NO_EMPTY );
61
60
foreach ($ dataArray as $ k => $ data ) {
62
61
$ data = trim (preg_replace ('/\s+/ ' ,'' , $ data ));
63
- if ( ! filter_var ($ data , FILTER_VALIDATE_IP ) === false ) {
64
- $ allowedIps .= ( empty ( $ allowedIps )) ? $ data : " , " . $ data ;
62
+ if ( filter_var ($ data , FILTER_VALIDATE_IP ) ) {
63
+ $ allowedIpsArray [] = $ data ;
65
64
} else {
66
- $ noticeMsg .= ( empty ( $ noticeMsg )) ? $ data : " , " . $ data ;
65
+ $ noticeMsgArray [] = $ data ;
67
66
}
68
67
}
69
68
70
- if (!empty ($ noticeMsg ))
69
+ $ noticeMsg = implode (', ' , $ noticeMsgArray );
70
+ if (!empty ($ noticeMsgArray ))
71
71
$ this ->messageManager ->addNotice (
72
72
__ (
73
- ' Invalid values ' . $ noticeMsg . ' are not saved. '
73
+ __ ( ' The following invalid values cannot be saved: %values ' , [ ' values ' => $ noticeMsg ])
74
74
)
75
75
);
76
76
77
- $ this ->setValue ($ allowedIps );
78
- return $ this ;
77
+ $ this ->setValue (implode ( ' , ' , $ allowedIpsArray ) );
78
+ return parent :: beforeSave () ;
79
79
}
80
80
}
0 commit comments