composer update
This commit is contained in:
parent
f6abc3dce2
commit
71dfaca858
1753 changed files with 45274 additions and 14619 deletions
|
@ -7,9 +7,31 @@
|
|||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Datetime\DateHelper;
|
||||
|
||||
/**
|
||||
* Callback for custom datetime datepicker.
|
||||
* Callback for removing abbreviation from datelist.
|
||||
*
|
||||
* @param array $element
|
||||
* The element.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The form state.
|
||||
* @param \Drupal\Core\Datetime\DrupalDateTime|null $date
|
||||
* The date value.
|
||||
*
|
||||
* @see \Drupal\Core\Datetime\Element\Datelist::processDatelist
|
||||
*/
|
||||
function _webform_datelist_date_date_callback(array &$element, FormStateInterface $form_state, $date) {
|
||||
$no_abbreviate = (isset($element['#date_abbreviate']) && $element['#date_abbreviate'] === FALSE);
|
||||
if ($no_abbreviate && isset($element['month']) && isset($element['month']['#options'])) {
|
||||
// Load translated date part labels from the appropriate calendar plugin.
|
||||
$date_helper = new DateHelper();
|
||||
$element['month']['#options'] = $date_helper->monthNames($element['#required']);;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for custom datetime date element.
|
||||
*
|
||||
* @param array $element
|
||||
* The element.
|
||||
|
@ -20,19 +42,27 @@ use Drupal\Core\Datetime\DrupalDateTime;
|
|||
*
|
||||
* @see \Drupal\webform\Plugin\WebformElement\DateTime::prepare
|
||||
*/
|
||||
function _webform_datetime_datepicker(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
|
||||
// Convert #type from datepicker to textfield.
|
||||
if (isset($element['#date_date_element']) && $element['#date_date_element'] === 'datepicker') {
|
||||
$element['date']['#type'] = 'textfield';
|
||||
function _webform_datetime_date(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
|
||||
// Make sure the date element is being displayed.
|
||||
if (!isset($element['date'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Must manually set 'data-drupal-date-format' to trigger date picker.
|
||||
// @see \Drupal\Core\Render\Element\Date::processDate
|
||||
$element['date']['#attributes']['data-drupal-date-format'] = [$element['date']['#date_date_format']];
|
||||
$type = (isset($element['#date_date_element'])) ? $element['#date_date_element'] : 'date';
|
||||
switch ($type) {
|
||||
case 'datepicker':
|
||||
// Convert #type from datepicker to textfield.
|
||||
$element['date']['#type'] = 'textfield';
|
||||
|
||||
// Must manually set 'data-drupal-date-format' to trigger date picker.
|
||||
// @see \Drupal\Core\Render\Element\Date::processDate
|
||||
$element['date']['#attributes']['data-drupal-date-format'] = [$element['date']['#date_date_format']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for custom datetime timepicker.
|
||||
* Callback for custom datetime time element.
|
||||
*
|
||||
* @param array $element
|
||||
* The element.
|
||||
|
@ -43,16 +73,58 @@ function _webform_datetime_datepicker(array &$element, FormStateInterface $form_
|
|||
*
|
||||
* @see \Drupal\webform\Plugin\WebformElement\DateTime::prepare
|
||||
*/
|
||||
function _webform_datetime_timepicker(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
|
||||
// Convert #type from timepicker to textfield.
|
||||
if (isset($element['#date_time_element']) && $element['#date_time_element'] === 'timepicker') {
|
||||
$element['time']['#type'] = 'textfield';
|
||||
function _webform_datetime_time(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
|
||||
// Make sure the time element is being displayed.
|
||||
if (!isset($element['time'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Must manually set 'data-webform-time-format' to trigger time picker.
|
||||
// @see \Drupal\webform\Element\WebformTime::processWebformTime
|
||||
$element['time']['#attributes']['data-webform-time-format'] = [$element['#date_time_format']];
|
||||
// Apply time specific min/max to the element.
|
||||
foreach (['min', 'max'] as $property) {
|
||||
if (!empty($element["#date_time_$property"])) {
|
||||
$value = $element["#date_time_$property"];
|
||||
}
|
||||
elseif (!empty($element["#date_$property"])) {
|
||||
$value = date('H:i:s', strtotime($element["#date_$property"]));
|
||||
}
|
||||
else {
|
||||
$value = NULL;
|
||||
}
|
||||
if ($value) {
|
||||
$element['time']["#$property"] = $value;
|
||||
$element['time']['#attributes'][$property] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Attached custom timepicker library.
|
||||
$element['time']['#attached']['library'][] = 'webform/webform.element.time';
|
||||
// Apply time step and format to the element.
|
||||
if (!empty($element['#date_time_step'])) {
|
||||
$element['time']['#step'] = $element['#date_time_step'];
|
||||
$element['time']['#attributes']['step'] = $element['#date_time_step'];
|
||||
}
|
||||
if (!empty($element['#date_time_format'])) {
|
||||
$element['time']['#time_format'] = $element['#date_time_format'];
|
||||
}
|
||||
|
||||
// Remove extra attributes for date element.
|
||||
unset(
|
||||
$element['time']['#attributes']['data-min-year'],
|
||||
$element['time']['#attributes']['data-max-year']
|
||||
);
|
||||
|
||||
$type = (isset($element['#date_time_element'])) ? $element['#date_time_element'] : 'time';
|
||||
|
||||
switch ($type) {
|
||||
case 'timepicker':
|
||||
$element['time']['#type'] = 'webform_time';
|
||||
$element['time']['#timepicker'] = TRUE;
|
||||
break;
|
||||
|
||||
case 'time':
|
||||
$element['time']['#type'] = 'webform_time';
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
$element['time']['#element_validate'][] = ['\Drupal\webform\Element\WebformTime', 'validateWebformTime'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ use Drupal\webform\Plugin\WebformHandler\EmailWebformHandler;
|
|||
use Drupal\webform\WebformInterface;
|
||||
use Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler;
|
||||
use Drupal\webform\Utility\WebformArrayHelper;
|
||||
use Drupal\webform\Utility\WebformFormHelper;
|
||||
use Drupal\webform\Utility\WebformOptionsHelper;
|
||||
use Drupal\webform\Utility\WebformReflectionHelper;
|
||||
use Drupal\webform\Utility\WebformYaml;
|
||||
|
@ -2712,6 +2713,10 @@ function webform_update_8146() {
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc23 - October 20, 2018.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Issue #3006468: Hide empty fields on on submission page.
|
||||
*/
|
||||
|
@ -2743,9 +2748,200 @@ function webform_update_8149() {
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc24 - October 22, 2018.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Issue #2980032: SUBMISSION BEHAVIORS: Allow edit the previous submission.
|
||||
*/
|
||||
function webform_update_8150() {
|
||||
_webform_update_webform_settings();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc25 - November 5, 2018 (No update required).
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc26 - November 5, 2018 (No update required).
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc27 - November 28, 2018.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Issue #3013767: Computed twig element is not working on multi-step form.
|
||||
*/
|
||||
function webform_update_8151() {
|
||||
$config_factory = \Drupal::configFactory();
|
||||
foreach ($config_factory->listAll('webform.webform.') as $webform_config_name) {
|
||||
$webform_config = $config_factory->getEditable($webform_config_name);
|
||||
$elements = $webform_config->get('elements');
|
||||
|
||||
// Try to decode elements.
|
||||
try {
|
||||
$elements = Yaml::decode($elements);
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make sure elements is an array.
|
||||
if (!is_array($elements)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_computed_element = FALSE;
|
||||
$flattened_elements =& WebformFormHelper::flattenElements($elements);
|
||||
foreach ($flattened_elements as &$element) {
|
||||
// Convert #value property to #template property.
|
||||
// @see \Drupal\webform\Entity\Webform::initElementsRecursive
|
||||
if (isset($element['#type']) && strpos($element['#type'], 'webform_computed_') === 0) {
|
||||
$has_computed_element = TRUE;
|
||||
if (isset($element['#value']) && !isset($element['#template'])) {
|
||||
$element['#template'] = $element['#value'];
|
||||
unset($element['#value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($has_computed_element) {
|
||||
$webform_config->set('elements', Yaml::encode($elements));
|
||||
$webform_config->save(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #3014933: Webform paths not being removed when a webform is deleted.
|
||||
*/
|
||||
function webform_update_8153() {
|
||||
// Load all webforms to improve performance.
|
||||
$webform = Webform::loadMultiple();
|
||||
|
||||
$database = \Drupal::database();
|
||||
$select = $database->select('url_alias', 'u');
|
||||
$select->fields('u', ['pid', 'source', 'alias', 'langcode']);
|
||||
$select->condition('source', '/webform/%', 'LIKE');
|
||||
$result = $select->execute();
|
||||
while ($record = $result->fetchAssoc()) {
|
||||
if (preg_match('#^/webform/([^/]+)/(?:drafts|submissions)$#', $record['source'], $match)) {
|
||||
// Check if the webform still exists.
|
||||
$webform_id = $match[1];
|
||||
if (!isset($webform[$webform_id])) {
|
||||
// Delete the broken URL alias.
|
||||
$database->delete('url_alias')
|
||||
->condition('pid', $record['pid'])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #3015990: Option not to store the IP address for logged-in users.
|
||||
*/
|
||||
function webform_update_8154() {
|
||||
_webform_update_webform_settings();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Webform-8.x-5.0-rc28 - TBD.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Issue #3017679: 2 different validation range modes for date/time field.
|
||||
*/
|
||||
function webform_update_8155() {
|
||||
$config_factory = \Drupal::configFactory();
|
||||
foreach ($config_factory->listAll('webform.webform.') as $webform_config_name) {
|
||||
$webform_config = $config_factory->getEditable($webform_config_name);
|
||||
$elements = $webform_config->get('elements');
|
||||
|
||||
// Try to decode elements.
|
||||
try {
|
||||
$elements = Yaml::decode($elements);
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make sure elements is an array.
|
||||
if (!is_array($elements)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_date_element = FALSE;
|
||||
$flattened_elements =& WebformFormHelper::flattenElements($elements);
|
||||
foreach ($flattened_elements as &$element) {
|
||||
// Convert #min/max property to #date_date_(min|max) property.
|
||||
// @see \Drupal\webform\Entity\Webform::initElementsRecursive
|
||||
if (isset($element['#type']) && in_array($element['#type'], ['date', 'datetime', 'datelist'])) {
|
||||
$has_date_element = TRUE;
|
||||
if (isset($element['#min']) && !isset($element['#date_date_min'])) {
|
||||
$element['#date_date_min'] = $element['#min'];
|
||||
unset($element['#min']);
|
||||
}
|
||||
if (isset($element['#max']) && !isset($element['#date_date_max'])) {
|
||||
$element['#date_date_max'] = $element['#max'];
|
||||
unset($element['#max']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($has_date_element) {
|
||||
$webform_config->set('elements', Yaml::encode($elements));
|
||||
$webform_config->save(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #3015180: Add 'webform_submission_log' submodule.
|
||||
*/
|
||||
function webform_update_8156() {
|
||||
$enable = \Drupal::config('webform.settings')->get('settings.default_submission_log');
|
||||
if (!$enable) {
|
||||
$query = \Drupal::entityQuery('webform')
|
||||
->condition('settings.submission_log', TRUE)
|
||||
->count();
|
||||
$enable = $query->execute() > 0;
|
||||
}
|
||||
|
||||
if ($enable) {
|
||||
try {
|
||||
\Drupal::service('module_installer')->install(['webform_submission_log']);
|
||||
}
|
||||
catch (\Drupal\Core\Database\SchemaObjectExistsException $exception) {
|
||||
// This is actually expected. The table {webform_submission_log} would exist
|
||||
// from webform submission entity schema.
|
||||
}
|
||||
|
||||
// Because MySQL does not allow default value on blob/text column types and
|
||||
// we want to add a not null blob column to a table that is likely to have
|
||||
// existing rows, we are doing it in such a 3-step fashion.
|
||||
\Drupal::database()->schema()->addField('webform_submission_log', 'variables', [
|
||||
'type' => 'blob',
|
||||
'size' => 'big',
|
||||
'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
|
||||
]);
|
||||
|
||||
\Drupal::database()->update('webform_submission_log')->fields([
|
||||
'variables' => serialize([]),
|
||||
])->execute();
|
||||
|
||||
\Drupal::database()->schema()->changeField('webform_submission_log', 'variables', 'variables', [
|
||||
'type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue #3022398: Possible modification to update hook and/or documentation.
|
||||
*/
|
||||
function webform_update_8157() {
|
||||
_webform_update_webform_submission_storage_schema();
|
||||
}
|
||||
|
|
|
@ -9,24 +9,37 @@
|
|||
* Implements hook_library_info_alter().
|
||||
*/
|
||||
function webform_library_info_alter(&$libraries, $extension) {
|
||||
$webform_libraries_modules = \Drupal::moduleHandler()->getImplementations('webform_libraries_info');
|
||||
$webform_libraries_modules[] = 'webform';
|
||||
|
||||
// Only alter modules that declare webform libraries.
|
||||
// @see hook_webform_libraries_info()
|
||||
$webform_libraries_modules = \Drupal::moduleHandler()->getImplementations('webform_libraries_info');
|
||||
$webform_libraries_modules[] = 'webform';
|
||||
if (!in_array($extension, $webform_libraries_modules)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent duplicate instances of the chosen plugin and use
|
||||
// the chosen_lib.module's as the dependency.
|
||||
if (isset($libraries['webform.element.chosen']) && \Drupal::moduleHandler()->moduleExists('chosen_lib')) {
|
||||
$dependencies =& $libraries['webform.element.chosen']['dependencies'];
|
||||
foreach ($dependencies as $index => $dependency) {
|
||||
if ($dependency === 'webform/libraries.jquery.chosen') {
|
||||
$dependencies[$index] = 'chosen_lib/chosen';
|
||||
$dependencies[] = 'chosen_lib/chosen.css';
|
||||
break;
|
||||
// If chosen_lib.module is installed, then update the dependency.
|
||||
if (\Drupal::moduleHandler()->moduleExists('chosen_lib')) {
|
||||
if (isset($libraries['webform.element.chosen'])) {
|
||||
$dependencies =& $libraries['webform.element.chosen']['dependencies'];
|
||||
foreach ($dependencies as $index => $dependency) {
|
||||
if ($dependency === 'webform/libraries.jquery.chosen') {
|
||||
$dependencies[$index] = 'chosen_lib/chosen';
|
||||
$dependencies[] = 'chosen_lib/chosen.css';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If select2.module is installed, then update the dependency.
|
||||
if (\Drupal::moduleHandler()->moduleExists('select2')) {
|
||||
if (isset($libraries['webform.element.select2'])) {
|
||||
$dependencies =& $libraries['webform.element.select2']['dependencies'];
|
||||
foreach ($dependencies as $index => $dependency) {
|
||||
if ($dependency === 'webform/libraries.jquery.select2') {
|
||||
$dependencies[$index] = 'select2/select2';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +56,11 @@ function webform_library_info_alter(&$libraries, $extension) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Skip libraries installed by other modules.
|
||||
if (isset($library['module'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($library['dependencies'])) {
|
||||
// Remove excluded libraries from dependencies.
|
||||
foreach ($library['dependencies'] as $dependency_index => $dependency_name) {
|
||||
|
|
|
@ -73,3 +73,16 @@ function webform_webform_options_languages_alter(array &$options, array $element
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_webform_options_WEBFORM_OPTIONS_ID_alter().
|
||||
*/
|
||||
function webform_webform_options_translations_alter(array &$options, array $element = []) {
|
||||
if (empty($options)) {
|
||||
$languages = \Drupal::languageManager()->getLanguages();
|
||||
$options = [];
|
||||
foreach ($languages as $language) {
|
||||
$options[$language->getId()] = $language->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,13 +289,16 @@ function webform_preprocess_table(&$variables) {
|
|||
foreach ($variables['rows'] as &$row) {
|
||||
// Check first cell.
|
||||
if (!isset($row['cells'][0]['content'])
|
||||
|| !is_array($row['cells'][0]['content'])
|
||||
|| !isset($row['cells'][0]['content']['#markup'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check last cell edit link.
|
||||
if (!isset($row['cells'][1]['content'])
|
||||
|| !is_array($row['cells'][1]['content'])
|
||||
|| !isset($row['cells'][1]['content']['#links'])
|
||||
|| !is_array($row['cells'][1]['content']['#links'])
|
||||
|| !isset($row['cells'][1]['content']['#links']['edit'])) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -283,6 +283,11 @@ function template_preprocess_webform_submission_navigation(array &$variables) {
|
|||
*/
|
||||
function template_preprocess_webform_submission(array &$variables) {
|
||||
$variables['view_mode'] = $variables['elements']['#view_mode'];
|
||||
|
||||
$variables['navigation'] = $variables['elements']['navigation'];
|
||||
$variables['information'] = $variables['elements']['information'];
|
||||
$variables['submission'] = $variables['elements']['submission'];
|
||||
|
||||
$variables['webform_submission'] = $variables['elements']['#webform_submission'];
|
||||
if ($variables['webform_submission'] instanceof WebformSubmissionInterface) {
|
||||
$variables['webform'] = $variables['webform_submission']->getWebform();
|
||||
|
@ -413,19 +418,21 @@ function template_preprocess_webform_element_base_html(array &$variables) {
|
|||
if (empty($variables['options']['email'])) {
|
||||
$type = $element['#type'];
|
||||
|
||||
$attributes = (isset($element['#format_attributes'])) ? $element['#format_attributes'] : [];
|
||||
$attributes += ['class' => []];
|
||||
// Use wrapper attributes for the id instead of #id,
|
||||
// this stops the <label> from having a 'for' attribute.
|
||||
$attributes += [
|
||||
'id' => $element['#webform_id'],
|
||||
];
|
||||
$attributes['class'][] = 'webform-element';
|
||||
$attributes['class'][] = 'webform-element-type-' . str_replace('_', '-', $type);
|
||||
|
||||
$variables['item'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $variables['title'],
|
||||
'#name' => $element['#webform_key'],
|
||||
// Use wrapper attributes for the id instead of #id,
|
||||
// this stops the <label> from having a 'for' attribute.
|
||||
'#wrapper_attributes' => [
|
||||
'id' => $element['#webform_id'],
|
||||
'class' => [
|
||||
'webform-element',
|
||||
'webform-element-type-' . str_replace('_', '-', $type),
|
||||
],
|
||||
],
|
||||
'#wrapper_attributes' => $attributes,
|
||||
];
|
||||
if (is_array($variables['value'])) {
|
||||
$variables['item']['value'] = $variables['value'];
|
||||
|
@ -942,8 +949,11 @@ function template_preprocess_webform_element_image_file(array &$variables) {
|
|||
$uri = $file->getFileUri();
|
||||
$url = Url::fromUri(file_create_url($uri));
|
||||
|
||||
$extension = pathinfo($uri, PATHINFO_EXTENSION);
|
||||
$is_image = in_array($extension, ['gif', 'png', 'jpg', 'jpeg']);
|
||||
|
||||
// Build image.
|
||||
if (\Drupal::moduleHandler()->moduleExists('image') && $style_name && ImageStyle::load($style_name)) {
|
||||
if ($is_image && \Drupal::moduleHandler()->moduleExists('image') && $style_name && ImageStyle::load($style_name)) {
|
||||
$variables['image'] = [
|
||||
'#theme' => 'image_style',
|
||||
'#style_name' => $variables['style_name'],
|
||||
|
|
|
@ -187,16 +187,7 @@ function webform_lingotek_config_entity_document_upload(array &$source_data, Con
|
|||
$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);
|
||||
_webform_lingotek_decode_tokens($source_data);
|
||||
break;
|
||||
|
||||
case 'webform_options';
|
||||
|
@ -212,16 +203,7 @@ function webform_lingotek_config_entity_document_upload(array &$source_data, Con
|
|||
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);
|
||||
_webform_lingotek_decode_tokens($data);
|
||||
|
||||
/** @var \Drupal\webform\WebformInterface $translation */
|
||||
$translation->setElements($data['elements']);
|
||||
|
@ -236,3 +218,79 @@ function webform_lingotek_config_entity_translation_presave(ConfigEntityInterfac
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_lingotek_config_object_document_upload()
|
||||
*/
|
||||
function webform_lingotek_config_object_document_upload(array &$data, $config_name) {
|
||||
if ($config_name !== 'webform.settings') {
|
||||
return;
|
||||
}
|
||||
|
||||
$data['webform.settings']['test.types'] = Yaml::decode($data['webform.settings']['test.types']);
|
||||
$data['webform.settings']['test.names'] = Yaml::decode($data['webform.settings']['test.names']);
|
||||
|
||||
_webform_lingotek_encode_tokens($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_lingotek_config_object_translation_presave()
|
||||
*/
|
||||
function webform_lingotek_config_object_translation_presave(array &$data, $config_name) {
|
||||
if ($config_name !== 'webform.settings') {
|
||||
return;
|
||||
}
|
||||
|
||||
_webform_lingotek_decode_tokens($data);
|
||||
|
||||
$data['webform.settings']['test.types'] = Yaml::encode($data['webform.settings']['test.types']);
|
||||
$data['webform.settings']['test.names'] = Yaml::encode($data['webform.settings']['test.names']);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Lingotek decode/encode token functions.
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Encode all tokens so that they won't be translated.
|
||||
*
|
||||
* @param array $data
|
||||
* An array of data.
|
||||
*/
|
||||
function _webform_lingotek_encode_tokens(array &$data) {
|
||||
$yaml = Yaml::encode($data);
|
||||
$yaml = preg_replace_callback(
|
||||
'/\[([a-z][^]]+)\]/',
|
||||
function ($matches) {
|
||||
// Encode all token characters to HTML entities.
|
||||
// @see https://stackoverflow.com/questions/6720826/php-convert-all-characters-to-html-entities.
|
||||
$replacement = mb_encode_numericentity($matches[1], array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
|
||||
return "[$replacement]";
|
||||
},
|
||||
$yaml
|
||||
);
|
||||
$data = Yaml::decode($yaml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode all tokens after string have been translated.
|
||||
*
|
||||
* @param array $data
|
||||
* An array of data.
|
||||
*/
|
||||
function _webform_lingotek_decode_tokens(array &$data) {
|
||||
$yaml = Yaml::encode($data);
|
||||
$yaml = preg_replace_callback(
|
||||
'/\[([^]]+?)\]/',
|
||||
function ($matches) {
|
||||
// Decode token HTML entities to characters.
|
||||
// @see https://stackoverflow.com/questions/6720826/php-convert-all-characters-to-html-entities.
|
||||
$token = mb_decode_numericentity($matches[1], array(0x000000, 0x10ffff, 0, 0xffffff), 'UTF-8');
|
||||
return "[$token]";
|
||||
},
|
||||
$yaml
|
||||
);
|
||||
$data = Yaml::decode($yaml);
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue