Hello,
After upgrading to Drupal 10 i got an Error in the following function:
Can you please help me ?
public function saveappointmentuser(){
@$user_current = \Drupal::currentUser()->id();
@$user_info_current = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$userID_current = $user_info_current->uid->value;
$query = \Drupal::entityQuery('node');
$query->accessCheck(TRUE);
$query->condition('type', array('calendar_main'), 'IN');
$query->condition('status', 1);
$query->condition('uid', intval($_POST['owner']));
$query->sort('nid', 'DESC');
$entity_ids = $query->execute();
$entity_ids = reset($entity_ids);
if(isset($_POST['mykalendarpage']) && intval($_POST['mykalendarpage']) == 1){
$name_appointment = 'Termin '.$this->counterappointments($entity_ids);
}elseif(isset($_POST['mycreatepage']) && intval($_POST['mycreatepage']) == 1){
$name_appointment = 'Termin '.$this->counterappointments($entity_ids);
}else{
$name_appointment = 'Buchung '.$this->counterappointments($entity_ids);
}
$appointment_data = array();
$appointment_data['type'] = 'calendar_entries';
$appointment_data['uid'] = intval($userID_current);
$appointment_data['title'] = $name_appointment;
$appointment_data['body'] = $_POST['text'];
$appointment_data['field_calendar_selected_date'] = $_POST['date_format'];
$appointment_data['field_calendar_selected_hour'] = $_POST['hour'];
$appointment_data['field_calendar_id_assoc'] = intval($entity_ids);
$appointment_data['field_calendar_entry_key'] = $_POST['date_format'].'>'.$_POST['hour'].'>'.$entity_ids;
$appointment_data['field_calendar_entry_type'] = $_POST['type'];
$appointment_data['status'] = 1;
#$created_appointment = entity_create('node', $appointment_data);
#$created_appointment->save();
$created_appointment = \Drupal::entityTypeManager()->getStorage('node')->create($appointment_data);
$created_appointment->save();
$appointment_id = $created_appointment->uid->value;
$load_calendar = Node::load(intval($entity_ids));
$array_apppintments = array();
foreach ($load_calendar->get('field_calendar_entry_assoc')->getValue() as $key => $value) {
$appointmentload = Node::load(intval($value['target_id']));
if(!is_object($appointmentload)){
}else{
$array_apppintments[] = $value['target_id'];
}
}
$load_calendar->field_calendar_entry_assoc = $array_apppintments;
$load_calendar->save();
$load_calendar = Node::load(intval($entity_ids));
$appointment_list_data = $load_calendar->get('field_calendar_entry_assoc')->getValue();
if (empty($appointment_list_data)) {
$load_calendar->field_calendar_entry_assoc[0] = $appointment_id;
$load_calendar->save();
} elseif(!empty($appointment_list_data)) {
$appointment_count = count($appointment_list_data);
$load_calendar->field_calendar_entry_assoc[$appointment_count] = $appointment_id;
$load_calendar->save();
}
if(intval($userID_current) != intval($_POST['owner'])){
//email send
$custom_mails = new CemailController();
$current_user = \Drupal\user\Entity\User::load($userID_current);
$owner_kalendar = \Drupal\user\Entity\User::load(intval($_POST['owner']));
$custom_mails->userbookedmail($current_user);
$custom_mails->teacherbookedmail($owner_kalendar);
//email send
//create chat
//chat validation
$query = \Drupal::entityQuery('node');
$query->accessCheck(TRUE);
$query->condition('type', array('chat_content'), 'IN');
$query->condition('status', 1);
$query->condition('field_chat_user_from', array($userID_current),"IN");
$query->condition('field_chat_user_to', array($_POST['owner']),"IN");
$query->sort('nid', 'DESC');
$entity_ids = $query->execute();
$query_second = \Drupal::entityQuery('node');
$query_second->accessCheck(TRUE);
$query_second->condition('type', array('chat_content'), 'IN');
$query_second->condition('status', 1);
$query_second->condition('field_chat_user_from', array($_POST['owner']),"IN");
$query_second->condition('field_chat_user_to', array($userID_current),"IN");
$query_second->sort('nid', 'DESC');
$entity_ids_second = $query_second->execute();
//chat validation
if(!empty($entity_ids)){
//create message
$subject = 'User Comment ID '.htmlspecialchars($userID_current, ENT_QUOTES, 'UTF-8');
$chatmessage = '<p>'.htmlspecialchars($_POST['text'], ENT_QUOTES, 'UTF-8').'</p>';
$values = [
'entity_type' => 'node',
'entity_id' => end($entity_ids),
'field_name' => 'comment',
'uid' => $userID_current,
'comment_type' => 'comment',
'subject' => $subject,
'comment_body' => strip_tags($chatmessage),
'status' => 1
];
$comment = Comment::create($values);
$comment->save();
//create message
/*echo $GLOBALS['base_url'].'/partner/profile/chat/'.$userID_current.'#'.end($entity_ids);
die();*/
$custom_url = $GLOBALS['base_url'].'/buchungerfolgreich';
#drupal_set_message(t("Deine Buchung wurde erfolgreich durchgeführt."), 'status');
echo $custom_url;
}elseif(!empty($entity_ids_second)){
//create message
$subject = 'User Comment ID '.htmlspecialchars($userID_current, ENT_QUOTES, 'UTF-8');
$chatmessage = '<p>'.htmlspecialchars($_POST['text'], ENT_QUOTES, 'UTF-8').'</p>';
$values = [
'entity_type' => 'node',
'entity_id' => end($entity_ids_second),
'field_name' => 'comment',
'uid' => $userID_current,
'comment_type' => 'comment',
'subject' => $subject,
'comment_body' => strip_tags($chatmessage),
'status' => 1
];
$comment = Comment::create($values);
$comment->save();
//create message
/* echo $GLOBALS['base_url'].'/partner/profile/chat/'.$userID_current.'#'.end($entity_ids_second);
die();*/
$custom_url = $GLOBALS['base_url'].'/buchungerfolgreich';
#drupal_set_message(t("Deine Buchung wurde erfolgreich durchgeführt."), 'status');
echo $custom_url;
}else{
$chatcreation = array();
$chatcreation['type'] = 'chat_content';
$chatcreation['uid'] = intval($userID_current);
$chatcreation['title'] = "Chat between: ID-".$userID_current." and ID-".$_POST['owner'];
$chatcreation['body'] = "Chat between: ID-".$userID_current." and ID-".$_POST['owner'];
$chatcreation['field_chat_user_from'] = $userID_current;
$chatcreation['field_chat_user_to'] = $_POST['owner'];
$chatcreation['status'] = 1;
$created_chat = entity_create('node', $chatcreation);
$created_chat->save();
$chat_id = $created_chat->nid->value;
//create message
$subject = 'User Comment ID '.htmlspecialchars($userID_current, ENT_QUOTES, 'UTF-8');
$chatmessage = '<p>'.htmlspecialchars($_POST['text'], ENT_QUOTES, 'UTF-8').'</p>';
$values = [
'entity_type' => 'node',
'entity_id' => $chat_id,
'field_name' => 'comment',
'uid' => $userID_current,
'comment_type' => 'comment',
'subject' => $subject,
'comment_body' => strip_tags($chatmessage),
'status' => 1
];
$comment = Comment::create($values);
$comment->save();
//create message
}
//create chat
$custom_url = $GLOBALS['base_url'].'/buchungerfolgreich';
#drupal_set_message(t("Deine Buchung wurde erfolgreich durchgeführt."), 'status');
echo $custom_url;
}else{
echo 'ok';
}
die();
}
Comments
Well, you didn't tell us what
Well, you didn't tell us what the error was. But that is just a bunch of PHP code, not really Drupal code, other than calling a couple of Drupal API functions in there. What is this function supposed to do? Is it part of a controller? A service? Something else? What is the error you are getting, and which line is causing it?
Contact me to contract me for D7 -> D10/11 migrations.
Hello, thx for reply. its
Hello, thx for reply. its for booking a course, the course is booked it workes but the site stays there.
how can i insert images here ? ☺️
What should i post here to
What should i post here to get help?
jquery.min.js?v=3.7.0:2
jquery.min.js?v=3.7.0:2 POST https://kalendra.net/saveappointmentuser 500
send @ jquery.min.js?v=3.7.0:2
ajax @ jquery.min.js?v=3.7.0:2
(anonym) @ calendarcustom.js?v=1.x:363
dispatch @ jquery.min.js?v=3.7.0:2
v.handle @ jquery.min.js?v=3.7.0:2
jquery.min.js?v=3.7.0:2
e.preventDefault();
jQuery.ajax({
url: '/saveappointmentuser',
type: 'POST',
data: {
date: jQuery('#custom_calendar_appointment form input[name="date"]').val(),
date_format: new_date_format,
hour: jQuery('#custom_calendar_appointment form input[name="hour"]').val(),
text: jQuery('#custom_calendar_appointment form textarea').val(),
owner: jQuery('#owner_id_data').val(),
type: jQuery('#custom_calendar_appointment form input[name="type"]').val(),
},
success : function( data ) {
window.loc
To get help, post the error message you got
Seeing a lot of PHP and JavaScript without any context or explantion is probably not going to be enough to make anyone here able to help you. Posting the error mesge you got would be a start, but maybe not enough if the error message is not directly related to Drupal. This is not a free general debugging service.
It is hard to embed an image in a forum post. Instead, put it somewhere else and post a link to it.
- gisle