Skip to content

Commit

Permalink
Add validation to blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianPrieber committed Oct 15, 2024
1 parent 434e6bb commit ac6daad
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 9 deletions.
11 changes: 10 additions & 1 deletion blocks/email/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [
'link' => [
'required',
'string',
'max:255',
],
];

// Prepare the link data
$linkData = [
'title' => $request->title,
'button_id' => "6",
'link' => $request->link,
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
13 changes: 10 additions & 3 deletions blocks/heading/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [
'title' => [
'required',
'string',
'max:255',
],
];

// Prepare the link data
$linkData = [
'title' => $request->title,
'button_id' => "42",
'var1' => "1",
'var2' => "1",
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
10 changes: 9 additions & 1 deletion blocks/link/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
*/
function handleLinkType($request, $linkType) {

$rules = [
'title' => [
'required',
'string',
'max:255',
],
];

if ($request->GetSiteIcon == "1") {
$buttonID = "2";
} else {
Expand All @@ -21,5 +29,5 @@ function handleLinkType($request, $linkType) {
'button_id' => $buttonID,
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
10 changes: 9 additions & 1 deletion blocks/spacer/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [
'height' => [
'required',
'max:255',
],
];

// Prepare the link data
$linkData = [
'title' => $request->height ?? null,
'button_id' => "43",
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
11 changes: 10 additions & 1 deletion blocks/telephone/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [
'link' => [
'required',
'max:255',
],
];

// Prepare the link data
$linkData = [
'title' => $request->title,
'button_id' => "44",
'link' => $request->link,
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
11 changes: 10 additions & 1 deletion blocks/text/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [
'text' => [
'required',
'string',
'max:5000',
],
];

// Sanitize the text input
$sanitizedText = $request->text;
$sanitizedText = strip_tags($sanitizedText, '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
Expand All @@ -24,5 +33,5 @@ function handleLinkType($request, $linkType) {
'button_id' => "93", // Assuming '93' is a predefined ID for a "text" button
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}
5 changes: 4 additions & 1 deletion blocks/vcard/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* @return array The prepared link data.
*/
function handleLinkType($request, $linkType) {

$rules = [];

// Extract the necessary data from the request
$data = $request->only([
'prefix', 'first_name', 'middle_name', 'last_name', 'suffix', 'nickname',
Expand All @@ -25,5 +28,5 @@ function handleLinkType($request, $linkType) {
'button_id' => "96",
];

return $linkData;
return ['rules' => $rules, 'linkData' => $linkData];
}

0 comments on commit ac6daad

Please sign in to comment.