diff --git a/core/MAINTAINERS.txt b/core/MAINTAINERS.txt index 28153ec4f0a69cb2030bdc8affcf0702f2d8519a..b5fb137b968912c34c6532dfe7060edddc9b6059 100644 --- a/core/MAINTAINERS.txt +++ b/core/MAINTAINERS.txt @@ -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 diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationListUiTest.php b/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationListUiTest.php index 03ba59b0550cc507eecfaee9237c83c20df3d260..06ede2db0f09b32c6c9972c5c4cb9636d7476399 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationListUiTest.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Tests/ConfigTranslationListUiTest.php @@ -35,7 +35,7 @@ class ConfigTranslationListUiTest extends WebTestBase { 'shortcut', 'taxonomy', 'image', - 'picture', + 'responsive_image', 'toolbar', ); @@ -73,7 +73,7 @@ public function setUp() { 'administer account settings', 'administer languages', 'administer image styles', - 'administer pictures', + 'administer responsive image', 'translate configuration', ); @@ -364,20 +364,20 @@ public function doImageStyleListTest() { } /** - * 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 @@ public function testTranslateOperationInListUi() { $this->doUserRoleListTest(); $this->doLanguageListTest(); $this->doImageStyleListTest(); - $this->doPictureListTest(); + $this->doResponsiveImageListTest(); $this->doDateFormatListTest(); $this->doFieldListTest(); diff --git a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php deleted file mode 100644 index ba47dd0a569acff8fdf961e4f7cc97ad9e566a4a..0000000000000000000000000000000000000000 --- a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php +++ /dev/null @@ -1,47 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingInterface.php b/core/modules/picture/lib/Drupal/picture/PictureMappingInterface.php deleted file mode 100644 index ca03918511a09cd6cb211468dc8e18c266e7bd2c..0000000000000000000000000000000000000000 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - '', 'label' => t('Clone of !label', array('!label' => check_plain($this->label()))), 'mappings' => $this->mappings, diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/Form/ResponsiveImageMappingDeleteForm.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Form/ResponsiveImageMappingDeleteForm.php new file mode 100644 index 0000000000000000000000000000000000000000..0e227a5234e7be4c2adbc462a24e0ee310668ca5 --- /dev/null +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Form/ResponsiveImageMappingDeleteForm.php @@ -0,0 +1,47 @@ + $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'; + } + +} diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php similarity index 68% rename from core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php rename to core/modules/responsive_image/lib/Drupal/responsive_image/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php index a6d3b9c83dc18b1e311356ac4d03eebabafade34..8f935c01f97d5d22e91493d56728c40247472f1a 100644 --- a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php @@ -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 @@ public function settingsForm(array $form, array &$form_state) { 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 @@ public function settingsSummary() { } } else { - $summary[] = t('Select a picture mapping.'); + $summary[] = t('Select a responsive image mapping.'); } return $summary; @@ -117,7 +117,7 @@ public function viewElements(FieldItemListInterface $items) { // 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 @@ public function viewElements(FieldItemListInterface $items) { $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 @@ public function viewElements(FieldItemListInterface $items) { ); } $elements[$delta] = array( - '#theme' => 'picture_formatter', + '#theme' => 'responsive_image_formatter', '#attached' => array('library' => array( 'core/picturefill', )), diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingFormController.php similarity index 62% rename from core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php rename to core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingFormController.php index 1e4b106f65fc3dbe5bedb677d2f1298b9433c378..d27db527626ea30f8522a334eb2e6304c772c1e6 100644 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingFormController.php @@ -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('Duplicate picture mapping @label', array('@label' => $this->entity->label())); + $form['#title'] = $this->t('Duplicate responsive image mapping @label', array('@label' => $this->entity->label())); $this->entity = $this->entity->createDuplicate(); } if ($this->operation == 'edit') { - $form['#title'] = $this->t('Edit picture mapping @label', array('@label' => $this->entity->label())); + $form['#title'] = $this->t('Edit responsive image mapping @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 @@ public function form(array $form, array &$form_state) { $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 @@ public function form(array $form, array &$form_state) { $form['#tree'] = TRUE; - return parent::form($form, $form_state, $picture_mapping); + return parent::form($form, $form_state, $responsive_image_mapping); } /** @@ -113,11 +113,11 @@ protected function actions(array $form, array &$form_state) { * 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 @@ public function validate(array $form, array &$form_state) { 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 @@ public function validate(array $form, array &$form_state) { * 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'; } } diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingInterface.php b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..2ec9832a1cdcb33bf38669026f25bad13e2b1519 --- /dev/null +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingInterface.php @@ -0,0 +1,22 @@ + '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 @@ public function setUp() { // Create user. $this->admin_user = $this->drupalCreateUser(array( - 'administer pictures', + 'administer responsive image', )); $this->drupalLogin($this->admin_user); @@ -74,15 +74,15 @@ public function setUp() { } /** - * 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 @@ public function testPictureAdmin() { '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 @@ public function testPictureAdmin() { '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 @@ public function testPictureAdmin() { $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.'); } } diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php similarity index 77% rename from core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php rename to core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php index 7c11a6fd30e1d432375b18df788a7cd5abce4a2b..c643774358baeea2c993b05c61eb57801ff7cfb9 100644 --- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageFieldDisplayTest.php @@ -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 @@ /** * 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 @@ public function setUp() { // 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 @@ public function setUp() { } $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 @@ public function _testPictureFieldFormatters($scheme) { $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 @@ public function _testPictureFieldFormatters($scheme) { $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(); diff --git a/core/modules/picture/picture.info.yml b/core/modules/responsive_image/responsive_image.info.yml similarity index 77% rename from core/modules/picture/picture.info.yml rename to core/modules/responsive_image/responsive_image.info.yml index 456d8a7b151937c48f5101761f7287677fe513a9..1991dc3361d050fa7054b7bea4785f6a407dee5b 100644 --- a/core/modules/picture/picture.info.yml +++ b/core/modules/responsive_image/responsive_image.info.yml @@ -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 diff --git a/core/modules/responsive_image/responsive_image.local_actions.yml b/core/modules/responsive_image/responsive_image.local_actions.yml new file mode 100644 index 0000000000000000000000000000000000000000..302437e006dbdcba9a1840006b12f7c0fc373d1e --- /dev/null +++ b/core/modules/responsive_image/responsive_image.local_actions.yml @@ -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 diff --git a/core/modules/responsive_image/responsive_image.local_tasks.yml b/core/modules/responsive_image/responsive_image.local_tasks.yml new file mode 100644 index 0000000000000000000000000000000000000000..7f09a7395294133249037fd95b322293f5c95604 --- /dev/null +++ b/core/modules/responsive_image/responsive_image.local_tasks.yml @@ -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 diff --git a/core/modules/picture/picture.module b/core/modules/responsive_image/responsive_image.module similarity index 58% rename from core/modules/picture/picture.module rename to core/modules/responsive_image/responsive_image.module index f7aecacce0b4b5d151a2329c827b5616372db096..bc0b431a0c691f6e030e69665489d580c9a77000 100644 --- a/core/modules/picture/picture.module +++ b/core/modules/responsive_image/responsive_image.module @@ -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 .= '

' . t('About') . '

'; - $output .= '

' . 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 online documentation for the Picture module.', array( '!picture' => 'https://drupal.org/documentation/modules/picture')) . '

'; + $output .= '

' . 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 online documentation for the Responsive Image module.', array( '!responsive_image' => 'https://drupal.org/documentation/modules/responsive_image')) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; - $output .= '
' . t('Defining picture mappings') . '
'; - $output .= '
' . t('By creating picture mappings you define the image styles that are being used to output images at certain breakpoints. On the Picture mappings page, click Add picture mapping 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 Image styles page that is provided by the Image module. Breakpoints are defined in the configuration files of the theme. See the help page of the Breakpoint module 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')))) . '
'; - $output .= '
' . t('Using picture mappings in image fields') . '
'; - $output .= '
' . 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 Picture, 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 help page of the Field UI module. For information about entities see the help page of the Entity module.', array('!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')),'!entity_help' => \Drupal::url('help.page', array('name' => 'entity')))) . '
'; + $output .= '
' . t('Defining responsive image mappings') . '
'; + $output .= '
' . t('By creating responsive image mappings you define the image styles that are being used to output images at certain breakpoints. On the Responsive image mappings page, click Add responsive image mapping 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 Image styles page that is provided by the Image module. Breakpoints are defined in the configuration files of the theme. See the help page of the Breakpoint module 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')))) . '
'; + $output .= '
' . t('Using responsive image mappings in Image fields') . '
'; + $output .= '
' . 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 Responsive image, 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 help page of the Field UI module. For information about entities see the help page of the Entity module.', array('!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')),'!entity_help' => \Drupal::url('help.page', array('name' => 'entity')))) . '
'; $output .= '
'; break; - case 'admin/config/media/picturemapping': - $output .= '

' . t('A picture mapping associates an image style with each breakpoint defined by your theme.') . '

'; + case 'admin/config/media/responsive-image-mapping': + $output .= '

' . t('A responsive image mapping associates an image style with each breakpoint defined by your theme.') . '

'; 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'], diff --git a/core/modules/responsive_image/responsive_image.routing.yml b/core/modules/responsive_image/responsive_image.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..459100aa4a5a79fb1adb60c52a6caec43be0dda6 --- /dev/null +++ b/core/modules/responsive_image/responsive_image.routing.yml @@ -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'