middleware('auth'); $this->_service = 'communication'; $this->_module = 'template'; $this->_viewname = 'template'; $this->_title = 'Template'; $this->_base_url = '/template'; } protected function get_list_fields() { return [ 'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']], 'name' => ['title' => 'Template Name', 'type' => 'text'], 'type' => ['title' => 'Type', 'type' => 'text'], 'template_code' => ['title' => 'Template Code', 'type' => 'text'], 'status' => ['title' => 'Status', 'type' => 'select'] ]; } protected function get_form_fields($type, $values) { return [ 'name' => ['title' => 'Template Name', 'type' => 'text', 'required' => true], 'type' => ['title' => 'Type', 'type' => 'select', 'required' => true, 'values' => ['whatsapp' => 'Whatsapp', 'whatsapp_interakt' => 'Whatsapp Interakt', 'sms' => 'SMS']], 'template_code' => ['title' => 'Template Code', 'type' => 'text', 'required' => true], 'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']], 'header_type' => ['title' => 'Header Type', 'type' => 'select', 'required' => true, 'values' => ['none' => 'None', 'text' => 'Text', 'video' => 'Video', 'image' => 'Image', 'document' => 'Document'] ], 'header_text' => ['title' => 'Header Text (if header type is text)', 'type' => 'text', 'fullwidth' => true], 'header_params' => ['title' => 'Header Params', 'type' => 'textarea', 'required' => true, 'fullwidth' => true], 'template_body' => ['title' => 'Template Body', 'type' => 'textarea', 'required' => true, 'fullwidth' => true], 'body_params' => ['title' => 'Body Params', 'type' => 'textarea', 'required' => true, 'fullwidth' => true], 'footer_text' => ['title' => 'Footer Text', 'type' => 'text'], // 'button_params' => ['title' => 'Button Params', 'type' => 'textarea', 'required' => true], 'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']], 'buttons' => ['title' => 'Options', 'type' => 'mapping', 'fullwidth' => true ], //'image' => ['title' => 'Template Image', 'type' => 'image', 'required' => true] ]; } protected function _beforesave($type, $request) { $data = $request->except('_token'); $data['header_param_count'] = substr_count($data['header_text'],"{{"); $data['body_param_count'] = substr_count($data['template_body'],"{{"); $data['header_params'] = json_decode($data['header_params']); $data['body_params'] = json_decode($data['body_params']); if(isset($data['button']) && is_array($data['button']) ) { $buttons = []; foreach($data['button']['type'] as $i => $type) { $buttons[] = ['type' => $type, 'index' => $data['button']['index'][$i], 'title' => $data['button']['title'][$i] ]; } $data['button'] = $buttons; } //echo '
'; print_r($data); exit;
        return $data;
    }

    protected function _beforeform($type, $values) {
        if ($type == 'edit') {
            $values->body_params = json_encode($values->body_params);
            //     $values->button_params = json_encode($values->button_params);
            $values->header_params = json_encode($values->header_params);
        }
        //echo '
'; print_r($values); exit;
        return $values;
    }
}