I have two csv databases, I already migrate de patients database to wordpress but now I need to migrate a services database, each patient can have 1 or more services. First I compare both csv databases and add the data if the Name and Last Name are the same. Everything works good, the data is in the wordpress database because I can print it, but the multicheck box doesn't show the saved data:
And another problem is that I can't click update because on the front end there is no checkbox checked so the custom post type updates the database with nothing checked.
Here is the code that I am using to get the csv data and saves it on the wordpress database:
`function wd_add_data_metabox_with_namemb()
{
wp_suspend_cache_addition(true);
$file_path = get_stylesheet_directory() . '/PATINENTS_LAVISH.csv';
// echo var_dump($file_path);
if (isset($file_path)) {
$filename = $file_path;
$count_patients = 0;
$file = fopen($filename, "r");
while (($getData = fgetcsv($file, null, ',')) !== FALSE) { //GET THE VARIABLES SET
$count_patients++;
echo $count_patients . " :";
echo var_dump($getData);
echo '<br/>';
$name = $getData[2];
$last_name = $getData[3];
if ($name != '') {
$file_path_2 = get_stylesheet_directory() . '/CHARTS_PATIENTS.csv';
$filename_2 = $file_path_2;
$count_charts = 0;
$file_2 = fopen($filename_2, "r");
while (($getData_2 = fgetcsv($file_2, null, ',')) !== FALSE) { //GET THE VARIABLES SET
echo "Chart " . $count_charts . " : ";
echo var_dump($getData_2);
echo '<br/>';
$name_chart = $getData_2[0];
$last_name_chart = $getData_2[1];
echo $name . ' and ' . $name_chart;
echo $last_name . ' and ' . $last_name_chart;
echo '<br/>';
if ($name == $name_chart && $last_name == $last_name_chart) {
$q = new WP_Query(array(
'post_type' => 'patient',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'patient_name',
'value' => $name,
),
array(
'key' => 'patient_last_name',
'value' => $last_name,
),
)
));
while ($q->have_posts()) {
$q->the_post();
$patient_id_chart = get_the_ID();
echo 'Patient ID ' . $patient_id_chart;
$service_chart = get_post_meta($patient_id_chart, 'patient_area_treated_group', true);
$service_chart_2 = get_post_meta($patient_id_chart, 'patient_pre_charting_answers', true);
echo var_dump($service_chart_2);
// check for existing charts
if (!empty($service_chart)) {
$key = count($service_chart);
} else {
$key = 0;
}
if (get_post_type() == 'patient') {
$ticket_id = $patient_id_chart . '-' . $key;
$area_treated = array(
explode(' $', $getData_2[2], 2),
);
$time = strtotime($getData_2[8]);
$comments = $getData_2[6];
$discount_type = 'fixed';
$discount_amount = $getData_2[7];
$chart_energy = $getData_2[4];
$chart_size = $getData_2[3];
$chart_dcd = $getData_2[5];
if (get_page_by_title($area_treated[0], OBJECT, 'service')) {
// Exists
} else {
// Gather post data.
$my_post = array(
'post_title' => $area_treated[0][0],
'post_status' => 'publish',
'post_type' => 'service',
'meta_input' => array(
'service_male_price' => $area_treated[0][1],
'service_female_price' => $area_treated[0][1]
)
);
// Insert the post into the database.
wp_insert_post($my_post);
}
$service_chart[$key] = array(
'patient_service_ticket_id' => $ticket_id,
'patient_area_treated' => $area_treated,
'patient_service_units' => NULL,
'patient_service_time_treated' => $time,
'patient_service_comments' => $comments,
'patient_service_discount_type' => $discount_type,
'patient_service_discount_amount' => $discount_amount,
'patient_service_picture' => NULL,
);
$pre_service_chart[$key] = array(
'patient_service_pre_chart_id' => $ticket_id,
'patient_pregnant' => '',
'patient_pre_chart_comments' => NULL,
'patient_chart_energy' => $chart_energy,
'patient_chart_size' => $chart_size,
'patient_chart_dcd' => $chart_dcd,
);
if (!empty($area_treated) || $comments != '' || $discount_type != '' || $discount_amount != '') {
update_post_meta($patient_id_chart, 'patient_area_treated_group', $service_chart);
}
if (!empty($area_treated)) {
update_post_meta($patient_id_chart, 'patient_pre_charting_answers', $pre_service_chart);
// reset the form
update_post_meta($patient_id_chart, 'patient_area_treated', '');
update_post_meta($patient_id_chart, 'patient_service_time_treated_single', '');
update_post_meta($patient_id_chart, 'patient_service_comments_single', '');
update_post_meta($patient_id_chart, 'patient_service_discount_type_single', '');
update_post_meta($patient_id_chart, 'patient_service_discount_amount_single', '');
update_post_meta($patient_id_chart, 'patient_service_pre_chart_id', '');
update_post_meta($patient_id_chart, 'patient_pregnant', '');
update_post_meta($patient_id_chart, 'patient_pre_chart_comments', '');
update_post_meta($patient_id_chart, 'patient_chart_energy', '');
update_post_meta($patient_id_chart, 'patient_chart_size', '');
update_post_meta($patient_id_chart, 'patient_chart_dcd', '');
}
}
}
$count_charts++;
}
wp_reset_postdata();
}
}
}
fclose($file);
}
}
add_action('wp_head', 'wd_add_data_metabox_with_namemb');`
I just need the multicheckbox to read the database and show the checked options.
This is the code that creates all the custom fields for the patients custom post type with cmb2 plugin:
function patient_meta()
{
$role = user_has_role(get_current_user_id(), 'staff_nurse');
/**
* Metaboxes for Patient Info
*/
if ($role == false) {
$cmb_user = new_cmb2_box(array(
'id' => 'patient_meta',
'title' => __('Patient Data', 'cmb2'),
'object_types' => array('patient'), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'vertical_tabs' => false,
'tabs' => array(
array(
'id' => 'tab-1',
'title' => __('Info', 'cmb2'),
'fields' => array(
'patient_name',
'patient_last_name',
'patient_cell_phone',
'patient_home_phone',
'patient_date_of_birth',
'patient_gender',
'patient_email',
'patient_comments'
),
),
array(
'id' => 'tab-2',
'title' => __('Services', 'cmb2'),
'fields' => array(
'patient_area_treated_single',
'patient_service_comments_single',
'patient_service_discount_type_single',
'patient_service_discount_amount_single',
'patient_service_submit_single',
),
),
array(
'id' => 'tab-3',
'title' => __('Charts', 'cmb2'),
'fields' => array(
'patient_pre_charting_answers',
'patient_pre_chart_comments',
'patient_chart_area_treated',
'patient_time_treated',
'patient_chart_energy',
'patient_chart_size',
'patient_chart_dcd',
'patient_chart_comments',
'patient_chart_discount_type',
'patient_chart_discount_amount',
),
),
array(
'id' => 'tab-4',
'title' => __('Notes', 'cmb2'),
'fields' => array(
'patient_chart_comments',
'patient_note_comments_group',
'patient_notes_comments',
),
),
array(
'id' => 'tab-5',
'title' => __('Images', 'cmb2'),
'fields' => array(
'patient_images',
),
),
array(
'id' => 'tab-6',
'title' => __('Documents', 'cmb2'),
'fields' => array(
'patient_documents',
),
),
array(
'id' => 'tab-7',
'title' => __('Clearances', 'cmb2'),
'fields' => array(
'patient_clearances',
),
),
array(
'id' => 'tab-8',
'title' => __('Referrals', 'cmb2'),
'fields' => array(
'patient_referrals',
'referred_patient_name',
'referred_date',
'referred_date_used',
'referred_discount_used',
'patient_available_ticket_ids',
),
),
array(
'id' => 'tab-9',
'title' => __('History', 'cmb2'),
'fields' => array(
'patient_area_treated_group',
'patient_service_ticket_id',
'patient_area_treated',
'patient_service_comments',
'patient_service_picture',
),
),
),
));
} else {
$cmb_user = new_cmb2_box(array(
'id' => 'patient_meta',
'title' => __('Patient Data', 'cmb2'),
'object_types' => array('patient'), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'vertical_tabs' => false,
'tabs' => array(
array(
'id' => 'tab-1',
'title' => __('Info', 'cmb2'),
'fields' => array(
'patient_name',
'patient_last_name',
'patient_cell_phone',
'patient_home_phone',
'patient_date_of_birth',
'patient_gender',
'patient_email',
'patient_comments'
),
),
array(
'id' => 'tab-2',
'title' => __('Services', 'cmb2'),
'fields' => array(
'patient_area_treated_single',
'patient_service_comments_single',
'patient_service_discount_type_single',
'patient_service_discount_amount_single',
'patient_service_submit_single',
),
),
array(
'id' => 'tab-3',
'title' => __('Charts', 'cmb2'),
'fields' => array(
'patient_pre_charting_answers',
'patient_pre_chart_comments',
'patient_chart_area_treated',
'patient_time_treated',
'patient_chart_energy',
'patient_chart_size',
'patient_chart_dcd',
'patient_chart_comments',
'patient_chart_discount_type',
'patient_chart_discount_amount',
),
),
array(
'id' => 'tab-4',
'title' => __('Notes', 'cmb2'),
'fields' => array(
'patient_chart_comments',
'patient_note_comments_group',
'patient_notes_comments',
),
),
array(
'id' => 'tab-5',
'title' => __('Images', 'cmb2'),
'fields' => array(
'patient_images',
),
),
array(
'id' => 'tab-6',
'title' => __('Documents', 'cmb2'),
'fields' => array(
'patient_documents',
),
),
array(
'id' => 'tab-7',
'title' => __('Clearances', 'cmb2'),
'fields' => array(
'patient_clearances',
),
),
array(
'id' => 'tab-8',
'title' => __('Referrals', 'cmb2'),
'fields' => array(
'patient_referrals',
'referred_patient_name',
'referred_date',
'referred_date_used',
'referred_discount_used',
'patient_available_ticket_ids',
),
),
),
));
}
$cmb_user->add_field(array(
'name' => __('Patient Name', 'cmb2'),
'id' => 'patient_name',
'type' => 'text',
'column' => true,
'description' => '',
));
$cmb_user->add_field(array(
'name' => __('Last Name', 'cmb2'),
'id' => 'patient_last_name',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Cell Phone', 'cmb2'),
'id' => 'patient_cell_phone',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Home Phone', 'cmb2'),
'id' => 'patient_home_phone',
'type' => 'text',
'column' => true,
));
$cmb_user->add_field(array(
'name' => __('Date of Birth', 'cmb2'),
'description' => '',
'id' => 'patient_date_of_birth',
'type' => 'text_date'
));
$cmb_user->add_field(array(
'name' => 'Gender',
'id' => 'patient_gender',
'type' => 'radio_inline',
'options' => array(
'Male' => __('Male', 'cmb2'),
'Female' => __('Female', 'cmb2')
),
));
$cmb_user->add_field(array(
'name' => __('Email Address', 'cmb2'),
'id' => 'patient_email',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => __('Patient Comments', 'cmb2'),
'id' => 'patient_comments',
'type' => 'textarea'
));
/**
* Metaboxes for Patient Services
*/
/*****
* Single form to add to history tab
*****/
// $cmb_user->add_field(array(
// 'id' => 'patient_service_ticket_id_single',
// 'type' => 'text',
// 'description' => 'Ticket ID / Chart ID - not for editing',
// 'name' => 'Ticket ID',
// ) );
$cmb_user->add_field(array(
'id' => 'patient_area_treated_single',
'name' => __('Area Treated', 'cmb2'),
'type' => 'radio',
'options' => get_all_services(),
'default' => 'No Treatment $0.00'
));
$cmb_user->add_field(array(
'id' => 'patient_service_time_treated_single',
'name' => __('Time Treated', 'cmb2'),
'type' => 'text_datetime_timestamp',
// 'default' => get_post_datetime()
));
// $cmb_user->add_field(array(
// 'id' => 'patient_service_comments_single',
// 'name' => __('Comments', 'cmb2'),
// 'type' => 'textarea'
// ));
$cmb_user->add_field(array(
'name' => 'Discount Type',
'id' => 'patient_service_discount_type_single',
'type' => 'radio_inline',
'options' => array(
'none' => 'None',
'percentage' => 'Percentage',
'fixed' => 'Fixed Amount'
)
));
$cmb_user->add_field(array(
'name' => __('Discount Amount', 'cmb2'),
'id' => 'patient_service_discount_amount_single',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => __('Submit Service', 'cmb2'),
'id' => 'patient_service_submit_single',
'type' => 'text'
));
$cmb_user->add_field(array(
'name' => 'Add Service',
'id' => 'patient_service_submit_single',
'type' => 'button',
'after' => '<button value="submit-single" type="submit" class="btn btn-primary">Submit</button>'
));
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_area_treated_group',
'type' => 'group',
'options' => array(
'group_title' => __('Service {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Service', 'cmb2'),
'remove_button' => __('Remove Service', 'cmb2'),
'sortable' => true
),
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_ticket_id',
'type' => 'text',
'description' => 'Ticket ID / Chart ID - not for editing',
'name' => 'Ticket ID'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_area_treated',
'name' => __('Area Treated', 'cmb2'),
'type' => 'multicheck',
'options' => get_all_services(),
'default' => 'No Treatment $0.00'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_time_treated',
'name' => __('Time Treated', 'cmb2'),
'type' => 'text_datetime_timestamp'
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_service_comments',
'name' => __('Comments', 'cmb2'),
'type' => 'textarea'
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Type',
'id' => 'patient_service_discount_type',
'type' => 'radio_inline',
'options' => array(
'none' => 'None',
'percentage' => 'Percentage',
'fixed' => 'Fixed Amount'
)
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Amount',
'id' => 'patient_service_discount_amount',
'type' => 'text',
));
// $cmb_user->add_group_field( $group_field_id, array(
// 'id' => 'patient_service_picture',
// 'name' => __('Facial Picture', 'cmb2'),
// 'type' => 'file'
// ));
/**
* Metaboxes for Patient Charting
*/
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_pre_charting_answers',
'type' => 'group',
'options' => array(
'group_title' => __('Chart {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Chart', 'cmb2'),
'remove_button' => __('Remove Chart', 'cmb2'),
'sortable' => true,
),
));
// match pre-chart to service
$cmb_user->add_group_field($group_field_id, array(
'name' => 'This Laser Pre-Chart is for test',
'id' => 'patient_service_pre_chart_id',
'type' => 'select_plus',
'description' => 'Select Service Ticket ID',
'options' => get_ticket_ids()
));
// Id's for group's fields only need to be unique for the group. Prefix is not needed.
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Are you pregnant or breastfeeding?',
'id' => 'patient_pregnant',
'type' => 'radio_inline',
'options' => array(
'Yes' => __('Yes', 'cmb2'),
'No' => __('No', 'cmb2')
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Pre Chart Comments',
'id' => 'patient_pre_chart_comments',
'type' => 'textarea_small',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Energy',
'id' => 'patient_chart_energy',
'type' => 'text',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Spot Size',
'id' => 'patient_chart_size',
'type' => 'text',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'DCD',
'id' => 'patient_chart_dcd',
'type' => 'text',
));
/**
* Metaboxes for Patient Notes
*/
$cmb_user->add_field(array(
'name' => 'Comments',
'id' => 'patient_chart_comments',
'type' => 'textarea_small',
'after' => '<button value="submit-single" type="submit" class="btn btn-primary">Submit</button>',
));
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_note_comments_group',
'type' => 'group',
'options' => array(
'group_title' => __('Comment {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Comment', 'cmb2'),
'remove_button' => __('Remove Comment', 'cmb2'),
'sortable' => true,
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Comments',
'id' => 'patient_notes_comments',
'type' => 'textarea_small',
));
/**
* Metaboxes for Patient Images
*/
$cmb_user->add_field(array(
'name' => 'Images',
'id' => 'patient_images',
'type' => 'file_list',
'text' => array(
'file_text' => 'test'
)
));
/**
* Metaboxes for Patient Documents
*/
$cmb_user->add_field(array(
'name' => 'Documents',
'id' => 'patient_documents',
'type' => 'file_list',
));
/**
* Metaboxes for Patient Clearances
*/
$cmb_user->add_field(array(
'name' => 'Clearances',
'id' => 'patient_clearances',
'type' => 'file_list',
));
/**
* Metaboxes for Patient Referrals
*/
$group_field_id = $cmb_user->add_field(array(
'id' => 'patient_referrals',
'type' => 'group',
'options' => array(
'group_title' => __('Referral {#}', 'cmb2'), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __('Add Another Referral', 'cmb2'),
'remove_button' => __('Remove Referral', 'cmb2'),
'sortable' => true,
),
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Referred Patient Name',
'id' => 'referred_patient_name',
'type' => 'select',
'options' => get_patient_names()
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Referred Date',
'id' => 'referred_date',
'type' => 'text_date',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Date Used',
'id' => 'referred_date_used',
'type' => 'text_date',
));
$cmb_user->add_group_field($group_field_id, array(
'name' => 'Discount Used',
'id' => 'referred_discount_used',
'type' => 'radio_inline',
'options' => array(
'Yes' => __('Yes', 'cmb2'),
'No' => __('No', 'cmb2')
),
));
$cmb_user->add_group_field($group_field_id, array(
'id' => 'patient_available_ticket_ids',
'name' => __('Ticket ID', 'cmb2'),
'description' => 'Assign the ticket ID to apply this discount',
'type' => 'select',
'options' => get_ticket_ids()
));
}
add_action('cmb2_init', 'patient_meta');
I am trying to create some custom Divi builder modules.
I followed the sparse documentation at their website, trying to create a module and a child module. Everything seems to be working fine, but the rendering.
It is just rendering the module shortcode as a string, and not the content.
Current code of the parent module is
class DEDE_Cards extends ET_Builder_Module {
public function init(){
$this->name = esc_html__('Custom Card', 'dede-designvox-divi-extension');
$this->plural = esc_html__('Custom Cards', 'dede-designvox-divi-extension');
$this->main_css_element = 'cards-wrapper';
$this->slug = 'dede_cards';
$this->vb_support = 'on';
$this->child_slug = 'dede_card_item';
}
public function get_fields(){
return array(
'title' => array(
'label' => esc_html__( 'Title', 'dede-designvox-divi-extension' ),
'type' => 'text',
'toggle_slug' => 'main_content',
'description' => esc_html__( 'Type the section title' ),
),
'card_title_position' => array(
'label' => esc_html__( 'Title Position', 'dede-designvox-divi-extension' ),
'type' => 'select',
'options' => array(
'overlay' => esc_html__( 'Overlay', 'et_builder' ),
'top' => esc_html__( 'Over image', 'et_builder' ),
'bottom' => esc_html__( 'Under image', 'et_builder' ),
),
'toggle_slug' => 'main_content',
'description' => esc_html__( 'Here you can choose the position of the card title', 'dede-designvox-divi-extension' ),
'default_on_front' => 'bottom',
),
);
}
function before_render() {
global $dede_card_item_number;
$dede_card_item_number = 1;
}
public function render($unprocessed_props, $content = null, $render_slug ){
global $dede_card_item_number;
return sprintf(
'<div>%1$s</div>',
$this->content
);
}
public function add_new_child_text() {
return esc_html__( 'Add New Card Item1', 'dede-designvox-divi-extension' );
}
}
new DEDE_Cards;
And then the child module
class DEDE_Card_Item extends ET_Builder_Module {
public function init(){
$this->name = esc_html__('Custom Card', 'dede-designvox-divi-extension');
$this->plural = esc_html__('Custom Cards', 'dede-designvox-divi-extension');
$this->type= 'child';
$this->child_title_var = 'title';
$this->no_render = true;
$this->slug = 'dede_card_item';
$this->vb_support = 'on';
}
public function get_fields(){
return array(
'title' => array(
'label' => esc_html__('Title', 'dede-designvox-divi-extension'),
'type' => 'text',
'description' => esc_html__('The title of this card', 'dede-designvox-divi-extension'),
'toggle_slug' => 'main_content',
),
'desc' => array(
'label' => esc_html__( 'Description', 'dede-designvox-divi-extension' ),
'type' => 'textarea',
'description' => esc_html__( 'The card description' ),
'toggle_slug' => 'main_content',
),
'src' => array(
'label' => esc_html__( 'Image', 'dede-designvox-divi-extension'),
'type' => 'upload',
'description' => esc_html__( 'Upload your desired image, or type in the URL to the image', 'dede-designvox-divi-extension'),
'upload_button_text' => esc_attr__('Upload an image', 'dede-designvox-divi-extension'),
'choose_text' => esc_attr__('Choose an Image', 'dede-designvox-divi-extension'),
'update_text' => esc_attr__('Set as Image', 'dede-designvox-divi-extension'),
'affects' => 'alt',
'toggle_slug' => 'main_content',
),
'alt' => array(
'label' => esc_html__( 'Image Alternative Text', 'dede-designvox-divi-extension' ),
'type' => 'text',
'depends_show_if' => 'on',
'depends_on' => array(
'src',
),
'description' => esc_html__( 'This defines the HTML ALT text. A short description of your image can be placed here.', 'dede-designvox-divi-extension' ),
'toggle_slug' => 'main_content',
),
'url' => array(
'label' => esc_html__( 'Link URL', 'dede-designvox-divi-extension' ),
'type' => 'text',
'description' => esc_html__( 'Enter the link that you would like this card to direct to.', 'dede-designvox-divi-extension' ),
'toggle_slug' => 'main_content',
),
);
}
}
new DEDE_Card_Item;
The shortcode is just being rendered as a string on the website, like:
[dede_card_item _builder_version=”3.14″ title=”#1 card title” desc=”#1 card desc” src=”http://localhost:8888/wp-content/uploads/2018/09/14079861_1202408189819777_4296465020285869305_n.jpg” use_background_color_gradient=”off” background_color_gradient_start=”#2b87da” background_color_gradient_end=”#29c4a9″ background_color_gradient_type=”linear” background_color_gradient_direction=”180deg” background_color_gradient_direction_radial=”center” background_color_gradient_start_position=”0%” background_color_gradient_end_position=”100%” background_color_gradient_overlays_image=”off” parallax=”off” parallax_method=”on” background_size=”cover” background_position=”center” background_repeat=”no-repeat” background_blend=”normal” allow_player_pause=”off” background_video_pause_outside_viewport=”on” text_shadow_style=”none” module_text_shadow_style=”none” box_shadow_style=”none” /][dede_card_item _builder_version=”3.14″ title=”#1 card title” desc=”#1 card desc” src=”http://localhost:8888/wp-content/uploads/2018/09/14079861_1202408189819777_4296465020285869305_n.jpg” use_background_color_gradient=”off” background_color_gradient_start=”#2b87da” background_color_gradient_end=”#29c4a9″ background_color_gradient_type=”linear” background_color_gradient_direction=”180deg” background_color_gradient_direction_radial=”center” background_color_gradient_start_position=”0%” background_color_gradient_end_position=”100%” background_color_gradient_overlays_image=”off” parallax=”off” parallax_method=”on” background_size=”cover” background_position=”center” background_repeat=”no-repeat” background_blend=”normal” allow_player_pause=”off” background_video_pause_outside_viewport=”on” text_shadow_style=”none” module_text_shadow_style=”none” box_shadow_style=”none” /][dede_card_item _builder_version=”3.14″ title=”#1 card title” desc=”#1 card desc” src=”http://localhost:8888/wp-content/uploads/2018/09/14079861_1202408189819777_4296465020285869305_n.jpg” use_background_color_gradient=”off” background_color_gradient_start=”#2b87da” background_color_gradient_end=”#29c4a9″ background_color_gradient_type=”linear” background_color_gradient_direction=”180deg” background_color_gradient_direction_radial=”center” background_color_gradient_start_position=”0%” background_color_gradient_end_position=”100%” background_color_gradient_overlays_image=”off” parallax=”off” parallax_method=”on” background_size=”cover” background_position=”center” background_repeat=”no-repeat” background_blend=”normal” allow_player_pause=”off” background_video_pause_outside_viewport=”on” text_shadow_style=”none” module_text_shadow_style=”none” box_shadow_style=”none” /][dede_card_item _builder_version=”3.14″ title=”#1 card title” desc=”#1 card desc” src=”http://localhost:8888/wp-content/uploads/2018/09/14079861_1202408189819777_4296465020285869305_n.jpg” use_background_color_gradient=”off” background_color_gradient_start=”#2b87da” background_color_gradient_end=”#29c4a9″ background_color_gradient_type=”linear” background_color_gradient_direction=”180deg” background_color_gradient_direction_radial=”center” background_color_gradient_start_position=”0%” background_color_gradient_end_position=”100%” background_color_gradient_overlays_image=”off” parallax=”off” parallax_method=”on” background_size=”cover” background_position=”center” background_repeat=”no-repeat” background_blend=”normal” allow_player_pause=”off” background_video_pause_outside_viewport=”on” text_shadow_style=”none” module_text_shadow_style=”none” box_shadow_style=”none” /]
You just have to leave out the line $this->no_render = true; and then implement the function render in the child Module.
I try to create the same module to add child items inside module. But I have another problem, when I click add child item I get the empty popup ((( like this https://prnt.sc/156jfev. I tried the same code as author
it's working for me you can try it,
Parents modules::
<?php
class GRDI_Barchart extends ET_Builder_Module {
public $slug = 'grdi_bar_chart';
public $vb_support = 'on';
protected $module_credits = array(
'module_uri' => '',
'author' => '',
'author_uri' => '',
);
public function init() {
$this->name = esc_html__( 'Bar Chart', 'grdi-graphina-divi' );
$this->plural = esc_html__( 'Bar Chart', 'et_builder' );
$this->slug = 'grdi_bar_chart';
$this->vb_support = 'on';
$this->child_slug = 'grdi_bar_chart_child';
$this->settings_modal_toggles = array(
'general' => array(
'toggles' => array(
'main_content' => esc_html__( 'Graphina Text', 'dsm-supreme-modules-for-divi' ),
),
),
'advanced' => array(
'toggles' => array(
'separator' => array(
'title' => esc_html__( 'Separator', 'dsm-supreme-modules-for-divi' ),
'priority' => 70,
),
'image' => array(
'title' => esc_html__( 'Image', 'dsm-supreme-modules-for-divi' ),
'priority' => 69,
),
),
),
);
}
public function get_fields() {
return array(
'title' => array(
'label' => esc_html__( 'Title', 'grdi-graphina-divi' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Input your desired heading here.', 'simp-simple-extension' ),
'toggle_slug' => 'main_content',
),
'content' => array(
'label' => esc_html__( 'Description', 'grdi-graphina-divi' ),
'type' => 'tiny_mce',
'option_category' => 'basic_option',
'description' => esc_html__( 'Content entered here will appear inside the module.', 'grdi-graphina-divi' ),
'toggle_slug' => 'main_content',
),
);
}
public function get_advanced_fields_config() {
return array();
}
public function get_charts(){
echo "charts";
}
public function render( $attrs, $content = null, $render_slug ) {
wp_enqueue_script( 'graphina_apex_chart_script' );
wp_enqueue_style( 'graphina_apex_chart_style' );
wp_enqueue_style( 'graphina-public' );
echo "<pre/>";
$var = "<script>
var options = {
series: [{
name: 'Sales',
data: [4, 3, 10, 9, 29, 19, 22, 9, 12, 7, 19, 5, 13, 9, 17, 2, 7, 5]
}],
chart: {
type: 'bar',
height: 350
},
plotOptions: {
bar: {
borderRadius: 4,
horizontal: true,
}
},
dataLabels: {
enabled: false
},
xaxis: {
categories: ['South Korea', 'Canada', 'United Kingdom', 'Netherlands', 'Italy', 'France', 'Japan',
'United States', 'China', 'Germany'
],
}
};
var chart = new ApexCharts(document.querySelector('#charts'), options);
chart.render();
</script>" ;
$html = sprintf(
'<h1>%1$s</h1>
<p>%2$s</p>
<div id="charts"></div>',
$this->props['title'],
$this->props['content']
);
echo $html ;
echo $var ;
}
}
new GRDI_Barchart;
Child Modules::
<?php
class GRDI_BarchartChild extends ET_Builder_Module {
function init() {
$this->name = esc_html__( 'Bar Chart Items', 'et_builder' );
$this->plural = esc_html__( 'Bar Chart Items', 'et_builder' );
$this->slug = 'grdi_bar_chart_child';
$this->vb_support = 'on';
$this->type = 'child';
$this->child_title_var = 'title';
$this->no_render = true;
$this->settings_text = esc_html__( 'Bar Chart Settings', 'et_builder' );
$this->settings_modal_toggles = array(
'general' => array(
'toggles' => array(
'main_content' => et_builder_i18n( 'Text' ),
),
),
'advanced' => array(
'toggles' => array(
'icon' => esc_html__( 'Icon', 'et_builder' ),
'toggle_layout' => esc_html__( 'Toggle', 'et_builder' ),
'text' => array(
'title' => et_builder_i18n( 'Text' ),
'priority' => 49,
),
),
),
);
}
function get_fields() {
$fields = array(
'child_title' => array(
'label' => et_builder_i18n( 'Data Label' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Data Label', 'et_builder' ),
'toggle_slug' => 'main_content',
'dynamic_content' => 'text',
'hover' => 'tabs',
'mobile_options' => true,
),
'child_content' => array(
'label' => et_builder_i18n( 'Data Value' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Data Value', 'et_builder' ),
'toggle_slug' => 'main_content',
'dynamic_content' => 'text',
'hover' => 'tabs',
'mobile_options' => true,
),
);
return $fields;
}
function render($attrs, $content, $render_slug){
$output = sprintf(
'<h1>%1$s</h1>
<p>%2$s</p>',
$this->props['child_title'],
$this->props['child_content']
);
return $output;
}
}
if ( et_builder_should_load_all_module_data() ) {
new GRDI_BarchartChild();
}
I was having similar issue to Mikael, where the child's setting looked like:
Just in case anyone is having similar issue, i realised its because the child's module wasn't being loaded. Since i was using a custom extension, there was a file called loader.phpin my extension that was responsible for loading the module files and it was loading the parent module file but skipping the child because of the pesky if statement with preg_match.
$module_files = glob( __DIR__ . '/modules/**/*.php' );
foreach ( (array) $module_files as $module_file ) {
if ( $module_file && preg_match( "/\/modules\/\b([^\/]+)\/\\1\.php$/", $module_file ) ) {
require_once $module_file;
}
}
if you replace it with:
foreach ( (array) $module_files as $module_file ) {
// if ( $module_file && preg_match( "/\/modules\/\b([^\/]+)\/\\1\.php$/", $module_file ) ) {
require_once $module_file;
//}
}
then it worked for me :)
Really hope that saves someone the 3 hours of debugging i spent.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new to Drupal but have been given the task of creating a widget.
The module loads, fields are displayed, but when I create some content the form values are not being stored when the content is being saved.
.install file:
function cloudinary_field_schema($field) {
$columns = array(
'publicID' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'url' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'caption' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'alt' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'credit' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE)
);
return array(
'columns' => $columns,
'indexes' => array(),
);
}
.module file:
/**
* Implements hook_field_info().
* define the field type
*/
function cloudinary_field_info() {
return array(
'cloudinary' => array(
'label' => t('Cloudinary image selector'),
'description' => t('Search for images and select one for display.'),
'default_widget' => 'cloudinary_widget',
'default_formatter' => 'cloudinary_formatter',
'settings' => array(),
'instance_settings' => array(),
)
);
}
/**
* This is the dropdown options for widget
*/
function cloudinary_field_widget_info() {
return array(
'cloudinary_widget' => array(
'label' => t('Default'),
'field types' => array('cloudinary', 'text'),
'behaviours' => array('multiple values' => 'FIELD_BEHAVIOUR_DEFAULT'),
)
);
}
/**
*/
function cloudinary_field_widget_form(&$form, &$form_state, $field, $instance, $lang, $items, $delta, $element) {
$element += array(
'#type' => 'fieldset',
);
$item =& $items[$delta];
$element['field_cloudinary_publicID'] = array(
'#title' => t('Public ID'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_publicID']) ? $item['field_cloudinary_publicID'] : '',
);
$element['field_cloudinary_url'] = array(
'#title' => t('Url'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_url']) ? $item['field_cloudinary_url'] : '',
);
$element['field_cloudinary_caption'] = array(
'#title' => t('Caption'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_caption']) ? $item['field_cloudinary_caption'] : '',
);
$element['field_cloudinary_alt'] = array(
'#title' => t('Alt'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_alt']) ? $item['field_cloudinary_alt'] : '',
);
$element['field_cloudinary_credit'] = array(
'#title' => t('Credit'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_credit']) ? $item['field_cloudinary_credit'] : '',
);
return $element;
}
function cloudinary_field_is_empty($item, $field) {
$flag = FALSE;
foreach ($item as $key => $value) {
if(empty($key[$value])) {
$flag = TRUE;
}
}
return !$flag;
}
function cloudinary_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!isset($item['field_cloudinary_publicID']) ||
!isset($item['field_cloudinary_url']) ||
!isset($item['field_cloudinary_caption']) ||
!isset($item['field_cloudinary_alt']) ||
!isset($item['field_cloudinary_credit'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'cloudinary_fields_missing',
'message' => t('%title: Make sure all fields are completed. '.
'Make sure all fiends are entered.',
array('%title' => $instance['label'])
),
);
}
}
}
function cloudinary_field_widget_error($element, $error, $form, &$form_state) {
switch ($error['error']) {
case 'cloudinary_fields_missing':
form_error($element, $error['message']);
break;
}
}
function cloudinary_field_formatter_info() {
return array(
'cloudinary_formatter' => array(
'label' => t('Default'),
'field types' => array('cloudinary'),
),
);
}
function cloudinary_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$element[$delta] = cloudinary_format_field($item);
}
return $element;
}
function poutine_maker_format_field($item) {
$element = array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
);
$element['field_cloudinary_publicID'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Public ID'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_publicID'],
),
),
);
$element['field_cloudinary_url'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Url'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_url'],
),
),
);
$element['field_cloudinary_caption'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Caption'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_caption'],
),
),
);
$element['field_cloudinary_alt'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Alt'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_alt'],
),
),
);
$element['field_cloudinary_credit'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Credit'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_credit'],
),
),
);
return $element;
}
function cloudinary_format_canvas_field($item) {
drupal_add_js(drupal_get_path('module', 'cloudinary') . '/cloudinary.js');
}
You need to implement hook_field_schema in your .install file.
// Something like this
function cloudinary_field_schema($field) {
// $field['type']
return array(
'columns' => array(
'column_name' => array(
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
)
);
}
It was a logic problem in cloudinary_field_is_empty(). It was always returning false. All working fine now! Thanks for your help Zolyboy!