mirror of
https://github.com/proelements/proelements.git
synced 2026-04-05 20:13:47 +00:00
v3.34.0
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\Attributes\Controls;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Repeatable_Control as Core_Repeatable_Control;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Repeatable_Attributes_Control extends Core_Repeatable_Control {
|
||||
private ?array $add_item_tooltip_props = null;
|
||||
|
||||
public function set_addItemTooltipProps( array $props ): self {
|
||||
$this->add_item_tooltip_props = $props;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_props(): array {
|
||||
$props = parent::get_props();
|
||||
|
||||
if ( null !== $this->add_item_tooltip_props ) {
|
||||
$props['addItemTooltipProps'] = (object) $this->add_item_tooltip_props;
|
||||
}
|
||||
|
||||
return $props;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ namespace ElementorPro\Modules\Attributes;
|
||||
|
||||
use ElementorPro\Base\Module_Base;
|
||||
use ElementorPro\License\API;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Types\Repeatable_Control;
|
||||
use ElementorPro\Modules\Attributes\Controls\Repeatable_Attributes_Control;
|
||||
use Elementor\Modules\AtomicWidgets\Controls\Section;
|
||||
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
|
||||
use ElementorPro\Modules\Attributes\PropsResolver\Transformers\Settings\Pro_Attributes_Transformer;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
@@ -20,10 +22,26 @@ class Module extends Module_Base {
|
||||
return API::is_licence_has_feature( 'atomic-custom-attributes' );
|
||||
}
|
||||
|
||||
private function is_license_expired() {
|
||||
return API::is_license_expired();
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
if ( $this->is_attributes_active() ) {
|
||||
if ( $this->is_attributes_active() || $this->is_license_expired() ) {
|
||||
add_action(
|
||||
'elementor/atomic-widgets/settings/transformers/register',
|
||||
function ( $transformers ) {
|
||||
$attributes_key = Attributes_Prop_Type::get_key();
|
||||
$transformers->register(
|
||||
$attributes_key,
|
||||
new Pro_Attributes_Transformer()
|
||||
);
|
||||
},
|
||||
20
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'elementor/atomic-widgets/controls',
|
||||
fn( $element_controls, $atomic_element ) => $this->inject_attrs_control( $element_controls, $atomic_element ),
|
||||
@@ -35,14 +53,17 @@ class Module extends Module_Base {
|
||||
|
||||
private function inject_attrs_control( $element_controls, $atomic_element ) {
|
||||
$schema = $atomic_element::get_props_schema();
|
||||
if ( ! array_key_exists( 'attributes', $schema ) || ! class_exists( '\\Elementor\\Modules\\AtomicWidgets\\PropTypes\\Attributes_Prop_Type' ) ) {
|
||||
|
||||
if ( ! array_key_exists( 'attributes', $schema ) ) {
|
||||
return $element_controls;
|
||||
}
|
||||
|
||||
foreach ( $element_controls as $item ) {
|
||||
if ( $item instanceof Section && $item->get_id() === 'settings' ) {
|
||||
$control = Repeatable_Control::bind_to( 'attributes' )
|
||||
->set_meta( [ 'topDivider' => true ] )
|
||||
$is_empty_controls = empty( $item->get_items() );
|
||||
|
||||
$control = Repeatable_Attributes_Control::bind_to( 'attributes' )
|
||||
->set_meta( [ 'topDivider' => ! $is_empty_controls ] )
|
||||
->set_repeaterLabel( __( 'Attributes', 'elementor-pro' ) )
|
||||
->set_initialValues(
|
||||
[
|
||||
@@ -67,6 +88,14 @@ class Module extends Module_Base {
|
||||
$control->set_prop_key( 'attributes' );
|
||||
}
|
||||
|
||||
if ( $this->is_license_expired() || ! $this->is_attributes_active() ) {
|
||||
$control
|
||||
->set_addItemTooltipProps( [
|
||||
'disabled' => true,
|
||||
] )
|
||||
->set_child_control_props( (object) [ 'readOnly' => true ] );
|
||||
}
|
||||
|
||||
$item->add_item( $control );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\Attributes\PropsResolver\Transformers\Settings;
|
||||
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Props_Resolver_Context;
|
||||
use Elementor\Modules\AtomicWidgets\PropsResolver\Transformer_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Pro_Attributes_Transformer extends Transformer_Base {
|
||||
public function transform( $value, Props_Resolver_Context $context ) {
|
||||
if ( ! is_array( $value ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = implode( ' ', array_map( function ( $item ) {
|
||||
if ( ! $this->is_valid_attribute_item( $item ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$escaped_value = esc_attr( $item['value'] );
|
||||
|
||||
return $item['key'] . '="' . $escaped_value . '"';
|
||||
}, $value ) );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function is_valid_attribute_item( $item ): bool {
|
||||
return isset( $item['key'], $item['value'] )
|
||||
&& '' !== $item['key']
|
||||
&& '' !== $item['value'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user