Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
|
@ -3,14 +3,43 @@
|
|||
/**
|
||||
* @file
|
||||
* Webform module translation hooks.
|
||||
*
|
||||
* @see webform_preprocess_table()
|
||||
*/
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\webform\Entity\Webform;
|
||||
use Drupal\webform\Utility\WebformYaml;
|
||||
use Drupal\Core\Serialization\Yaml;
|
||||
use Drupal\webform\Utility\WebformElementHelper;
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function webform_form_locale_translate_edit_form_alter(&$form, FormStateInterface $form_state) {
|
||||
// Don't allow YAML to be validated using locale string translation.
|
||||
foreach (Element::children($form['strings']) as $key) {
|
||||
$element =& $form['strings'][$key];
|
||||
if ($element['original']
|
||||
&& !empty($element['original']['#plain_text'])
|
||||
&& preg_match("/'#[^']+':/", $element['original']['#plain_text'])
|
||||
&& WebformYaml::isValid($element['original']['#plain_text'])) {
|
||||
$element['original'] = [
|
||||
'#theme' => 'webform_codemirror',
|
||||
'#code' => $element['original']['#plain_text'],
|
||||
'#type' => 'yaml',
|
||||
];
|
||||
$element['translations'] = [
|
||||
'#type' => 'webform_message',
|
||||
'#message_type' => 'warning',
|
||||
'#message_message' => t("Webforms can only be translated via the Webform's (Configuration) Translate tab."),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
|
|
@ -33,8 +62,8 @@ function webform_form_config_translation_add_form_alter(&$form, FormStateInterfa
|
|||
$translation_langcode = $form_state->get('config_translation_language')->getId();;
|
||||
$source_elements = $translation_manager->getSourceElements($webform);
|
||||
$translation_elements = $translation_manager->getTranslationElements($webform, $translation_langcode);
|
||||
$source_value = trim(Yaml::encode($source_elements));
|
||||
$translation_value = trim(Yaml::encode($translation_elements));
|
||||
$source_value = WebformYaml::encode($source_elements);
|
||||
$translation_value = WebformYaml::encode($translation_elements);
|
||||
|
||||
_webform_form_config_translate_add_form_alter_yaml_element($config_element['elements'], $source_value, $translation_value);
|
||||
|
||||
|
|
@ -52,6 +81,10 @@ function webform_form_config_translation_add_form_alter(&$form, FormStateInterfa
|
|||
* Validate callback; Validates and cleanups webform elements.
|
||||
*/
|
||||
function _webform_form_config_translate_add_form_validate(&$form, FormStateInterface $form_state) {
|
||||
if ($form_state::hasAnyErrors()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = $form_state->getValues();
|
||||
|
||||
$config_name = $form_state->get('webform_config_name');
|
||||
|
|
@ -129,8 +162,77 @@ function _webform_form_config_translate_add_form_alter_yaml_element(array &$elem
|
|||
$element['translation']['#type'] = 'webform_codemirror';
|
||||
$element['translation']['#mode'] = 'yaml';
|
||||
if ($translation_value) {
|
||||
$element['translation']['#default_value'] = $translation_value;
|
||||
$element['translation']['#default_value'] = WebformYaml::tidy($translation_value);
|
||||
}
|
||||
$element['translation']['#default_value'] = trim($element['translation']['#default_value']);
|
||||
$element['#attached']['library'][] = 'webform/webform.admin.translation';
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Lingotek integration.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Implements hook_lingotek_config_entity_document_upload().
|
||||
*/
|
||||
function webform_lingotek_config_entity_document_upload(array &$source_data, ConfigEntityInterface &$entity, &$url) {
|
||||
switch ($entity->getEntityTypeId()) {
|
||||
case 'webform';
|
||||
/** @var \Drupal\webform\WebformTranslationManagerInterface $translation_manager */
|
||||
$translation_manager = \Drupal::service('webform.translation_manager');
|
||||
|
||||
// Replace elements with just the translatable properties
|
||||
// (i.e. #title, #description, #options, etc…) so that Lingotek's
|
||||
// translation services can correctly translate each element.
|
||||
$translation_elements = $translation_manager->getTranslationElements($entity, $entity->language()->getId());
|
||||
$source_data['elements'] = $translation_elements;
|
||||
|
||||
// Encode all [tokens].
|
||||
$yaml = Yaml::encode($source_data);
|
||||
$yaml = preg_replace_callback(
|
||||
'/\[([a-z][^]]+)\]/',
|
||||
function ($matches) {
|
||||
return '[***' . base64_encode($matches[1]) . '***]';
|
||||
},
|
||||
$yaml
|
||||
);
|
||||
$source_data = Yaml::decode($yaml);
|
||||
break;
|
||||
|
||||
case 'webform_options';
|
||||
// Convert options YAML string to an associative array.
|
||||
$source_data['options'] = Yaml::decode($source_data['options']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_lingotek_config_entity_translation_presave().
|
||||
*/
|
||||
function webform_lingotek_config_entity_translation_presave(ConfigEntityInterface &$translation, $langcode, &$data) {
|
||||
switch ($translation->getEntityTypeId()) {
|
||||
case 'webform';
|
||||
// Decode all [tokens].
|
||||
$yaml = Yaml::encode($data);
|
||||
$yaml = preg_replace_callback(
|
||||
'/\[\*\*\*([^]]+)\*\*\*\]/',
|
||||
function ($matches) {
|
||||
return '[' . base64_decode($matches[1]) . ']';
|
||||
},
|
||||
$yaml
|
||||
);
|
||||
$data = Yaml::decode($yaml);
|
||||
|
||||
/** @var \Drupal\webform\WebformInterface $translation */
|
||||
$translation->setElements($data['elements']);
|
||||
$data['elements'] = Yaml::encode($data['elements']);
|
||||
break;
|
||||
|
||||
case 'webform_options';
|
||||
/** @var \Drupal\webform\WebformOptionsInterface $translation */
|
||||
// Convert options associative array back to YAML string.
|
||||
$translation->setOptions($data['options']);
|
||||
$data['options'] = Yaml::encode($data['options']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue