Skip to content

Commit

Permalink
テーマ設定の「リンク先URL」欄のルートパスやnullがエラー 対策
Browse files Browse the repository at this point in the history
  • Loading branch information
IwasakiRyuichi committed Jan 24, 2025
1 parent 6557809 commit 318bcc4
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions plugins/bc-theme-config/src/Model/Table/ThemeConfigsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ public function validationKeyValue(Validator $validator): Validator
$validator->add('logo_link', [
'urlCheck' => [
'rule' => function ($value, $context) {
// 空白またはルートパス(/)の場合はバリデーションをスキップ
if (empty($value) || $value === '/') {
return true;
}
// それ以外の場合はURL形式をチェック
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
Expand All @@ -151,11 +149,17 @@ public function validationKeyValue(Validator $validator): Validator
]
]);

$validator->add('main_image_link_1',[

$validator->add('main_image_link_1', [
'urlCheck' => [
'rule' => ['url', true],
'rule' => function ($value) {
if (empty($value) || $value === '/') {
return true;
}
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
]
]
]);

// main_image_2
Expand All @@ -167,11 +171,16 @@ public function validationKeyValue(Validator $validator): Validator
]
]);

$validator->add('main_image_link_2',[
$validator->add('main_image_link_2', [
'urlCheck' => [
'rule' => ['url', true],
'rule' => function ($value) {
if (empty($value) || $value === '/') {
return true;
}
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
]
]
]);

// main_image_3
Expand All @@ -183,11 +192,16 @@ public function validationKeyValue(Validator $validator): Validator
]
]);

$validator->add('main_image_link_3',[
$validator->add('main_image_link_3', [
'urlCheck' => [
'rule' => ['url', true],
'rule' => function ($value, $context) {
if (empty($value) || $value === '/') {
return true;
}
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
]
]
]);

// main_image_4
Expand All @@ -199,11 +213,16 @@ public function validationKeyValue(Validator $validator): Validator
]
]);

$validator->add('main_image_link_4',[
$validator->add('main_image_link_4', [
'urlCheck' => [
'rule' => ['url', true],
'rule' => function ($value) {
if (empty($value) || $value === '/') {
return true;
}
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
]
]
]);

// main_image_5
Expand All @@ -215,11 +234,16 @@ public function validationKeyValue(Validator $validator): Validator
]
]);

$validator->add('main_image_link_5',[
$validator->add('main_image_link_5', [
'urlCheck' => [
'rule' => ['url', true],
'rule' => function ($value, $context) {
if (empty($value) || $value === '/') {
return true;
}
return filter_var($value, FILTER_VALIDATE_URL) !== false;
},
'message' => __d('baser_core', '無効なURLです')
]
]
]);
return $validator;
}
Expand Down

0 comments on commit 318bcc4

Please sign in to comment.