Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
custom_elements
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
custom_elements
Merge requests
!79
Add image-style config
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add image-style config
issue/custom_elements-3468348:3468348-image-style-config
into
3.x
Overview
5
Commits
17
Pipelines
21
Changes
2
Merged
Bálint Junkuncz
requested to merge
issue/custom_elements-3468348:3468348-image-style-config
into
3.x
8 months ago
Overview
5
Commits
17
Pipelines
21
Changes
2
Expand
Closes
#3468348
0
0
Merge request reports
Compare
3.x
version 19
071f44b7
8 months ago
version 18
071f44b7
8 months ago
version 17
ff967135
8 months ago
version 16
133e77d6
8 months ago
version 15
81be92ed
8 months ago
version 14
08529bbe
8 months ago
version 13
1adc5166
8 months ago
version 12
b56fd8b0
8 months ago
version 11
26ec83ae
8 months ago
version 10
7eb5a7b3
8 months ago
version 9
588b2555
8 months ago
version 8
1056a658
8 months ago
version 7
5ea3903f
8 months ago
version 6
a1dd2993
8 months ago
version 5
05c5110f
8 months ago
version 4
63a18d51
8 months ago
version 3
7e7f0014
8 months ago
version 2
4481e2a5
8 months ago
version 1
131ab58f
8 months ago
3.x (base)
and
latest version
latest version
071f44b7
17 commits,
8 months ago
version 19
071f44b7
17 commits,
8 months ago
version 18
071f44b7
17 commits,
8 months ago
version 17
ff967135
17 commits,
8 months ago
version 16
133e77d6
16 commits,
8 months ago
version 15
81be92ed
15 commits,
8 months ago
version 14
08529bbe
14 commits,
8 months ago
version 13
1adc5166
13 commits,
8 months ago
version 12
b56fd8b0
12 commits,
8 months ago
version 11
26ec83ae
11 commits,
8 months ago
version 10
7eb5a7b3
10 commits,
8 months ago
version 9
588b2555
9 commits,
8 months ago
version 8
1056a658
8 commits,
8 months ago
version 7
5ea3903f
7 commits,
8 months ago
version 6
a1dd2993
6 commits,
8 months ago
version 5
05c5110f
5 commits,
8 months ago
version 4
63a18d51
4 commits,
8 months ago
version 3
7e7f0014
3 commits,
8 months ago
version 2
4481e2a5
2 commits,
8 months ago
version 1
131ab58f
1 commit,
8 months ago
2 files
+
261
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/CustomElementsFieldFormatter/FileCeFieldFormatter.php
+
52
−
2
Options
@@ -3,6 +3,8 @@
namespace
Drupal\custom_elements\Plugin\CustomElementsFieldFormatter
;
use
Drupal\Core\Field\FieldItemInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\custom_elements
\CustomElementsImageStyleConfigTrait
;
/**
* Implementation of the 'file' custom element formatter plugin.
@@ -25,13 +27,58 @@ use Drupal\Core\Field\FieldItemInterface;
*/
class
FileCeFieldFormatter
extends
FlattenedCeFieldFormatter
{
use
CustomElementsImageStyleConfigTrait
;
/**
* {@inheritdoc}
*/
public
static
function
defaultSettings
()
{
return
[
'image_style'
=>
''
,
]
+
parent
::
defaultSettings
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$element
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
if
(
$this
->
getFieldDefinition
()
->
getType
()
===
'image'
)
{
$element
+=
$this
->
getImageStyleConfigForm
(
$this
->
configuration
[
'image_style'
]
??
''
);
}
return
$element
;
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
if
(
$this
->
getFieldDefinition
()
->
getType
()
===
'image'
)
{
$this
->
configuration
[
'image_style'
]
=
$form_state
->
getValue
(
'image_style'
);
}
}
/**
* {@inheritdoc}
*/
protected
function
getFieldItemProperties
(
FieldItemInterface
$field_item
,
array
$ignore_properties
=
[]):
array
{
$values
=
parent
::
getFieldItemProperties
(
$field_item
,
[
'target_id'
]);
// Add url property of the referenced file to the values.
$values
[
'url'
]
=
$field_item
->
entity
->
uri
->
url
;
if
(
$this
->
getFieldDefinition
()
->
getType
()
===
'image'
&&
!
empty
(
$this
->
configuration
[
'image_style'
]))
{
$image_style
=
$this
->
loadImageStyle
(
$this
->
configuration
[
'image_style'
]);
if
(
$image_style
)
{
$values
[
'url'
]
=
$this
->
getImageStyleUrl
(
$image_style
,
$field_item
->
entity
->
getFileUri
());
}
else
{
// Wrong/incomplete backend configuration must be fixed, rather than
// silently output an unintended response.
throw
new
\UnexpectedValueException
(
"Image style '
{
$this
->
configuration
[
'image_style'
]
}
' cannot be loaded."
);
}
}
else
{
// Add url property of the referenced file to the values.
$values
[
'url'
]
=
$field_item
->
entity
->
uri
->
url
;
}
return
$values
;
}
@@ -40,6 +87,9 @@ class FileCeFieldFormatter extends FlattenedCeFieldFormatter {
*/
public
function
settingsSummary
()
{
$summary
=
parent
::
settingsSummary
();
if
(
$this
->
getFieldDefinition
()
->
getType
()
===
'image'
)
{
$summary
+=
$this
->
getSettingsSummary
(
$this
->
configuration
[
'image_style'
]
??
''
);
}
// target_id is the 'main' property, so nothing gets set into a slot.
$summary
[]
=
$this
->
t
(
'Is Slot is ignored.'
);
return
$summary
;
Loading