Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
color_field
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
color_field
Commits
f5bf6455
Commit
f5bf6455
authored
Nov 10, 2013
by
targoo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Covert Swatch formatter to support new Drupal 8 API
parent
4fb64503
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
lib/Drupal/color_field/Plugin/Field/FieldFormatter/ColorFieldSwatchFormatter.php
...Plugin/Field/FieldFormatter/ColorFieldSwatchFormatter.php
+20
-19
No files found.
lib/Drupal/color_field/Plugin/Field/FieldFormatter/ColorFieldSwatchFormatter.php
View file @
f5bf6455
...
...
@@ -2,12 +2,13 @@
/**
* @file
*
Definition of
Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldSwatchFormatter.
*
Contains \
Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldSwatchFormatter.
*/
namespace
Drupal\color_field\Plugin\Field\FieldFormatter
;
use
Drupal\Core\Field\FormatterBase
;
use
Drupal\Core\Field\FieldItemListInterface
;
/**
* Plugin implementation of the 'color_field_swatch' formatter.
...
...
@@ -27,22 +28,6 @@ use Drupal\Core\Field\FormatterBase;
*/
class
ColorFieldSwatchFormatter
extends
FormatterBase
{
/**
* {@inheritdoc}
*/
public
function
settingsSummary
()
{
$summary
=
array
();
$settings
=
$this
->
getSettings
();
$summary
[]
=
t
(
'Width: @width Height: @height px'
,
array
(
'@width'
=>
$settings
[
'width'
],
'@height'
=>
$settings
[
'height'
]
));
return
$summary
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -70,10 +55,26 @@ class ColorFieldSwatchFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
array
$items
)
{
$elements
=
array
();
public
function
settingsSummary
()
{
$summary
=
array
();
$settings
=
$this
->
getSettings
();
$summary
[]
=
t
(
'Width: @width Height: @height px'
,
array
(
'@width'
=>
$settings
[
'width'
],
'@height'
=>
$settings
[
'height'
]
));
return
$summary
;
}
/**
* {@inheritdoc}
*/
public
function
viewElements
(
FieldItemListInterface
$items
)
{
$elements
=
array
();
$settings
=
$this
->
getFieldSettings
();
foreach
(
$items
as
$delta
=>
$item
)
{
$elements
[
$delta
]
=
array
(
'#markup'
=>
'<div style="background: '
.
$item
[
'rgb'
]
.
'; width: '
.
$settings
[
'width'
]
.
'px; height: '
.
$settings
[
'height'
]
.
'px;"></div>'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment