← All changes
|
modules/global-classes/global-classes-labels.php
+2
-50
4.3.0-beta2
→
4.1.0-beta1
View file →
| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\GlobalClasses; |
| 4 | 4 | |
| 5 | 5 | use Elementor\Core\Kits\Documents\Kit; |
| 6 | -use Elementor\Core\Kits\Concerns\Has_Kit_Dependency; | |
| 6 | +use Elementor\Modules\GlobalClasses\Concerns\Has_Kit_Dependency; | |
| 7 | 7 | use Elementor\Modules\GlobalClasses\Concerns\Has_Preview_Context; |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | 10 | exit; |
| @@ -49,9 +49,9 @@ | ||
| 49 | 49 | return $stored; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function get_ordered_labels(): array { |
| 53 | - $order = Global_Classes_Order::make( $this->get_kit() )->set_preview( $this->is_preview() )->get_order(); | |
| 53 | + $order = Global_Classes_Order::make( $this->get_kit() )->get_order(); | |
| 54 | 54 | $map = $this->get_labels(); |
| 55 | 55 | |
| 56 | 56 | if ( $this->is_preview() ) { |
| 57 | 57 | $frontend_map = self::make( $this->get_kit() )->get_labels(); |
| @@ -70,56 +70,8 @@ | ||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | return $result; |
| 74 | - } | |
| 75 | - | |
| 76 | - public static function generate_unique_label( string $label, array $existing_labels ): string { | |
| 77 | - $prefix = 'DUP_'; | |
| 78 | - $max_length = 50; | |
| 79 | - | |
| 80 | - $has_prefix = str_starts_with( $label, $prefix ); | |
| 81 | - | |
| 82 | - if ( $has_prefix ) { | |
| 83 | - $base = substr( $label, strlen( $prefix ) ); | |
| 84 | - $counter = 1; | |
| 85 | - $candidate = $prefix . $base . $counter; | |
| 86 | - | |
| 87 | - while ( in_array( $candidate, $existing_labels, true ) ) { | |
| 88 | - $candidate = $prefix . $base . ( ++$counter ); | |
| 89 | - } | |
| 90 | - | |
| 91 | - if ( strlen( $candidate ) > $max_length ) { | |
| 92 | - $base = substr( $base, 0, $max_length - strlen( $prefix . $counter ) ); | |
| 93 | - $candidate = $prefix . $base . $counter; | |
| 94 | - } | |
| 95 | - | |
| 96 | - return $candidate; | |
| 97 | - } | |
| 98 | - | |
| 99 | - $available_length = strlen( $label ); | |
| 100 | - $candidate = $prefix . $label; | |
| 101 | - | |
| 102 | - if ( strlen( $candidate ) > $max_length ) { | |
| 103 | - $available_length = $max_length - strlen( $prefix ); | |
| 104 | - $candidate = $prefix . substr( $label, 0, $available_length ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - $base = substr( $label, 0, $available_length ); | |
| 108 | - $counter = 1; | |
| 109 | - | |
| 110 | - while ( in_array( $candidate, $existing_labels, true ) ) { | |
| 111 | - $candidate = $prefix . $base . $counter; | |
| 112 | - | |
| 113 | - if ( strlen( $candidate ) > $max_length ) { | |
| 114 | - $base = substr( $label, 0, $max_length - strlen( $prefix . $counter ) ); | |
| 115 | - $candidate = $prefix . $base . $counter; | |
| 116 | - } | |
| 117 | - | |
| 118 | - ++$counter; | |
| 119 | - } | |
| 120 | - | |
| 121 | - return $candidate; | |
| 122 | 74 | } |
| 123 | 75 | |
| 124 | 76 | public function set_labels( array $id_to_label ): bool { |
| 125 | 77 | $kit = $this->get_kit(); |