Skip to content
Snippets Groups Projects
Commit b9ff0883 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2: Committed by Julian Pustkuchen
Browse files

Issue #3298029 by Grevil, Project Update Bot, Anybody: Automated Drupal 10 compatibility fixes

parent bf0f5cba
No related branches found
Tags 7.x-2.0
No related merge requests found
<?php
namespace Drupal\select_translation\Commands;
use Drush\Commands\DrushCommands;
/**
* Drush command class containing select translation drush commands.
*
* @package Drupal\select_translation\Commands
*/
class SelectTranslationCommands extends DrushCommands {
/**
* Select which translation of a node should be displayed.
*
* @param int $nid
* The Node ID.
*
* @command select_translation:translation
* @aliases select-translation
*
* @option mode
* The selection mode, it can be: 'default', 'original', or a comma
* separated list of language codes. See the API doc for more details.
* @usage select_translation:translation --mode default
*
*/
public function translation($nid, array $options = ['mode' => NULL]) {
$node_id = filter_var($nid, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if (!$node_id) {
throw new \Exception(dt("The 'nid' argument must be an integer >= 1."));
}
$mode = $options['mode'];
if ($mode) {
$node = select_translation_of_node($node_id, $mode);
}
else {
$node = select_translation_of_node($node_id);
}
if (!$node) {
throw new \Exception(dt("Node with 'nid' = $nid not available."));
}
\Drupal::logger('select_translation')->info("Selected translation for node $nid: " . $node->language()->getId());
return $node;
}
}
{
"name": "org/select_translation",
"type": "drupal-drush",
"extra": {
"drush": {
"services": {
"drush.services.yml": "^10"
}
}
}
}
services:
select_translation.commands:
class: \Drupal\select_translation\Commands\SelectTranslationCommands
tags:
- { name: drush.command }
<?php
/**
* @file
* Drush integration for the select_translation module.
*/
use Drush\Log\LogLevel;
/**
* Implements hook_drush_command().
*/
function select_translation_drush_command() {
$items['select-translation'] = [
'description' => dt('Select which translation of a node should be displayed.'),
'arguments' => [
'nid' => dt('The Node ID.'),
],
'options' => [
'mode' => dt('The selection mode, it can be: \'default\', \'original\', or a comma separated list of language codes. See the API doc for more details.'),
],
'required-arguments' => 1,
];
return $items;
}
/**
* Select which translation of a node should be displayed.
*
* @param int $nid
* The Node ID.
*/
function drush_select_translation($nid) {
if (\Drupal::moduleHandler()->moduleExists('select_translation') === FALSE) {
return drush_set_error('INVALID_MODULE', dt("Module 'select_translation' doesn't exist or is uninstalled."));
}
$node_id = filter_var($nid, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if (!$node_id) {
return drush_set_error('INVALID_ARGUMENT', dt("The 'nid' argument must be an integer >= 1."));
}
$mode = drush_get_option('mode');
if ($mode) {
$node = select_translation_of_node($node_id, $mode);
}
else {
$node = select_translation_of_node($node_id);
}
if (!$node) {
return drush_set_error('INVALID_NODE', dt("Node with 'nid' = $nid not available."));
}
\Drupal::logger("Selected translation for node $nid: " . $node->language()->getId(), LogLevel::OK);
return $node;
}
......@@ -2,7 +2,7 @@ name: 'Select Translation'
type: module
description: 'Provides a Views filter to select which translation of a node should be displayed.'
package: Multilingual
core_version_requirement: ^9
core_version_requirement: ^9 || ^10
dependencies:
- drupal:language
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment