Commit b0607fca authored by Loparev's avatar Loparev
Browse files

Drupal 9 compatibility update

parent fa4f5c95
......@@ -9,7 +9,7 @@ use Drupal\tmgmt_smartling_acquia_cohesion\AcquiaCohesionDataConverter;
/**
* Tests JSON <-> XML data transformation.
*
* @group tmgmt_smartling
* @group tmgmt_smartling_acquia_cohesion
*/
class AcquiaCohesionDataConverterTest extends SmartlingTestBase {
public function testJsonToXmlTransformation() {
......
......@@ -11,7 +11,7 @@ use Drupal\tmgmt_smartling_acquia_cohesion\AcquiaCohesionDataSuggester;
/**
* Tests job items suggestions.
*
* @group tmgmt_smartling
* @group tmgmt_smartling_acquia_cohesion
*/
class AcquiaCohesionDataSuggesterTest extends SmartlingTestBase {
/**
......
name: 'Smartling Acquia Cohesion support'
description: 'Implements support for Acquia Cohesion components'
package: 'Translation Management'
core: 8.x
core_version_requirement: ^8.8 || ^9
type: module
dependencies:
- tmgmt_smartling:tmgmt_smartling
- cohesion
hidden: true
......@@ -116,7 +116,7 @@ class TmgmtSmartlingContextDebugForm extends FormBase {
$message = print_r($response, TRUE);
\Drupal::logger('tmgmt_smartling_context_debug')->info($message);
drupal_set_message('Smartling response: ' . $message);
$this->messenger()->addStatus('Smartling response: ' . $message);
}
}
}
name: 'Smartling Context Debugger'
description: 'A form that helps to debug Smartling context feature.'
package: 'Translation Management'
core: 8.x
core_version_requirement: ^8.8 || ^9
type: module
dependencies:
......
name: Smartling Log Settings
description: 'Set up log severity for each channel and logger.'
package: 'Translation Management'
core: '8.x'
core_version_requirement: ^8.8 || ^9
type: module
configure: system.logging_settings
name: 'Smartling Translator Test: alter filename'
description: 'Implements hook hook_tmgmt_smartling_filename_alter for testing purposes'
package: 'Translation Management'
core: 8.x
core_version_requirement: ^8.8 || ^9
type: module
hidden: true
name: 'Smartling Translator Test'
description: 'Implements hooks hook_user_login and hook_user_logout for testing purposes'
package: 'Translation Management'
core: 8.x
core_version_requirement: ^8.8 || ^9
type: module
hidden: true
......@@ -2,6 +2,7 @@
namespace Drupal\tmgmt_smartling\Context;
use Drupal\Core\File\FileSystemInterface;
use Drupal;
use Drupal\tmgmt_smartling\Exceptions\EmptyContextParameterException;
use Drupal\tmgmt_smartling\Smartling\SmartlingApiWrapper;
......@@ -122,8 +123,8 @@ class ContextUploader {
$html = $this->getContextualizedPage($url, $proj_settings);
// Save context file.
if (file_prepare_directory($smartling_context_directory, FILE_CREATE_DIRECTORY) &&
($file = file_save_data($html, $smartling_context_file, FILE_EXISTS_REPLACE))
if (\Drupal::service('file_system')->prepareDirectory($smartling_context_directory, FileSystemInterface::CREATE_DIRECTORY) &&
($file = file_save_data($html, $smartling_context_file, FileSystemInterface::EXISTS_REPLACE))
) {
$response = $this->uploadContextBody($url, $file, $proj_settings, $filename);
$this->uploadContextMissingResources($smartling_context_directory, $proj_settings);
......@@ -228,7 +229,7 @@ class ContextUploader {
$smartling_context_resources_directory = $smartling_context_directory . '/resources';
// Do nothing if directory for resources isn't accessible.
if (!file_prepare_directory($smartling_context_resources_directory, FILE_CREATE_DIRECTORY)) {
if (!\Drupal::service('file_system')->prepareDirectory($smartling_context_resources_directory, FileSystemInterface::CREATE_DIRECTORY)) {
$this->logger->error("Context resources directory @dir doesn't exist or is not writable. Missing resources were not uploaded. Context might look incomplete.", [
'@dir' => $smartling_context_directory,
]);
......@@ -288,7 +289,7 @@ class ContextUploader {
// be able to fopen() resource which is behind basic auth. So
// download it first (with a help of curl), save it to smartling's
// directory and then upload.
if ($file = file_save_data($smartling_context_resource_file_content, $smartling_context_resource_file, FILE_EXISTS_REPLACE)) {
if ($file = file_save_data($smartling_context_resource_file_content, $smartling_context_resource_file, FileSystemInterface::EXISTS_REPLACE)) {
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')->getViaUri($file->getFileUri());
$params = new UploadResourceParameters();
$params->setFile($stream_wrapper_manager->realpath());
......
......@@ -2,12 +2,12 @@
namespace Drupal\tmgmt_smartling\Context;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\tmgmt_smartling\Exceptions\WrongUsernameException;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Session\SessionManagerInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use \Drupal\Core\Entity\EntityManagerInterface;
use Psr\Log\LoggerInterface;
class ContextUserAuth {
......@@ -50,7 +50,7 @@ class ContextUserAuth {
*
* @param \Drupal\Core\Session\AccountProxyInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManager $entity_manager
* The user storage.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The user storage.
......@@ -62,7 +62,7 @@ class ContextUserAuth {
*/
public function __construct(
AccountProxyInterface $account,
EntityManagerInterface $entity_manager,
EntityTypeManager $entity_manager,
ModuleHandlerInterface $module_handler,
SessionManagerInterface $session_manager,
Session $session,
......
......@@ -34,9 +34,6 @@ class HtmlAssetInliner {
);
/**
*
*/
public function __construct() {
# suppress DOM parsing errors
libxml_use_internal_errors(TRUE);
......
......@@ -84,7 +84,7 @@ class RequestSubscriber implements EventSubscriberInterface {
if (!empty($message)) {
$message .= ' ' . $this->t('Configure your cron job to run once per 5-10 minutes in order to process Smartling queues more effectively. Please visit this <a href="http://docs.drush.org/en/master/cron/" target="_blank">page</a> for more information.');
drupal_set_message(new TranslatableMarkup($message), 'warning');
\Drupal::messenger()->addWarning(new TranslatableMarkup($message));
}
}
}
......
......@@ -12,8 +12,8 @@ use Drupal\Core\Url;
use Drupal\tmgmt\Entity\JobItem;
use Drupal\tmgmt_smartling\Context\ContextUserAuth;
use Drupal\tmgmt_smartling\Exceptions\SmartlingBaseException;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\user\SharedTempStoreFactory;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -84,9 +84,9 @@ class SendContextActionApproveForm extends ConfirmFormBase {
/**
* Constructs a new UserMultipleCancelConfirm.
*
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The temp store factory.
* @param \Drupal\user\SharedTempStoreFactory $shared_store_factory
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $shared_store_factory
* @param \Drupal\tmgmt_smartling\Context\ContextUserAuth $context_user_auth
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
......@@ -116,8 +116,8 @@ class SendContextActionApproveForm extends ConfirmFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('user.private_tempstore'),
$container->get('user.shared_tempstore'),
$container->get('tempstore.private'),
$container->get('tempstore.shared'),
$container->get('tmgmt_smartling.utils.context.user_auth'),
$container->get('entity_type.manager'),
$container->get('language_manager'),
......@@ -261,10 +261,9 @@ class SendContextActionApproveForm extends ConfirmFormBase {
$this->contextUserAuth->switchUser($translator_settings['contextUsername'], $translator_settings['context_silent_user_switching']);
}
else {
drupal_set_message(
t('Context was not sent to Smartling, because Smartling provider was not selected for one of these jobs: @jids', [
'@jids' => implode(' ,', $ids),
]), 'error');
$this->messenger()->addError(t('Context was not sent to Smartling, because Smartling provider was not selected for one of these jobs: @jids', [
'@jids' => implode(' ,', $ids),
]));
}
}
catch (Exception $e) {
......
......@@ -13,7 +13,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use \Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
/**
* Translate entity.
......@@ -50,7 +50,7 @@ class SendContextAction extends ActionBase implements ContainerFactoryPluginInte
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Session\AccountInterface $current_user
* Current user.
......@@ -88,7 +88,7 @@ class SendContextAction extends ActionBase implements ContainerFactoryPluginInte
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition,
$container->get('user.private_tempstore'),
$container->get('tempstore.private'),
$container->get('current_user')
);
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\tmgmt_smartling\Plugin\tmgmt\Translator;
use Drupal\Core\File\FileSystemInterface;
use Drupal;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -169,7 +170,7 @@ class SmartlingTranslator extends TranslatorPluginBase implements
}
return AvailableResult::no(t('@translator is not available. Make sure it is properly <a href=:configured>configured</a>.', [
'@translator' => $translator->label(),
':configured' => $translator->url(),
':configured' => $translator->toUrl(),
]));
}
......@@ -271,9 +272,9 @@ class SmartlingTranslator extends TranslatorPluginBase implements
$path = $job->getSetting('scheme') . '://tmgmt_sources/' . $name;
$dirname = dirname($path);
if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
if (\Drupal::service('file_system')->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY)) {
$data = $export->export($job);
$file = file_save_data($data, $path, FILE_EXISTS_REPLACE);
$file = file_save_data($data, $path, FileSystemInterface::EXISTS_REPLACE);
$this->fileUsage->add($file, 'tmgmt_smartling', 'tmgmt_job', $job->id());
$job->submitted('Exported file can be downloaded <a href="@link">here</a>.', array('@link' => file_create_url($path)));
}
......
......@@ -32,7 +32,7 @@ class ConnectorInfo {
* @return string
*/
public static function getLibVersion($name = 'tmgmt_smartling', $default = 'unknown') {
$info = system_get_info('module', $name);
$info = \Drupal::service('extension.list.module')->getExtensionInfo($name);
$client_version = $default;
if (!empty($info['version'])) {
......
......@@ -340,7 +340,7 @@ class SmartlingTranslatorUi extends TranslatorPluginUiBase {
// queues selected.
if (count($selected_queues) > 1 && in_array('smartling_context_upload', $selected_queues)) {
unset($selected_queues['smartling_context_upload']);
drupal_set_message(t('Please, process "Upload context" queue separately.'), 'warning');
$this->messenger()->addWarning(t('Please, process "Upload context" queue separately.'));
}
foreach ($selected_queues as $queue_name) {
......@@ -390,10 +390,10 @@ class SmartlingTranslatorUi extends TranslatorPluginUiBase {
*/
public function runCron(array &$form, FormStateInterface $form_state) {
if (\Drupal::service('cron')->run()) {
drupal_set_message(t('Cron ran successfully.'));
$this->messenger()->addStatus(t('Cron ran successfully.'));
}
else {
drupal_set_message(t('Cron run failed.'), 'error');
$this->messenger()->addError(t('Cron run failed.'));
}
}
......
......@@ -215,7 +215,7 @@ class ContextTest extends SmartlingTestBase {
$this->drupalPostForm(NULL, [], t('Send Context to Smartling'));
$fileName = str_replace('.', '_', $fileName);
$file_path = \Drupal::getContainer()->get('file_system')->realpath(file_default_scheme() . "://tmgmt_smartling_context/{$fileName}.html");
$file_path = \Drupal::getContainer()->get('file_system')->realpath(\Drupal::config('system.file')->get('default_scheme') . "://tmgmt_smartling_context/{$fileName}.html");
$content = file_get_contents($file_path);
$this->assertTrue(strpos($content, 'class="sl-override-context"') === FALSE);
......
......@@ -227,7 +227,7 @@ abstract class SmartlingTestBase extends TMGMTTestBase {
* @param string $format
*/
protected function checkGeneratedFile($fileName, $nodeTitle, $format = 'xml') {
$file_path = \Drupal::getContainer()->get('file_system')->realpath(file_default_scheme() . "://tmgmt_sources/$fileName");
$file_path = \Drupal::getContainer()->get('file_system')->realpath(\Drupal::config('system.file')->get('default_scheme') . "://tmgmt_sources/$fileName");
$content = file_get_contents($file_path);
$this->assertTrue(strpos($content, $nodeTitle) !== FALSE, 'Title is in file');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment