| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\CssConverter\Converters; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\CssConverter\Conversion_Context; |
| 6 |
use Elementor\Modules\AtomicWidgets\CssConverter\Property_Converter_Base; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Span_Prop_Type; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Reusable converter for properties backed by a Span_Prop_Type (grid-column/grid-row). One instance |
| 15 |
* per property. Accepts any non-empty string that matches the schema regex (URLs/semicolons are |
| 16 |
* rejected by the live grid-* pattern); a non-matching value declines (-> custom_css). Emits the |
| 17 |
* canonical Span PropValue from generate(). |
| 18 |
*/ |
| 19 |
class Span_Property_Converter extends Property_Converter_Base { |
| 20 |
private string $property; |
| 21 |
|
| 22 |
private ?string $pattern; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param string $property The schema property this converter owns. |
| 26 |
* @param string|null $pattern The Span regex sourced from the schema, or null for no constraint. |
| 27 |
*/ |
| 28 |
public function __construct( string $property, ?string $pattern = null ) { |
| 29 |
$this->property = $property; |
| 30 |
$this->pattern = $pattern; |
| 31 |
} |
| 32 |
|
| 33 |
protected function get_supported_properties(): array { |
| 34 |
return [ $this->property ]; |
| 35 |
} |
| 36 |
|
| 37 |
protected function do_convert( Conversion_Context $context, array $rule ): bool { |
| 38 |
$value = trim( $rule['value'] ); |
| 39 |
|
| 40 |
if ( '' === $value ) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
if ( null !== $this->pattern && 1 !== preg_match( $this->pattern, $value ) ) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
$context->set_prop( $this->property, Span_Prop_Type::generate( $value ) ); |
| 49 |
|
| 50 |
return true; |
| 51 |
} |
| 52 |
} |
| 53 |
|