| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_Form; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Webmcp_Utils { |
| 9 |
public static function build_tool_name( string $form_name, string $element_id = '' ): string { |
| 10 |
$slug = sanitize_title( $form_name ); |
| 11 |
$slug = str_replace( '-', '_', $slug ); |
| 12 |
|
| 13 |
if ( '' === $slug ) { |
| 14 |
$slug = 'submit_form'; |
| 15 |
} |
| 16 |
|
| 17 |
$id_suffix = self::build_element_id_suffix( $element_id ); |
| 18 |
|
| 19 |
if ( '' === $id_suffix ) { |
| 20 |
return $slug; |
| 21 |
} |
| 22 |
|
| 23 |
return $slug . '_' . $id_suffix; |
| 24 |
} |
| 25 |
|
| 26 |
private static function build_element_id_suffix( string $element_id ): string { |
| 27 |
$suffix = sanitize_title( $element_id ); |
| 28 |
$suffix = str_replace( '-', '_', $suffix ); |
| 29 |
|
| 30 |
return $suffix; |
| 31 |
} |
| 32 |
|
| 33 |
public static function build_tool_description( string $form_name ): string { |
| 34 |
$label = trim( $form_name ); |
| 35 |
|
| 36 |
if ( '' === $label ) { |
| 37 |
return esc_html__( 'Submit this form with the provided field values.', 'elementor' ); |
| 38 |
} |
| 39 |
|
| 40 |
return sprintf( |
| 41 |
/* translators: %s: form name */ |
| 42 |
esc_html__( 'Submit the %s form with the provided field values.', 'elementor' ), |
| 43 |
$label |
| 44 |
); |
| 45 |
} |
| 46 |
} |
| 47 |
|