I am building a Widget for Elementor. It's a 'basic' widget where I need to grab the value of a control. Like, if I choose a select control a method will be called and will show another select control or something. Here is what I am doing:
protected function register_controls()
{
$this->start_controls_section(
'new_section',
[
'label' => esc_html__('Settings', 'textdomain'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
// New Select settings
$this->add_control(
'data_types',
[
'label' => esc_html__('Testimonial Type', 'textdomain'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => [
'static' => 'Static',
'dynamic' => 'Dynamic',
],
'default' => 'static',
]
);
// I want to get 'data_types' value here to call the *get_data_by_type($type)*
$this->end_controls_section();
}
public function get_data_by_type($type){
// Something will be done with the data type.
}
Related
Maybe I'm in over my head but I'm trying to create an extension for WpGraphQL to just gather the YITH WooCommerce Product Add-Ons info for each product but I've gotten to the point of banging my head against the desk in frustration. Is there a fairly easy way to just output the array into nodes? The following is what I have so far, currently I'm only getting one product with a set ID (later, hopefully it will get the one associated with that query). I can get a simple string output but I can't get it to output the array into nodes? What am I doing wrong? I commented out ideas I had for an output but it just usually results in an error or null. I do see the graphql_debug working and outputting $fields as an array though? Thanks!
register_graphql_object_type('MyNewType', [
'description' => __('Describe the Type and what it represents', 'replace-me'),
'fields' => [
'nodes' => [
'type' => 'String',
'description' => __('Describe what this field should be used for', 'replace-me'),
'fields' => [
'form_type' => [
'type' => 'String',
'description' => __('Describe what this field should be used for', 'replace-me'),
],
],
],
],
]);
register_graphql_field(
'Product',
'YITH_fields',
[
'type' => 'MyNewType',
'description' => __('Example field added to the Post Type', 'replace-with-your-textdomain'),
'resolve' => function (\WPGraphQL\Model\Post $post) {
global $wpdb;
$sql = "SELECT wp_live_yith_wapo_types.type, wp_live_yith_wapo_types.options FROM wp_live_yith_wapo_groups JOIN wp_live_yith_wapo_types on wp_live_yith_wapo_groups.id = wp_live_yith_wapo_types.group_id WHERE FIND_IN_SET(13, products_id)";
$results = $wpdb->get_results($sql);
if ($results) {
$array = array('nodes');
//$array = array();
foreach ($results as $result) {
$type = array('form_type' => $result->type);
$options = maybe_unserialize($result->options);
$result = array_merge($type, $options);
$array[] = $result;
}
//$array = wp_json_encode($array);
$fields = !empty($array) ? $array : null;
} else {
$fields = null;
}
graphql_debug($fields, ['type' => 'ARGS_BREAKPOINT']);
//return $fields['nodes'];
return $fields;
}
]
);
Probably it's good enough to return an array of Info 'records' (without embedding into nodes subfield - it would require some, own 'InfoList' type def.), then you need a type for single Info, like:
register_graphql_object_type('MyInfoItem', [
'description' => __('Describe the Type and what it represents', 'replace-me'),
'fields' => [
'form_type' => [
'type' => 'String',
'description' => __('Describe what this field should be used for', 'replace-me'),
],
// options field - list of some scalar or custom type
'options' => [
'type' => [ 'list_of' => 'String' ],
'description' => __('Describe what this field should be used for', 'replace-me'),
],
],
]);
extend Product with:
register_graphql_field(
'Product',
'YITH_fields',
[
'type' => [ 'list_of' => 'MyInfoItem' ],
'description' => __('Example field added to the Post Type', 'replace-with-your-textdomain'),
'resolve' => function (\WPGraphQL\Model\Post $post) {
// ...
return [
['form_type' => 'some_value'],
[
'form_type' => 'other_value',
'options' => ['opt_1', 'opt_2'],
],
];
Any, not trivial data 'nesting level' requires a separate type definition.
For more complex options 'records' you need to register another type - e.g. ids required for optional option selection.
If you don't want to explicitely express these [unknown/dynamic] structures, you can use custom JSON scalar type.
I am having trouble with elementor prefix class using with CHOOSE control
Here is code snippet
$this->add_responsive_control(
'course_author_layout',
[
'label' => __('Layout', 'text-domain'),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => __('Left', 'text-domain'),
'icon' => 'fa fa-long-arrow-left',
],
'up' => [
'title' => __('Center', 'text-domain'),
'icon' => 'fa fa-long-arrow-up',
],
],
'prefix_class' => 'etlms-author-layout-%s',
'default' => 'left',
]
);
Problem is here in prefix_class. In the HTML Markup prefix class is showing with %s but there should only show value.
Current scenario of class : etlms-author-layout-%sleft
Expected result of class : etlms-author-layout-left
Just remove the %s, then you will get the expected result.
So, I am working with the Repeater beta add-on for Gravity Forms (https://docs.gravityforms.com/repeater-fields/), and I need to make it required--or more specifically, the first entry within it's field. I have tried various methods to no avail and am not sure why.
I tried setting "required" to true for the fields inside the repeater
I tried setting the "required" to true for the repeater field itself
I tried having the repeater field AND the fields within it required
In the admin, every time I click the "Required" checkbox for the repeater field, the checkbox becomes unchecked after saving the form
Using $(window).load I tried adding a required=required attribute to all fields in the repeater but that prevents the only fields in the form from displaying any "required" messages to the user, and only the first empty field in the repeater is actually checked. The rest, even if empty, are not, and do no display a "required" message.
Using $(document).ready() but the results were similar to above but the rest of the form fields started validating again
Browsing the Gravity Forms forum but could not find the answer I was looking for, and I don't know how long it will take for anyone to respond to my question and this can't wait days or weeks.
This is all the code I setup for the repeater in functions.php per the field's documentation example:
// Adjust your form ID
add_filter( 'gform_form_post_get_meta_5', 'add_my_field' );
function add_my_field( $form ) {
// Create a Single Line text field for the product member's name
$purchasedFrom = GF_Fields::create( array(
'type' => 'text',
'id' => 1002, // The Field ID must be unique on the form
'formId' => $form['id'],
'required' => true,
'label' => 'Purchased From',
'pageNumber' => 1, // Ensure this is correct
) );
$itemtype = GF_Fields::create( array(
'type' => 'text',
'id' => 1007, // The Field ID must be unique on the form
'formId' => $form['id'],
'required' => true,
'label' => 'Item Type',
'pageNumber' => 1, // Ensure this is correct
) );
// Create an email field for the product s
$quantity = GF_Fields::create( array(
'type' => 'text',
'id' => 1001, // The Field ID must be unique on the form
'formId' => $form['id'],
'required' => true,
'label' => 'Quantity',
'pageNumber' => 1, // Ensure this is correct
) );
$purchasedDate = GF_Fields::create( array(
'type' => 'text',
'id' => 1003, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Date of Purchase',
'required' => true,
'pageNumber' => 1, // Ensure this is correct
) );
$serviceDate = GF_Fields::create( array(
'type' => 'text',
'id' => 1004, // The Field ID must be unique on the form
'required' => true,
'formId' => $form['id'],
'label' => 'Date Out of Service',
'pageNumber' => 1, // Ensure this is correct
) );
$size = GF_Fields::create( array(
'type' => 'text',
'required' => true,
'id' => 1009, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' =>'Size',
'pageNumber' => 1, // Ensure this is correct
) );
$upc = GF_Fields::create( array(
'type' => 'text',
'required' => true,
'id' => 1010, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'UPC/Part # (From Receipt)',
'pageNumber' => 1, // Ensure this is correct
) );
$damage = GF_Fields::create( array(
'type' => 'text',
'required' => true,
'id' => 1005, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Description of Damage',
'pageNumber' => 1, // Ensure this is correct
) );
// Create a repeater for the product and add the name and email fields as the fields to display inside the repeater.
$product = GF_Fields::create( array(
'type' => 'repeater',
'required' => true,
'id' => 1000, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Add Products',
'addButtonText' => 'Add Another Product',
'removeButtonText'=> 'Remove Product',
'pageNumber' => 1, // Ensure this is correct
'fields' => array( $purchasedFrom,$itemtype, $quantity, $purchasedDate,$serviceDate, $size, $upc, $damage), // Add the fields here.
) );
$form['fields'][] = $product;
return $form;
}
// Remove the field before the form is saved. Adjust your form ID
add_filter( 'gform_form_update_meta_5', 'remove_my_field', 10, 3 );
function remove_my_field( $form_meta, $form_id, $meta_name ) {
if ( $meta_name == 'display_meta' ) {
// Remove the Repeater field: ID 1000
$form_meta['fields'] = wp_list_filter( $form_meta['fields'], array( 'id' => 1000 ), 'NOT' );
}
return $form_meta;
}
I do need this field to be required somehow, specifically the first entry so that the user knows to enter at least one product. What am I missing?
Hi you simply need to flag them as:
'isRequired' => true,
rather than
'required' => true,
After the change, be sure to remove the repeater from the form and update. The repeater should appear again, click update and check the results.
I'm using Sonata 3 in my project. I faced with the problem with autocomplete field.
protected function configureFormFields(FormMapper $form)
{
$form
->add(
'contactPerson',
ModelAutocompleteType::class,
[
'label' => 'Contact Person',
'property' => 'name',
'model_manager' => $this->modelManager,
'class' => ContactPerson::class,
'btn_add' => 'Add new',
'callback' => [CustomerCompanyFilters::class, 'filterContactPersons'],
]
)
}
I added 'Add new' button and can create a new entity in popup, but it is not set automatically as a field value, I need to search it again. Is it possible to set field value just after pressing 'Create' button popup?
I'm working with Yii 2, and it's grid view to show information.
Now, my problem is that whenever a user scans two identical serial numbers and/or mac addresses, it should highlight the row (change color to red), and show some error sign or whatever.
Screenshot:
What I want it to look like:
I'm new to Yii2 and don't exactly know how they do it with the grid view. I've been researching on this specific problem but couldn't find anything.
Code for Gridview
<?= GridView::widget([
'id' => 'scan-batch-grid',
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\CheckboxColumn'],
[
'attribute' => 'product_ID',
'value' => 'product.name'
],
'SN',
'MAC',
[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return Url::to(['scan-batch/view', 'id' => $key, 'scan' => $model->scan_batch_ID]);
},
'buttons' => [
'update' => function ($url, $model, $key) {
return '';
},
'delete' => function ($url, $model, $key) {
return '';
},
],
],
],
]); ?>
EDIT
I only want to know how to change the color of only one row.
Got it!
Yii2 : Adding Classes to Rows in the GridView (YouTube)
Yii2 Gridview row by row css expression
Simply add rowOptions to your gridview.
<?= GridView::widget([
'id' => 'scan-batch-grid',
'dataProvider' => $dataProvider,
'rowOptions'=>function($model){
if($a == $b){
return ['class' => 'danger'];
}
},
Thanks for posting your answer Paramone. Worked great.
Here is my implementation:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'rowOptions' => function ($model) {
if ($model->name == 'test') {
return ['class' => 'info'];
}
},