Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
transform_api
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
transform_api
Merge requests
!6
Introduced FileTransformBase class for File field transforms
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Introduced FileTransformBase class for File field transforms
issue/transform_api-3413192:3413192-create-filetransformbase-class
into
1.0.x
Overview
0
Commits
1
Pipelines
1
Changes
3
Merged
Erik Petra
requested to merge
issue/transform_api-3413192:3413192-create-filetransformbase-class
into
1.0.x
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
3
Expand
Closes
#3413192
0
0
Merge request reports
Compare
1.0.x
version 1
a1d249f8
1 year ago
1.0.x (base)
and
latest version
latest version
a1d249f8
1 commit,
1 year ago
version 1
a1d249f8
1 commit,
1 year ago
3 files
+
88
−
33
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/Transform/Field/FileTransformBase.php
0 → 100644
+
83
−
0
Options
<?php
namespace
Drupal\transform_api\Plugin\Transform\Field
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\Core\File\FileUrlGeneratorInterface
;
use
Drupal\transform_api
\FieldTransformBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Base class for File field transform plugins.
*/
abstract
class
FileTransformBase
extends
FieldTransformBase
{
/**
* File url generator.
*
* @var \Drupal\Core\File\FileUrlGeneratorInterface
*/
protected
$fileUrlGenerator
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* Constructs a FieldTransformBase object.
*
* @param string $plugin_id
* The plugin_id for the transform.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the transform is associated.
* @param array $settings
* The transform settings.
* @param string $label
* The transform label display setting.
* @param string $transform_mode
* The transform mode.
* @param array $third_party_settings
* Any third party settings.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file url generator.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public
function
__construct
(
$plugin_id
,
$plugin_definition
,
FieldDefinitionInterface
$field_definition
,
array
$settings
,
$label
,
$transform_mode
,
array
$third_party_settings
,
FileUrlGeneratorInterface
$file_url_generator
,
EntityTypeManagerInterface
$entity_type_manager
)
{
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$field_definition
,
$settings
,
$label
,
$transform_mode
,
$third_party_settings
);
$this
->
fileUrlGenerator
=
$file_url_generator
;
$this
->
entityTypeManager
=
$entity_type_manager
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$plugin_id
,
$plugin_definition
,
$configuration
[
'field_definition'
],
$configuration
[
'settings'
],
$configuration
[
'label'
],
$configuration
[
'transform_mode'
],
$configuration
[
'third_party_settings'
],
$container
->
get
(
'file_url_generator'
),
$container
->
get
(
'entity_type.manager'
));
}
/**
* Loads file entity.
*
* @param $fid
*
* @return \Drupal\file\FileInterface|null
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected
function
loadFile
(
$fid
)
{
/** @var \Drupal\file\FileInterface|null $file */
$file
=
$this
->
entityTypeManager
->
getStorage
(
'file'
)
->
load
(
$fid
);
return
$file
;
}
}
Loading