Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tamper
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
tamper
Merge requests
!28
convert to UTF8 Plugin
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
convert to UTF8 Plugin
issue/tamper-3471059:3471059-convert-to-utf8
into
8.x-1.x
Overview
0
Commits
8
Pipelines
8
Changes
1
Open
Thomas Speer
requested to merge
issue/tamper-3471059:3471059-convert-to-utf8
into
8.x-1.x
8 months ago
Overview
0
Commits
8
Pipelines
8
Changes
1
Expand
Closes
#3471059
0
0
Merge request reports
Compare
8.x-1.x
version 7
0ee2ec3e
1 month ago
version 6
11a27a1b
8 months ago
version 5
c033ee60
8 months ago
version 4
78093af4
8 months ago
version 3
b251d228
8 months ago
version 2
ebfbdfe0
8 months ago
version 1
e8bb5fe9
8 months ago
8.x-1.x (HEAD)
and
latest version
latest version
d7b79205
8 commits,
1 month ago
version 7
0ee2ec3e
7 commits,
1 month ago
version 6
11a27a1b
6 commits,
8 months ago
version 5
c033ee60
5 commits,
8 months ago
version 4
78093af4
4 commits,
8 months ago
version 3
b251d228
3 commits,
8 months ago
version 2
ebfbdfe0
2 commits,
8 months ago
version 1
e8bb5fe9
1 commit,
8 months ago
1 file
+
99
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/Tamper/ConvertToUtf8.php
0 → 100644
+
99
−
0
Options
<?php
namespace
Drupal\tamper\Plugin\Tamper
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\tamper\Exception\TamperException
;
use
Drupal\tamper\TamperableItemInterface
;
use
Drupal\tamper\TamperBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Plugin implementation for transliteration.
*
* @Tamper(
* id = "convertToUtf8",
* label = @Translation("Converts to UTF-8"),
* description = @Translation("Runs the value through mb_convert_encoding to convert it to UTF-8."),
* category = "Text"
* )
*/
class
ConvertToUtf8
extends
TamperBase
implements
ContainerFactoryPluginInterface
{
const
SETTING_MODE
=
'mode'
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$configuration
[
'source_definition'
]
);
}
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
()
{
$config
=
parent
::
defaultConfiguration
();
$config
[
self
::
SETTING_MODE
]
=
'ISO-8859-1'
;
return
$config
;
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
self
::
SETTING_MODE
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Source Encoding:'
),
'#options'
=>
$this
->
getOptions
(),
'#default_value'
=>
$this
->
getSetting
(
self
::
SETTING_MODE
),
];
return
$form
;
}
/**
* Provides Options for the configuration Form.
*/
protected
function
getOptions
()
{
$encodings
=
mb_list_encodings
();
$options
=
[];
foreach
(
$encodings
as
$encoding
)
{
if
(
$encoding
!=
"UTF-8"
)
{
$options
[
$encoding
]
=
$encoding
;
}
}
return
$options
;
}
/**
* {@inheritdoc}
*/
public
function
tamper
(
$data
,
TamperableItemInterface
$item
=
NULL
)
{
if
(
!
is_string
(
$data
))
{
throw
new
TamperException
(
'Input should be a string.'
);
}
$sourceencoding
=
$this
->
getSetting
(
self
::
SETTING_MODE
);
return
mb_convert_encoding
(
$data
,
"UTF-8"
,
$sourceencoding
);
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
$this
->
setConfiguration
([
self
::
SETTING_MODE
=>
$form_state
->
getValue
(
self
::
SETTING_MODE
),
]);
}
}
Loading