|
23 | 23 | // get the keys and normalize to lowercase |
24 | 24 | $originalContentKeys = array_keys($contentFields); |
25 | 25 | $contentFieldKeys = array_map('strtolower', $originalContentKeys); |
| 26 | + $contentFieldKeys = array_map('mb_strtolower', $originalContentKeys); |
26 | 27 |
|
27 | 28 | // get all field keys from blueprint and normalize to lowercase |
28 | 29 | $blueprintFields = array_keys($item->blueprint()->fields()); |
29 | | - $blueprintFieldKeys = array_map('strtolower', $blueprintFields); |
| 30 | + $blueprintFieldKeys = array_map('mb_strtolower', $blueprintFields); |
30 | 31 |
|
31 | 32 | // get all field keys that are in $contentFieldKeys but not in $blueprintFieldKeys |
32 | 33 | $fieldsToBeDeleted = array_diff($contentFieldKeys, $blueprintFieldKeys); |
|
36 | 37 | // create a mapping: lowercase => original field name |
37 | 38 | $lowercaseToOriginal = array_combine($contentFieldKeys, $originalContentKeys); |
38 | 39 |
|
39 | | - // flip keys and values and set new values to null |
40 | | - $data = array_map( |
41 | | - fn ($field) => null, |
42 | | - array_flip(array_intersect_key($lowercaseToOriginal, array_flip($fieldsToBeDeleted))) |
43 | | - ); |
| 40 | + // build data array with original field names as keys and null as values |
| 41 | + $data = []; |
| 42 | + foreach ($fieldsToBeDeleted as $lowercaseField) { |
| 43 | + $originalField = $lowercaseToOriginal[$lowercaseField]; |
| 44 | + $data[$originalField] = null; |
| 45 | + } |
44 | 46 |
|
45 | 47 | // try to update the page with the data |
46 | | - if (count($data) > 0) { |
47 | | - $item->update($data, $lang); |
48 | | - } |
| 48 | + $item->update($data, $lang); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | }; |
|
0 commit comments