Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| RowLocales | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
8 | |
100.00% |
1 / 1 |
| owned | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
8 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Panel; |
| 6 | |
| 7 | /** |
| 8 | * Whether a typed repeater row carries its own locale tabs. A row owns |
| 9 | * them when any visible sub-field renders one variant per locale, and |
| 10 | * then switches all of them at once; the sub-field wrappers inside show |
| 11 | * none. The controls listed here are the ones field/field.php renders |
| 12 | * per locale. |
| 13 | */ |
| 14 | final class RowLocales |
| 15 | { |
| 16 | private const array SWITCHABLE = ['text', 'textarea', 'iframe', 'youtube', 'element']; |
| 17 | |
| 18 | /** @param array<string, mixed> $type a row type descriptor */ |
| 19 | public static function owned(array $type, int $locales): bool |
| 20 | { |
| 21 | if ($locales < 2) { |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | foreach ((array) ($type['fields'] ?? []) as $sub) { |
| 26 | if (!is_array($sub) || ($sub['hidden'] ?? false) || !($sub['translate'] ?? false)) { |
| 27 | continue; |
| 28 | } |
| 29 | |
| 30 | $control = is_array($sub['control'] ?? null) ? $sub['control'] : []; |
| 31 | |
| 32 | if (in_array((string) ($control['name'] ?? ''), self::SWITCHABLE, true)) { |
| 33 | return true; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return false; |
| 38 | } |
| 39 | } |