Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
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
drupal
Commits
bb3ee207
Commit
bb3ee207
authored
10 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2333395
by Jelle_S, attiks: Add sizes to template_preprocess_image.
parent
0096eb08
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/includes/theme.inc
+4
-2
4 additions, 2 deletions
core/includes/theme.inc
core/modules/system/src/Tests/Theme/ImageTest.php
+47
-0
47 additions, 0 deletions
core/modules/system/src/Tests/Theme/ImageTest.php
with
51 additions
and
2 deletions
core/includes/theme.inc
+
4
−
2
View file @
bb3ee207
...
...
@@ -1073,11 +1073,13 @@ function template_preprocess_links(&$variables) {
* - title: The title text is displayed when the image is hovered in some
* popular browsers.
* - attributes: Associative array of attributes to be placed in the img tag.
* - sizes: The sizes attribute for viewport-based selection of images.
* - http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content.html#introduction-3:viewport-based-selection-2
*/
function
template_preprocess_image
(
&
$variables
)
{
$variables
[
'attributes'
][
'src'
]
=
file_create_url
(
$variables
[
'uri'
]);
foreach
(
array
(
'width'
,
'height'
,
'alt'
,
'title'
)
as
$key
)
{
foreach
(
array
(
'width'
,
'height'
,
'alt'
,
'title'
,
'sizes'
)
as
$key
)
{
if
(
isset
(
$variables
[
$key
]))
{
// If the property has already been defined in the attributes,
// do not override, including NULL.
...
...
@@ -2266,7 +2268,7 @@ function drupal_common_theme() {
// - http://dev.w3.org/html5/spec/Overview.html#alt
// The title attribute is optional in all cases, so it is omitted by
// default.
'variables'
=>
array
(
'uri'
=>
NULL
,
'width'
=>
NULL
,
'height'
=>
NULL
,
'alt'
=>
''
,
'title'
=>
NULL
,
'attributes'
=>
array
()),
'variables'
=>
array
(
'uri'
=>
NULL
,
'width'
=>
NULL
,
'height'
=>
NULL
,
'alt'
=>
''
,
'title'
=>
NULL
,
'attributes'
=>
array
()
,
'sizes'
=>
NULL
),
'template'
=>
'image'
,
),
'breadcrumb'
=>
array
(
...
...
This diff is collapsed.
Click to expand it.
core/modules/system/src/Tests/Theme/ImageTest.php
0 → 100644
+
47
−
0
View file @
bb3ee207
<?php
/**
* @file
* Definition of Drupal\system\Tests\Theme\ImageTest.
*/
namespace
Drupal\system\Tests\Theme
;
use
Drupal\simpletest\KernelTestBase
;
/**
* Tests built-in image theme functions.
*
* @group Theme
*/
class
ImageTest
extends
KernelTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
array
(
'system'
);
/**
* Tests that an image with the sizes attribute is output correctly.
*/
function
testThemeImageWithSizes
()
{
// Test with multipliers.
$sizes
=
'(max-width: '
.
rand
(
10
,
30
)
.
'em) 100vw, (max-width: '
.
rand
(
30
,
50
)
.
'em) 50vw, 30vw'
;
$image
=
array
(
'#theme'
=>
'image'
,
'#sizes'
=>
$sizes
,
'#uri'
=>
'/core/misc/druplicon.png'
,
'#width'
=>
rand
(
0
,
1000
)
.
'px'
,
'#height'
=>
rand
(
0
,
500
)
.
'px'
,
'#alt'
=>
$this
->
randomMachineName
(),
'#title'
=>
$this
->
randomMachineName
(),
);
$this
->
render
(
$image
);
// Make sure sizes is set.
$this
->
assertRaw
(
$sizes
,
'Sizes is set correctly.'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment