/** * Updates an exiting Trapp entry with a new revision. * * @return void. */ public function updateTrappRevision() { $service = new ServiceTranslation(); $service = $service->getById($this->trappId); if (!empty($_POST['trapp_deadline'])) { $deadline = esc_attr($_POST['trapp_deadline']); update_post_meta($this->postId, self::TRAPP_META_DEADLINE, $deadline); $deadline = new DateTime($deadline); $service->setDeadline($deadline); } if (!empty($_POST['trapp_comment'])) { $service->setComment(esc_attr($_POST['trapp_comment'])); } if (isset($_POST['trapp_start'])) { $service->setState('state-missing'); } $newFields = []; $arrayIgnore = []; $serviceFields = $service->getFields(); $fieldGroups = Mappings::getFields(get_post_type($this->post)); foreach ($fieldGroups as $fieldGroup) { foreach ($fieldGroup['fields'] as $field) { $field['group'] = $fieldGroup['title']; foreach ($serviceFields as $fieldId => $serviceField) { if ($field['label'] == $serviceField->getLabel()) { $value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']); if (!empty($value)) { $serviceFields[$fieldId]->setValue($value); } continue 2; } elseif ($field['type'] == 'post_meta_array') { $value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']); $label = $serviceField->getLabel(); if (is_array($value) && array_key_exists($label, $value)) { $serviceFields[$fieldId]->setValue($value[$label]); $arrayIgnore[] = $label; } } } $newFields[] = $field; } } $service->setFields($serviceFields); if (!empty($newFields)) { foreach ($newFields as $newField) { $field = Mappings::translationField($newField, $this->postId, $this->post, $arrayIgnore); if (!empty($field)) { if (is_array($field)) { foreach ($field as $singleField) { $service->addField($singleField); } } else { $service->addField($field); } } } } $post_translations = []; foreach ($service->getRelatedTranslations() as $serviceTranslation) { if ($serviceTranslation->isOriginal()) { continue; } $post_translations[] = $serviceTranslation->getLocale(); } if (!empty($_POST['trapp_tr_lang'])) { foreach ($_POST['trapp_tr_lang'] as $trapp_lang => $active) { $trapp_lang = esc_attr($trapp_lang); $trapp_lang = PLL()->model->get_language($trapp_lang); if (!$trapp_lang) { continue; } $locale = $this->filterLocale($trapp_lang->locale); if (in_array($locale, $post_translations)) { continue; } $service->addTranslatation($locale); } } $row = $service->update(); do_action('bp_trapp_after_save_post', $row, $this->post); }