Issue #2124377 by ellishettinga, Jelle_S, attiks, mdrummond, Schnitzel, InternetDevels: Rename "Picture" module to "Responsive Image" module.

8.0.x
webchick 2014-03-16 10:44:47 -07:00
parent 533ee3a17f
commit 21ae3ef209
21 changed files with 347 additions and 324 deletions

View File

@ -353,9 +353,6 @@ Path module
Phone module
- Dave Reid 'davereid' http://drupal.org/user/53892
Picture module
- Peter Droogmans 'attiks' http://drupal.org/user/105002
RDF module
- Stéphane Corlosquet 'scor' http://drupal.org/user/52142
@ -363,6 +360,9 @@ REST module
- Klaus Purer 'klausi' http://drupal.org/user/262198
- Larry Garfield 'Crell' http://drupal.org/user/26398
Responsive Image module
- Peter Droogmans 'attiks' http://drupal.org/user/105002
Search module
- Jennifer Hodgdon 'jhodgdon' https://drupal.org/user/155601
- Peter Wolanin 'pwolanin' https://drupal.org/user/49851

View File

@ -35,7 +35,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'shortcut',
'taxonomy',
'image',
'picture',
'responsive_image',
'toolbar',
);
@ -73,7 +73,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
'administer account settings',
'administer languages',
'administer image styles',
'administer pictures',
'administer responsive image',
'translate configuration',
);
@ -364,20 +364,20 @@ class ConfigTranslationListUiTest extends WebTestBase {
}
/**
* Tests the picture mapping listing for the translate operation.
* Tests the responsive image mapping listing for the translate operation.
*/
public function doPictureListTest() {
public function doResponsiveImageListTest() {
$edit = array();
$edit['label'] = $this->randomName();
$edit['id'] = strtolower($edit['label']);
$this->drupalPostForm('admin/config/media/picturemapping/add', $edit, t('Save'));
$this->assertRaw(t('Picture mapping %label saved.', array('%label' => $edit['label'])));
$this->drupalPostForm('admin/config/media/responsive-image-mapping/add', $edit, t('Save'));
$this->assertRaw(t('Responsive image mapping %label saved.', array('%label' => $edit['label'])));
// Get the picture mapping listing.
$this->drupalGet('admin/config/media/picturemapping');
// Get the responsive image mapping listing.
$this->drupalGet('admin/config/media/responsive-image-mapping');
$translate_link = 'admin/config/media/picturemapping/' . $edit['id'] . '/translate';
$translate_link = 'admin/config/media/responsive-image-mapping/' . $edit['id'] . '/translate';
// Test if the link to translate the style is on the page.
$this->assertLinkByHref($translate_link);
@ -474,7 +474,7 @@ class ConfigTranslationListUiTest extends WebTestBase {
$this->doUserRoleListTest();
$this->doLanguageListTest();
$this->doImageStyleListTest();
$this->doPictureListTest();
$this->doResponsiveImageListTest();
$this->doDateFormatListTest();
$this->doFieldListTest();

View File

@ -1,47 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\picture\Form\PictureMappingActionConfirm.
*/
namespace Drupal\picture\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
class PictureMappingDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the picture_mapping %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'picture.mapping_page',
);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Picture mapping %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('picture', 'Picture mapping %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'picture.mapping_page';
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\picture\Entity\PictureMappingInterface.
*/
namespace Drupal\picture;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a picture mapping entity.
*/
interface PictureMappingInterface extends ConfigEntityInterface {
/**
* Checks if there's at least one mapping defined.
*/
public function hasMappings();
}

View File

@ -1,5 +0,0 @@
picture.mapping_page_add:
route_name: picture.mapping_page_add
title: 'Add picture mapping'
appears_on:
- picture.mapping_page

View File

@ -1,5 +0,0 @@
picture.mapping_page_edit:
title: Edit
route_name: picture.mapping_page_edit
base_route: picture.mapping_page_edit
weight: -10

View File

@ -1,39 +0,0 @@
picture.mapping_page:
path: '/admin/config/media/picturemapping'
defaults:
_entity_list: 'picture_mapping'
_title: 'Picture mappings'
requirements:
_permission: 'administer pictures'
picture.mapping_page_add:
path: '/admin/config/media/picturemapping/add'
defaults:
_entity_form: 'picture_mapping.add'
_title: 'Add picture mapping'
requirements:
_permission: 'administer pictures'
picture.mapping_page_edit:
path: '/admin/config/media/picturemapping/{picture_mapping}'
defaults:
_entity_form: 'picture_mapping.edit'
_title: 'Edit picture mapping'
requirements:
_permission: 'administer pictures'
picture.mapping_page_duplicate:
path: '/admin/config/media/picturemapping/{picture_mapping}/duplicate'
defaults:
_entity_form: 'picture_mapping.duplicate'
_title: 'Duplicate picture mapping'
requirements:
_permission: 'administer pictures'
picture.mapping_action_confirm:
path: '/admin/config/media/picturemapping/{picture_mapping}/delete'
defaults:
_entity_form: 'picture_mapping.delete'
_title: 'Delete'
requirements:
_permission: 'administer pictures'

View File

@ -1,8 +1,8 @@
# Schema for the configuration files of the Picture module.
# Schema for the configuration files of the Responsive Image module.
picture.mappings.*:
responsive_image.mappings.*:
type: mapping
label: 'Picture mapping'
label: 'Responsive image mapping'
mapping:
id:
type: string
@ -38,17 +38,17 @@ picture.mappings.*:
type: string
label: 'Default language'
entity_view_display.field.picture:
entity_view_display.field.responsive_image:
type: entity_field_view_display_base
label: 'Picture list format settings'
label: 'Responsive image list format settings'
mapping:
settings:
type: mapping
label: 'Settings'
mapping:
picture_mapping:
responsive_image_mapping:
type: string
label: 'Picture mapping'
label: 'Responsive image mapping'
fallback_image_style:
type: string
label: 'Fallback image style'

View File

@ -2,67 +2,67 @@
/**
* @file
* Definition of Drupal\picture\PictureMapping.
* Definition of Drupal\responsive_image\ResponsiveImageMapping.
*/
namespace Drupal\picture\Entity;
namespace Drupal\responsive_image\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\picture\PictureMappingInterface;
use Drupal\responsive_image\ResponsiveImageMappingInterface;
/**
* Defines the Picture entity.
* Defines the responsive image mapping entity.
*
* @ConfigEntityType(
* id = "picture_mapping",
* label = @Translation("Picture mapping"),
* id = "responsive_image_mapping",
* label = @Translation("Responsive image mapping"),
* controllers = {
* "list" = "Drupal\picture\PictureMappingListController",
* "list" = "Drupal\responsive_image\ResponsiveImageMappingListController",
* "form" = {
* "edit" = "Drupal\picture\PictureMappingFormController",
* "add" = "Drupal\picture\PictureMappingFormController",
* "delete" = "Drupal\picture\Form\PictureMappingDeleteForm",
* "duplicate" = "Drupal\picture\PictureMappingFormController"
* "edit" = "Drupal\responsive_image\ResponsiveImageMappingFormController",
* "add" = "Drupal\responsive_image\ResponsiveImageMappingFormController",
* "delete" = "Drupal\responsive_image\Form\ResponsiveImageMappingDeleteForm",
* "duplicate" = "Drupal\responsive_image\ResponsiveImageMappingFormController"
* }
* },
* list_path = "admin/config/media/picturemapping",
* admin_permission = "administer pictures",
* list_path = "admin/config/media/responsive-image-mapping",
* admin_permission = "administer responsive image",
* config_prefix = "mappings",
* entity_keys = {
* "id" = "id",
* "label" = "label"
* },
* links = {
* "edit-form" = "picture.mapping_page_edit",
* "duplicate-form" = "picture.mapping_page_duplicate"
* "edit-form" = "responsive_image.mapping_page_edit",
* "duplicate-form" = "responsive_image.mapping_page_duplicate"
* }
* )
*/
class PictureMapping extends ConfigEntityBase implements PictureMappingInterface {
class ResponsiveImageMapping extends ConfigEntityBase implements ResponsiveImageMappingInterface {
/**
* The picture ID (machine name).
* The responsive image ID (machine name).
*
* @var string
*/
public $id;
/**
* The picture label.
* The responsive image label.
*
* @var string
*/
public $label;
/**
* The picture mappings.
* The responsive image mappings.
*
* @var array
*/
public $mappings = array();
/**
* The picture breakpoint group.
* The responsive image breakpoint group.
*
* @var BreakpointGroup
*/
@ -104,7 +104,7 @@ class PictureMapping extends ConfigEntityBase implements PictureMappingInterface
* Implements \Drupal\Core\Entity\EntityInterface::createDuplicate().
*/
public function createDuplicate() {
return entity_create('picture_mapping', array(
return entity_create('responsive_image_mapping', array(
'id' => '',
'label' => t('Clone of !label', array('!label' => check_plain($this->label()))),
'mappings' => $this->mappings,

View File

@ -0,0 +1,47 @@
<?php
/**
* @file
* Contains \Drupal\responsive_image\Form\ResponsiveImageMappingActionConfirm.
*/
namespace Drupal\responsive_image\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
class ResponsiveImageMappingDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the responsive image mapping %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelRoute() {
return array(
'route_name' => 'responsive_image.mapping_page',
);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('responsive_image', 'Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'responsive_image.mapping_page';
}
}

View File

@ -2,52 +2,52 @@
/**
* @file
* Contains \Drupal\picture\Plugin\field\formatter\PictureFormatter.
* Contains \Drupal\responsive_image\Plugin\field\formatter\ResponsiveImageFormatter.
*/
namespace Drupal\picture\Plugin\Field\FieldFormatter;
namespace Drupal\responsive_image\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
/**
* Plugin for picture formatter.
* Plugin for responsive image formatter.
*
* @FieldFormatter(
* id = "picture",
* label = @Translation("Picture"),
* id = "responsive_image",
* label = @Translation("Responsive image"),
* field_types = {
* "image",
* },
* settings = {
* "picture_mapping" = "",
* "responsive_image_mapping" = "",
* "fallback_image_style" = "",
* "image_link" = "",
* }
* )
*/
class PictureFormatter extends ImageFormatterBase {
class ResponsiveImageFormatter extends ImageFormatterBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$picture_options = array();
$picture_mappings = entity_load_multiple('picture_mapping');
if ($picture_mappings && !empty($picture_mappings)) {
foreach ($picture_mappings as $machine_name => $picture_mapping) {
if ($picture_mapping->hasMappings()) {
$picture_options[$machine_name] = $picture_mapping->label();
$responsive_image_options = array();
$responsive_image_mappings = entity_load_multiple('responsive_image_mapping');
if ($responsive_image_mappings && !empty($responsive_image_mappings)) {
foreach ($responsive_image_mappings as $machine_name => $responsive_image_mapping) {
if ($responsive_image_mapping->hasMappings()) {
$responsive_image_options[$machine_name] = $responsive_image_mapping->label();
}
}
}
$elements['picture_mapping'] = array(
'#title' => t('Picture mapping'),
$elements['responsive_image_mapping'] = array(
'#title' => t('Responsive image mapping'),
'#type' => 'select',
'#default_value' => $this->getSetting('picture_mapping'),
'#default_value' => $this->getSetting('responsive_image_mapping'),
'#required' => TRUE,
'#options' => $picture_options,
'#options' => $responsive_image_options,
);
$image_styles = image_style_options(FALSE);
@ -80,9 +80,9 @@ class PictureFormatter extends ImageFormatterBase {
public function settingsSummary() {
$summary = array();
$picture_mapping = entity_load('picture_mapping', $this->getSetting('picture_mapping'));
if ($picture_mapping) {
$summary[] = t('Picture mapping: @picture_mapping', array('@picture_mapping' => $picture_mapping->label()));
$responsive_image_mapping = entity_load('responsive_image_mapping', $this->getSetting('responsive_image_mapping'));
if ($responsive_image_mapping) {
$summary[] = t('Responsive image mapping: @responsive_image_mapping', array('@responsive_image_mapping' => $responsive_image_mapping->label()));
$image_styles = image_style_options(FALSE);
unset($image_styles['']);
@ -103,7 +103,7 @@ class PictureFormatter extends ImageFormatterBase {
}
}
else {
$summary[] = t('Select a picture mapping.');
$summary[] = t('Select a responsive image mapping.');
}
return $summary;
@ -117,7 +117,7 @@ class PictureFormatter extends ImageFormatterBase {
// Check if the formatter involves a link.
if ($this->getSetting('image_link') == 'content') {
$uri = $items->getEntity()->urlInfo();
// @todo Remove when theme_picture_formatter() has support for route name.
// @todo Remove when theme_responsive_image_formatter() has support for route name.
$uri['path'] = $items->getEntity()->getSystemPath();
}
elseif ($this->getSetting('image_link') == 'file') {
@ -127,15 +127,15 @@ class PictureFormatter extends ImageFormatterBase {
$breakpoint_styles = array();
$fallback_image_style = '';
$picture_mapping = entity_load('picture_mapping', $this->getSetting('picture_mapping'));
if ($picture_mapping) {
foreach ($picture_mapping->mappings as $breakpoint_name => $multipliers) {
$responsive_image_mapping = entity_load('responsive_image_mapping', $this->getSetting('responsive_image_mapping'));
if ($responsive_image_mapping) {
foreach ($responsive_image_mapping->mappings as $breakpoint_name => $multipliers) {
// Make sure there are multipliers.
if (!empty($multipliers)) {
// Make sure that the breakpoint exists and is enabled.
// @todo add the following when breakpoint->status is added again:
// $picture_mapping->breakpointGroup->breakpoints[$breakpoint_name]->status
$breakpoint = $picture_mapping->breakpointGroup->getBreakpointById($breakpoint_name);
// $responsive_image_mapping->breakpointGroup->breakpoints[$breakpoint_name]->status
$breakpoint = $responsive_image_mapping->breakpointGroup->getBreakpointById($breakpoint_name);
if ($breakpoint) {
// Determine the enabled multipliers.
$multipliers = array_intersect_key($multipliers, $breakpoint->multipliers);
@ -170,7 +170,7 @@ class PictureFormatter extends ImageFormatterBase {
);
}
$elements[$delta] = array(
'#theme' => 'picture_formatter',
'#theme' => 'responsive_image_formatter',
'#attached' => array('library' => array(
'core/picturefill',
)),

View File

@ -2,17 +2,17 @@
/**
* @file
* Contains Drupal\picture\PictureFormController.
* Contains Drupal\responsive_image\ResponsiveImageFormController.
*/
namespace Drupal\picture;
namespace Drupal\responsive_image;
use Drupal\Core\Entity\EntityFormController;
/**
* Form controller for the picture edit/add forms.
* Form controller for the responsive image edit/add forms.
*/
class PictureMappingFormController extends EntityFormController {
class ResponsiveImageMappingFormController extends EntityFormController {
/**
* Overrides Drupal\Core\Entity\EntityFormController::form().
@ -21,7 +21,7 @@ class PictureMappingFormController extends EntityFormController {
* A nested array form elements comprising the form.
* @param array $form_state
* An associative array containing the current state of the form.
* @param \Drupal\picture\PictureMappingInterface $picture_mapping
* @param \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping
* The entity being edited.
*
* @return array
@ -29,33 +29,33 @@ class PictureMappingFormController extends EntityFormController {
*/
public function form(array $form, array &$form_state) {
if ($this->operation == 'duplicate') {
$form['#title'] = $this->t('<em>Duplicate picture mapping</em> @label', array('@label' => $this->entity->label()));
$form['#title'] = $this->t('<em>Duplicate responsive image mapping</em> @label', array('@label' => $this->entity->label()));
$this->entity = $this->entity->createDuplicate();
}
if ($this->operation == 'edit') {
$form['#title'] = $this->t('<em>Edit picture mapping</em> @label', array('@label' => $this->entity->label()));
$form['#title'] = $this->t('<em>Edit responsive image mapping</em> @label', array('@label' => $this->entity->label()));
}
$picture_mapping = $this->entity;
$responsive_image_mapping = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $picture_mapping->label(),
'#default_value' => $responsive_image_mapping->label(),
'#description' => $this->t("Example: 'Hero image' or 'Author image'."),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $picture_mapping->id(),
'#default_value' => $responsive_image_mapping->id(),
'#machine_name' => array(
'exists' => 'picture_mapping_load',
'exists' => 'responsive_image_mapping_load',
'source' => array('label'),
),
'#disabled' => (bool) $picture_mapping->id() && $this->operation != 'duplicate',
'#disabled' => (bool) $responsive_image_mapping->id() && $this->operation != 'duplicate',
);
if ((bool) $picture_mapping->id() && $this->operation != 'duplicate') {
if ((bool) $responsive_image_mapping->id() && $this->operation != 'duplicate') {
$description = $this->t('Select a breakpoint group from the enabled themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected mappings.");
}
else {
@ -64,16 +64,16 @@ class PictureMappingFormController extends EntityFormController {
$form['breakpointGroup'] = array(
'#type' => 'select',
'#title' => $this->t('Breakpoint group'),
'#default_value' => !empty($picture_mapping->breakpointGroup) ? $picture_mapping->breakpointGroup->id() : '',
'#default_value' => !empty($responsive_image_mapping->breakpointGroup) ? $responsive_image_mapping->breakpointGroup->id() : '',
'#options' => breakpoint_group_select_options(),
'#required' => TRUE,
'#description' => $description,
);
$image_styles = image_style_options(TRUE);
foreach ($picture_mapping->mappings as $breakpoint_id => $mapping) {
foreach ($responsive_image_mapping->mappings as $breakpoint_id => $mapping) {
foreach ($mapping as $multiplier => $image_style) {
$breakpoint = $picture_mapping->breakpointGroup->getBreakpointById($breakpoint_id);
$breakpoint = $responsive_image_mapping->breakpointGroup->getBreakpointById($breakpoint_id);
$label = $multiplier . ' ' . $breakpoint->name . ' [' . $breakpoint->mediaQuery . ']';
$form['mappings'][$breakpoint_id][$multiplier] = array(
'#type' => 'select',
@ -87,7 +87,7 @@ class PictureMappingFormController extends EntityFormController {
$form['#tree'] = TRUE;
return parent::form($form, $form_state, $picture_mapping);
return parent::form($form, $form_state, $responsive_image_mapping);
}
/**
@ -113,11 +113,11 @@ class PictureMappingFormController extends EntityFormController {
* Overrides Drupal\Core\Entity\EntityFormController::validate().
*/
public function validate(array $form, array &$form_state) {
$picture_mapping = $this->entity;
$responsive_image_mapping = $this->entity;
// Only validate on edit.
if (isset($form_state['values']['mappings'])) {
$picture_mapping->mappings = $form_state['values']['mappings'];
$responsive_image_mapping->mappings = $form_state['values']['mappings'];
// Check if another breakpoint group is selected.
if ($form_state['values']['breakpointGroup'] != $form_state['complete_form']['breakpointGroup']['#default_value']) {
@ -125,7 +125,7 @@ class PictureMappingFormController extends EntityFormController {
unset($form_state['values']['mappings']);
}
// Make sure at least one mapping is defined.
elseif (!$picture_mapping->isNew() && !$picture_mapping->hasMappings()) {
elseif (!$responsive_image_mapping->isNew() && !$responsive_image_mapping->hasMappings()) {
$this->setFormError('mappings', $form_state, $this->t('Please select at least one mapping.'));
}
}
@ -135,24 +135,24 @@ class PictureMappingFormController extends EntityFormController {
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
public function save(array $form, array &$form_state) {
$picture_mapping = $this->entity;
$picture_mapping->save();
$responsive_image_mapping = $this->entity;
$responsive_image_mapping->save();
watchdog('picture', 'Picture mapping @label saved.', array('@label' => $picture_mapping->label()), WATCHDOG_NOTICE);
drupal_set_message($this->t('Picture mapping %label saved.', array('%label' => $picture_mapping->label())));
watchdog('responsive_image', 'Responsive image mapping @label saved.', array('@label' => $responsive_image_mapping->label()), WATCHDOG_NOTICE);
drupal_set_message($this->t('Responsive image mapping %label saved.', array('%label' => $responsive_image_mapping->label())));
// Redirect to edit form after creating a new mapping or after selecting
// another breakpoint group.
if (!$picture_mapping->hasMappings()) {
if (!$responsive_image_mapping->hasMappings()) {
$form_state['redirect_route'] = array(
'route_name' => 'picture.mapping_page_edit',
'route_name' => 'responsive_image.mapping_page_edit',
'route_parameters' => array(
'picture_mapping' => $picture_mapping->id(),
'responsive_image_mapping' => $responsive_image_mapping->id(),
),
);
}
else {
$form_state['redirect_route']['route_name'] = 'picture.mapping_page';
$form_state['redirect_route']['route_name'] = 'responsive_image.mapping_page';
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @file
* Contains \Drupal\responsive_image\Entity\ResponsiveImageMappingInterface.
*/
namespace Drupal\responsive_image;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a responsive image mapping entity.
*/
interface ResponsiveImageMappingInterface extends ConfigEntityInterface {
/**
* Checks if there's at least one mapping defined.
*/
public function hasMappings();
}

View File

@ -2,18 +2,18 @@
/**
* @file
* Contains Drupal\picture\PictureListController.
* Contains Drupal\responsive_image\ResponsiveImageListController.
*/
namespace Drupal\picture;
namespace Drupal\responsive_image;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of Pictures.
* Provides a listing of responsive image mappings.
*/
class PictureMappingListController extends ConfigEntityListController {
class ResponsiveImageMappingListController extends ConfigEntityListController {
/**
* {@inheritdoc}

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\picture\Tests\PictureAdminUITest.
* Definition of Drupal\responsive_image\Tests\ResponsiveImageAdminUITest.
*/
namespace Drupal\picture\Tests;
namespace Drupal\responsive_image\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\breakpoint\Entity\Breakpoint;
@ -13,23 +13,23 @@ use Drupal\breakpoint\Entity\Breakpoint;
/**
* Tests for breakpoint sets admin interface.
*/
class PictureAdminUITest extends WebTestBase {
class ResponsiveImageAdminUITest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('picture');
public static $modules = array('responsive_image');
/**
* Drupal\simpletest\WebTestBase\getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Picture administration functionality',
'description' => 'Thoroughly test the administrative interface of the picture module.',
'group' => 'Picture',
'name' => 'Responsive Image administration functionality',
'description' => 'Thoroughly test the administrative interface of the responsive image module.',
'group' => 'Responsive Image',
);
}
@ -41,7 +41,7 @@ class PictureAdminUITest extends WebTestBase {
// Create user.
$this->admin_user = $this->drupalCreateUser(array(
'administer pictures',
'administer responsive image',
));
$this->drupalLogin($this->admin_user);
@ -74,15 +74,15 @@ class PictureAdminUITest extends WebTestBase {
}
/**
* Test picture administration functionality.
* Test responsive image administration functionality.
*/
public function testPictureAdmin() {
public function testResponsiveImageAdmin() {
// We start without any default mappings.
$this->drupalGet('admin/config/media/picturemapping');
$this->assertText('There is no Picture mapping yet.');
$this->drupalGet('admin/config/media/responsive-image-mapping');
$this->assertText('There is no Responsive image mapping yet.');
// Add a new picture mapping, our breakpoint set should be selected.
$this->drupalGet('admin/config/media/picturemapping/add');
// Add a new responsive_image mapping, our breakpoint set should be selected.
$this->drupalGet('admin/config/media/responsive-image-mapping/add');
$this->assertFieldByName('breakpointGroup', 'atestset');
// Create a new group.
@ -91,17 +91,17 @@ class PictureAdminUITest extends WebTestBase {
'id' => 'mapping_one',
'breakpointGroup' => 'atestset',
);
$this->drupalPostForm('admin/config/media/picturemapping/add', $edit, t('Save'));
$this->drupalPostForm('admin/config/media/responsive-image-mapping/add', $edit, t('Save'));
// Check if the new group is created.
$this->assertResponse(200);
$this->drupalGet('admin/config/media/picturemapping');
$this->assertNoText('There is no Picture mapping yet.');
$this->drupalGet('admin/config/media/responsive-image-mapping');
$this->assertNoText('There is no Responsive image mapping yet.');
$this->assertText('Mapping One');
$this->assertText('mapping_one');
// Edit the group.
$this->drupalGet('admin/config/media/picturemapping/mapping_one');
$this->drupalGet('admin/config/media/responsive-image-mapping/mapping_one');
$this->assertFieldByName('label', 'Mapping One');
$this->assertFieldByName('breakpointGroup', 'atestset');
@ -121,8 +121,8 @@ class PictureAdminUITest extends WebTestBase {
'mappings[custom.user.medium][1x]' => 'medium',
'mappings[custom.user.large][1x]' => 'large',
);
$this->drupalPostForm('admin/config/media/picturemapping/mapping_one', $edit, t('Save'));
$this->drupalGet('admin/config/media/picturemapping/mapping_one');
$this->drupalPostForm('admin/config/media/responsive-image-mapping/mapping_one', $edit, t('Save'));
$this->drupalGet('admin/config/media/responsive-image-mapping/mapping_one');
$this->assertFieldByName('mappings[custom.user.small][1x]', 'thumbnail');
$this->assertFieldByName('mappings[custom.user.small][2x]', '');
$this->assertFieldByName('mappings[custom.user.medium][1x]', 'medium');
@ -131,10 +131,10 @@ class PictureAdminUITest extends WebTestBase {
$this->assertFieldByName('mappings[custom.user.large][2x]', '');
// Delete the mapping.
$this->drupalGet('admin/config/media/picturemapping/mapping_one/delete');
$this->drupalGet('admin/config/media/responsive-image-mapping/mapping_one/delete');
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->drupalGet('admin/config/media/picturemapping');
$this->assertText('There is no Picture mapping yet.');
$this->drupalGet('admin/config/media/responsive-image-mapping');
$this->assertText('There is no Responsive image mapping yet.');
}
}

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\picture\Tests\PictureFieldDisplayTest.
* Definition of Drupal\responsive_image\Tests\ResponsiveImageFieldDisplayTest.
*/
namespace Drupal\picture\Tests;
namespace Drupal\responsive_image\Tests;
use Drupal\Core\Language\Language;
use Drupal\breakpoint\Entity\Breakpoint;
@ -14,23 +14,23 @@ use Drupal\image\Tests\ImageFieldTestBase;
/**
* Test class to check that formatters and display settings are working.
*/
class PictureFieldDisplayTest extends ImageFieldTestBase {
class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('field_ui', 'picture');
public static $modules = array('field_ui', 'responsive_image');
/**
* Drupal\simpletest\WebTestBase\getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Picture field display tests',
'description' => 'Test picture display formatter.',
'group' => 'Picture',
'name' => 'Responsive Image field display tests',
'description' => 'Test responsive image display formatter.',
'group' => 'Responsive Image',
);
}
@ -42,7 +42,7 @@ class PictureFieldDisplayTest extends ImageFieldTestBase {
// Create user.
$this->admin_user = $this->drupalCreateUser(array(
'administer pictures',
'administer responsive image',
'access content',
'access administration pages',
'administer site configuration',
@ -81,39 +81,39 @@ class PictureFieldDisplayTest extends ImageFieldTestBase {
}
$breakpoint_group->save();
// Add picture mapping.
$picture_mapping = entity_create('picture_mapping', array(
// Add responsive image mapping.
$responsive_image_mapping = entity_create('responsive_image_mapping', array(
'id' => 'mapping_one',
'label' => 'Mapping One',
'breakpointGroup' => 'atestset',
));
$picture_mapping->save();
$picture_mapping->mappings['custom.user.small']['1x'] = 'thumbnail';
$picture_mapping->mappings['custom.user.medium']['1x'] = 'medium';
$picture_mapping->mappings['custom.user.large']['1x'] = 'large';
$picture_mapping->save();
$responsive_image_mapping->save();
$responsive_image_mapping->mappings['custom.user.small']['1x'] = 'thumbnail';
$responsive_image_mapping->mappings['custom.user.medium']['1x'] = 'medium';
$responsive_image_mapping->mappings['custom.user.large']['1x'] = 'large';
$responsive_image_mapping->save();
}
/**
* Test picture formatters on node display for public files.
* Test responsive image formatters on node display for public files.
*/
public function testPictureFieldFormattersPublic() {
$this->_testPictureFieldFormatters('public');
public function testResponsiveImageFieldFormattersPublic() {
$this->_testResponsiveImageFieldFormatters('public');
}
/**
* Test picture formatters on node display for private files.
* Test responsive image formatters on node display for private files.
*/
public function testPictureFieldFormattersPrivate() {
public function testResponsiveImageFieldFormattersPrivate() {
// Remove access content permission from anonymous users.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array('access content' => FALSE));
$this->_testPictureFieldFormatters('private');
$this->_testResponsiveImageFieldFormatters('private');
}
/**
* Test picture formatters on node display.
* Test responsive image formatters on node display.
*/
public function _testPictureFieldFormatters($scheme) {
public function _testResponsiveImageFieldFormatters($scheme) {
$field_name = drupal_strtolower($this->randomName());
$this->createImageField($field_name, 'article', array('uri_scheme' => $scheme));
// Create a new node with an image attached.
@ -132,10 +132,10 @@ class PictureFieldDisplayTest extends ImageFieldTestBase {
$default_output = drupal_render($image);
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Use the picture formatter linked to file formatter.
// Use the responsive image formatter linked to file formatter.
$display_options = array(
'type' => 'picture',
'module' => 'picture',
'type' => 'responsive_image',
'module' => 'responsive_image',
'settings' => array('image_link' => 'file'),
);
$display = entity_get_display('node', 'article', 'default');
@ -168,8 +168,8 @@ class PictureFieldDisplayTest extends ImageFieldTestBase {
$this->drupalLogin($this->admin_user);
}
// Use the picture formatter with a picture mapping.
$display_options['settings']['picture_mapping'] = 'mapping_one';
// Use the responsive image formatter with a responsive image mapping.
$display_options['settings']['responsive_image_mapping'] = 'mapping_one';
$display->setComponent($field_name, $display_options)
->save();

View File

@ -1,4 +1,4 @@
name: Picture
name: Responsive Image
type: module
description: 'Provides an image formatter and breakpoint mappings to output responsive images using the HTML5 picture tag.'
package: Core
@ -7,4 +7,4 @@ core: 8.x
dependencies:
- breakpoint
- image
configure: picture.mapping_page
configure: responsive_image.mapping_page

View File

@ -0,0 +1,5 @@
responsive_image.mapping_page_add:
route_name: responsive_image.mapping_page_add
title: 'Add responsive image mapping'
appears_on:
- responsive_image.mapping_page

View File

@ -0,0 +1,5 @@
responsive_image.mapping_page_edit:
title: Edit
route_name: responsive_image.mapping_page_edit
base_route: responsive_image.mapping_page_edit
weight: -10

View File

@ -2,31 +2,31 @@
/**
* @file
* Picture display formatter for image fields.
* Responsive image display formatter for image fields.
*/
use Drupal\picture\Entity\PictureMapping;
use Drupal\responsive_image\Entity\ResponsiveImageMapping;
use \Drupal\Core\Template\Attribute;
/**
* Implements hook_help().
*/
function picture_help($path, $arg) {
function responsive_image_help($path, $arg) {
$output = '';
switch ($path) {
case 'admin/help#picture':
case 'admin/help#responsive_image':
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Picture module provides an image formatter and breakpoint mappings to output responsive images using the HTML5 picture tag. For more information, see the <a href="!picture">online documentation for the Picture module</a>.', array( '!picture' => 'https://drupal.org/documentation/modules/picture')) . '</p>';
$output .= '<p>' . t('The Responsive Image module provides an image formatter and breakpoint mappings to output responsive images using the HTML5 picture tag. For more information, see the <a href="!responsive_image">online documentation for the Responsive Image module</a>.', array( '!responsive_image' => 'https://drupal.org/documentation/modules/responsive_image')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Defining picture mappings') . '</dt>';
$output .= '<dd>' . t('By creating picture mappings you define the image styles that are being used to output images at certain breakpoints. On the <a href="!picture_mapping">Picture mappings</a> page, click <em>Add picture mapping</em> to create a new mapping. First chose a label and a breakpoint group and click Save. After that you can choose the image styles that will be used for each breakpoint. Image styles can be defined on the <a href="!image_styles">Image styles page</a> that is provided by the <a href="!image_help">Image module</a>. Breakpoints are defined in the configuration files of the theme. See the <a href="!breakpoint_help">help page of the Breakpoint module</a> for more information.', array('!picture_mapping' => \Drupal::url('picture.mapping_page'), '!image_styles' => \Drupal::url('image.style_list'),'!image_help' => \Drupal::url('help.page', array('name' => 'image')), '!breakpoint_help' => \Drupal::url('help.page', array('name' => 'breakpoint')))) . '</dd>';
$output .= '<dt>' . t('Using picture mappings in image fields') . '</dt>';
$output .= '<dd>' . t('After defining picture mappings, you can use them in the display settings for your image fields, so that the site displays responsive images using the HTML5 picture tag. Open the Manage display page for the entity type (content type, taxonomy vocabulary, etc.) that the Image field is attached to. Choose the format <em>Picture</em>, click the Edit icon and select one of the picture mappings that you have created. For general information on how to manage fields and their display see the <a href="!field_ui">help page of the Field UI module</a>. For information about entities see the <a href="!entity_help">help page of the Entity module</a>.', array('!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')),'!entity_help' => \Drupal::url('help.page', array('name' => 'entity')))) . '</dd>';
$output .= '<dt>' . t('Defining responsive image mappings') . '</dt>';
$output .= '<dd>' . t('By creating responsive image mappings you define the image styles that are being used to output images at certain breakpoints. On the <a href="!responsive_image_mapping">Responsive image mappings</a> page, click <em>Add responsive image mapping</em> to create a new mapping. First chose a label and a breakpoint group and click Save. After that you can choose the image styles that will be used for each breakpoint. Image styles can be defined on the <a href="!image_styles">Image styles page</a> that is provided by the <a href="!image_help">Image module</a>. Breakpoints are defined in the configuration files of the theme. See the <a href="!breakpoint_help">help page of the Breakpoint module</a> for more information.', array('!responsive_image_mapping' => \Drupal::url('responsive_image.mapping_page'), '!image_styles' => \Drupal::url('image.style_list'),'!image_help' => \Drupal::url('help.page', array('name' => 'image')), '!breakpoint_help' => \Drupal::url('help.page', array('name' => 'breakpoint')))) . '</dd>';
$output .= '<dt>' . t('Using responsive image mappings in Image fields') . '</dt>';
$output .= '<dd>' . t('After defining responsive image mappings, you can use them in the display settings for your Image fields, so that the site displays responsive images using the HTML5 picture tag. Open the Manage display page for the entity type (content type, taxonomy vocabulary, etc.) that the Image field is attached to. Choose the format <em>Responsive image</em>, click the Edit icon, and select one of the responsive image mappings that you have created. For general information on how to manage fields and their display see the <a href="!field_ui">help page of the Field UI module</a>. For information about entities see the <a href="!entity_help">help page of the Entity module</a>.', array('!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')),'!entity_help' => \Drupal::url('help.page', array('name' => 'entity')))) . '</dd>';
$output .= '</dl>';
break;
case 'admin/config/media/picturemapping':
$output .= '<p>' . t('A picture mapping associates an image style with each breakpoint defined by your theme.') . '</p>';
case 'admin/config/media/responsive-image-mapping':
$output .= '<p>' . t('A responsive image mapping associates an image style with each breakpoint defined by your theme.') . '</p>';
break;
}
@ -36,24 +36,47 @@ function picture_help($path, $arg) {
/**
* Implements hook_permission().
*/
function picture_permission() {
function responsive_image_permission() {
return array(
'administer pictures' => array(
'title' => t('Administer Pictures'),
'description' => t('Administer Pictures'),
'administer responsive image' => array(
'title' => t('Administer responsive images'),
),
);
}
/**
* Implements hook_menu().
*/
function responsive_image_menu() {
$items = array();
$items['admin/config/media/responsive-image-mapping'] = array(
'title' => 'Responsive image mappings',
'description' => 'Manage responsive image mappings',
'weight' => 10,
'route_name' => 'responsive_image.mapping_page',
);
$items['admin/config/media/responsive-image-mapping/%responsive_image_mapping'] = array(
'title' => 'Edit responsive image mapping',
'route_name' => 'responsive_image.mapping_page_edit',
);
$items['admin/config/media/responsive-image-mapping/%responsive_image_mapping/duplicate'] = array(
'title' => 'Duplicate responsive image mapping',
'route_name' => 'responsive_image.mapping_page_duplicate',
);
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function picture_menu_link_defaults() {
$links['picture.admin.config.picturemapping'] = array(
'link_title' => 'Picture Mappings',
'description' => 'Manage picture mappings',
function responsive_image_menu_link_defaults() {
$links['responsive_image.admin.config.responsive_imagemapping'] = array(
'link_title' => 'Responsive image mappings',
'description' => 'Manage responsive image mappings',
'weight' => 10,
'route_name' => 'picture.mapping_page',
'route_name' => 'responsive_image.mapping_page',
'parent' => 'system.admin.config.media',
);
@ -61,12 +84,12 @@ function picture_menu_link_defaults() {
}
/**
* Load one picture by its identifier.
* Load one responsive image by its identifier.
*
* @param int $id
* The id of the picture mapping to load.
* The id of the responsive image mapping to load.
*
* @return \Drupal\picture\Picture
* @return \Drupal\responsive_image\ResponsiveImageMappingInterface
* The entity object, or NULL if there is no entity with the given id.
*
* @todo Needed for menu_callback
@ -74,16 +97,16 @@ function picture_menu_link_defaults() {
* @see http://drupal.org/node/1798214
*
*/
function picture_mapping_load($id) {
return entity_load('picture_mapping', $id);
function responsive_image_mapping_load($id) {
return entity_load('responsive_image_mapping', $id);
}
/**
* Implements hook_theme().
*/
function picture_theme() {
function responsive_image_theme() {
return array(
'picture' => array(
'responsive_image' => array(
'variables' => array(
'style_name' => NULL,
'uri' => NULL,
@ -95,7 +118,7 @@ function picture_theme() {
'breakpoints' => array(),
),
),
'picture_formatter' => array(
'responsive_image_formatter' => array(
'variables' => array(
'item' => NULL,
'path' => NULL,
@ -103,7 +126,7 @@ function picture_theme() {
'breakpoints' => array(),
),
),
'picture_source' => array(
'responsive_image_source' => array(
'variables' => array(
'src' => NULL,
'srcset' => NULL,
@ -115,7 +138,7 @@ function picture_theme() {
}
/**
* Returns HTML for a picture field formatter.
* Returns HTML for a responsive image field formatter.
*
* @param array $variables
* An associative array containing:
@ -126,7 +149,7 @@ function picture_theme() {
*
* @ingroup themeable
*/
function theme_picture_formatter($variables) {
function theme_responsive_image_formatter($variables) {
$item = $variables['item'];
if (!isset($variables['breakpoints']) || empty($variables['breakpoints'])) {
$image_formatter = array(
@ -138,37 +161,37 @@ function theme_picture_formatter($variables) {
return drupal_render($image_formatter);
}
$picture = array(
'#theme' => 'picture',
$responsive_image = array(
'#theme' => 'responsive_image',
'#width' => $item->width,
'#height' => $item->height,
'#style_name' => $variables['image_style'],
'#breakpoints' => $variables['breakpoints'],
);
if (isset($item->uri)) {
$picture['#uri'] = $item->uri;
$responsive_image['#uri'] = $item->uri;
}
elseif ($entity = $item->entity) {
$picture['#uri'] = $entity->getFileUri();
$picture['#entity'] = $entity;
$responsive_image['#uri'] = $entity->getFileUri();
$responsive_image['#entity'] = $entity;
}
$picture['#alt'] = $item->alt;
$responsive_image['#alt'] = $item->alt;
if (drupal_strlen($item->title) != 0) {
$picture['#title'] = $item->title;
$responsive_image['#title'] = $item->title;
}
// @todo Add support for route names.
if (isset($variables['path']['path'])) {
$path = $variables['path']['path'];
$options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
$options['html'] = TRUE;
return l($picture, $path, $options);
return l($responsive_image, $path, $options);
}
return drupal_render($picture);
return drupal_render($responsive_image);
}
/**
* Returns HTML for a picture.
* Returns HTML for a responsive image.
*
* @param $variables
* An associative array containing:
@ -181,7 +204,7 @@ function theme_picture_formatter($variables) {
*
* @ingroup themeable
*/
function theme_picture($variables) {
function theme_responsive_image($variables) {
// Make sure that width and height are proper values
// If they exists we'll output them
// @see http://www.w3.org/community/respimg/2012/06/18/florians-compromise/
@ -200,7 +223,7 @@ function theme_picture($variables) {
// Fallback image, output as source with media query.
$sources[] = array(
'src' => entity_load('image_style', $variables['style_name'])->buildUrl($variables['uri']),
'dimensions' => picture_get_image_dimensions($variables),
'dimensions' => responsive_image_get_image_dimensions($variables),
);
// All breakpoints and multipliers.
@ -219,7 +242,7 @@ function theme_picture($variables) {
if (count($new_sources) == 1) {
$sources[] = array(
'src' => entity_load('image_style', $new_sources[0]['style_name'])->buildUrl($new_sources[0]['uri']),
'dimensions' => picture_get_image_dimensions($new_sources[0]),
'dimensions' => responsive_image_get_image_dimensions($new_sources[0]),
'media' => $breakpoint->mediaQuery,
);
}
@ -231,7 +254,7 @@ function theme_picture($variables) {
}
$sources[] = array(
'srcset' => implode(', ', $srcset),
'dimensions' => picture_get_image_dimensions($new_sources[0]),
'dimensions' => responsive_image_get_image_dimensions($new_sources[0]),
'media' => $breakpoint->mediaQuery,
);
}
@ -249,18 +272,18 @@ function theme_picture($variables) {
// Add source tags to the output.
foreach ($sources as $source) {
$picture_source = array(
'#theme' => 'picture_source',
$responsive_image_source = array(
'#theme' => 'responsive_image_source',
'#src' => $source['src'],
'#dimensions' => $source['dimensions'],
);
if (isset($source['media'])) {
$picture_source['#media'] = $source['media'];
$responsive_image_source['#media'] = $source['media'];
}
if (isset($source['srcset'])) {
$picture_source['#srcset'] = $source['srcset'];
$responsive_image_source['#srcset'] = $source['srcset'];
}
$output[] = drupal_render($picture_source);
$output[] = drupal_render($responsive_image_source);
}
// Output the fallback image.
@ -295,7 +318,7 @@ function theme_picture($variables) {
*
* @ingroup themeable
*/
function theme_picture_source($variables) {
function theme_responsive_image_source($variables) {
$output = array();
if (isset($variables['media']) && !empty($variables['media'])) {
if (!isset($variables['srcset'])) {
@ -327,7 +350,7 @@ function theme_picture_source($variables) {
* Dimensions to be modified - an array with components width and height, in
* pixels.
*/
function picture_get_image_dimensions($variables) {
function responsive_image_get_image_dimensions($variables) {
// Determine the dimensions of the styled image.
$dimensions = array(
'width' => $variables['width'],

View File

@ -0,0 +1,39 @@
responsive_image.mapping_page:
path: '/admin/config/media/responsive-image-mapping'
defaults:
_entity_list: 'responsive_image_mapping'
_title: 'Responsive image mappings'
requirements:
_permission: 'administer responsive image'
responsive_image.mapping_page_add:
path: '/admin/config/media/responsive-image-mapping/add'
defaults:
_entity_form: 'responsive_image_mapping.add'
_title: 'Add responsive image mapping'
requirements:
_permission: 'administer responsive image'
responsive_image.mapping_page_edit:
path: '/admin/config/media/responsive-image-mapping/{responsive_image_mapping}'
defaults:
_entity_form: 'responsive_image_mapping.edit'
_title: 'Edit responsive image mapping'
requirements:
_permission: 'administer responsive image'
responsive_image.mapping_page_duplicate:
path: '/admin/config/media/responsive-image-mapping/{responsive_image_mapping}/duplicate'
defaults:
_entity_form: 'responsive_image_mapping.duplicate'
_title: 'Duplicate responsive image mapping'
requirements:
_permission: 'administer responsive image'
responsive_image.mapping_action_confirm:
path: '/admin/config/media/responsive-image-mapping/{responsive_image_mapping}/delete'
defaults:
_entity_form: 'responsive_image_mapping.delete'
_title: 'Delete'
requirements:
_permission: 'administer responsive image'