Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
|
@ -26,7 +26,6 @@ use Drupal\responsive_image\ResponsiveImageStyleInterface;
|
|||
* "duplicate" = "Drupal\responsive_image\ResponsiveImageStyleForm"
|
||||
* }
|
||||
* },
|
||||
* list_path = "admin/config/media/responsive-image-style",
|
||||
* admin_permission = "administer responsive images",
|
||||
* config_prefix = "styles",
|
||||
* entity_keys = {
|
||||
|
|
|
|||
|
|
@ -83,30 +83,23 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
'#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate',
|
||||
);
|
||||
|
||||
if ((bool) $responsive_image_style->id() && $this->operation != 'duplicate') {
|
||||
$description = $this->t('Select a breakpoint group from the installed themes.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your selected image style mappings.");
|
||||
}
|
||||
else {
|
||||
$description = $this->t('Select a breakpoint group from the installed themes.');
|
||||
}
|
||||
$form['breakpoint_group'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Breakpoint group'),
|
||||
'#default_value' => $responsive_image_style->getBreakpointGroup(),
|
||||
'#options' => $this->breakpointManager->getGroups(),
|
||||
'#required' => TRUE,
|
||||
'#description' => $description,
|
||||
);
|
||||
|
||||
$image_styles = image_style_options(TRUE);
|
||||
$image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -');
|
||||
|
||||
$form['fallback_image_style'] = array(
|
||||
'#title' => $this->t('Fallback image style'),
|
||||
if ((bool) $responsive_image_style->id() && $this->operation != 'duplicate') {
|
||||
$description = $this->t('Select a breakpoint group from the installed themes and modules. Below you can select which breakpoints to use from this group. You can also select which image style or styles to use for each breakpoint you use.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your image style selections for each breakpoint.");
|
||||
}
|
||||
else {
|
||||
$description = $this->t('Select a breakpoint group from the installed themes and modules.');
|
||||
}
|
||||
|
||||
$form['breakpoint_group'] = array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => $responsive_image_style->getFallbackImageStyle(),
|
||||
'#options' => $image_styles,
|
||||
'#title' => $this->t('Breakpoint group'),
|
||||
'#default_value' => $responsive_image_style->getBreakpointGroup() ?: 'responsive_image',
|
||||
'#options' => $this->breakpointManager->getGroups(),
|
||||
'#required' => TRUE,
|
||||
'#description' => $description,
|
||||
);
|
||||
|
||||
// By default, breakpoints are ordered from smallest weight to largest:
|
||||
|
|
@ -115,30 +108,84 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
// width. For responsive images, we need largest breakpoint widths first, so
|
||||
// we need to reverse the order of these breakpoints.
|
||||
$breakpoints = array_reverse($this->breakpointManager->getBreakpointsByGroup($responsive_image_style->getBreakpointGroup()));
|
||||
|
||||
foreach ($breakpoints as $breakpoint_id => $breakpoint) {
|
||||
foreach ($breakpoint->getMultipliers() as $multiplier) {
|
||||
$label = $multiplier . ' ' . $breakpoint->getLabel() . ' [' . $breakpoint->getMediaQuery() . ']';
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier] = array(
|
||||
'#type' => 'container',
|
||||
'#type' => 'details',
|
||||
'#title' => $label,
|
||||
);
|
||||
$image_style_mapping = $responsive_image_style->getImageStyleMapping($breakpoint_id, $multiplier);
|
||||
// @todo The image_mapping_type is only temporarily hardcoded, until
|
||||
// support for the other responsive image mapping type ('sizes') is
|
||||
// added in https://www.drupal.org/node/2334387.
|
||||
if (\Drupal::moduleHandler()->moduleExists('help')) {
|
||||
$description = $this->t('See the <a href="!responsive_image_help">Responsive Image help page</a> for information on the sizes attribute.', array('!responsive_image_help' => (\Drupal::url('help.page', array('name' => 'responsive_image')))));
|
||||
}
|
||||
else {
|
||||
$description = $this->t('Enable the Help module for more information on the sizes attribute.');
|
||||
}
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping_type'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => 'image_style',
|
||||
'#title' => $this->t('Type'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
'sizes' => $this->t('Select multiple image styles and use the sizes attribute.'),
|
||||
'image_style' => $this->t('Select a single image style.'),
|
||||
'_none' => $this->t('Do not use this breakpoint.'),
|
||||
),
|
||||
'#default_value' => isset($image_style_mapping['image_mapping_type']) ? $image_style_mapping['image_mapping_type'] : '_none',
|
||||
'#description' => $description,
|
||||
);
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping'] = array(
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['image_style'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => $label,
|
||||
'#title' => $this->t('Image style'),
|
||||
'#options' => $image_styles,
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']) ? $image_style_mapping['image_mapping'] : array(),
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']) && is_string($image_style_mapping['image_mapping']) ? $image_style_mapping['image_mapping'] : '',
|
||||
'#description' => $this->t('Select an image style for this breakpoint.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'image_style'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Sizes'),
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']['sizes']) ? $image_style_mapping['image_mapping']['sizes'] : '',
|
||||
'#description' => $this->t('Enter the value for the sizes attribute: for example "(min-width:700px) 700px, 100vw)".'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes_image_styles'] = array(
|
||||
'#title' => $this->t('Image styles'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array_diff_key($image_styles, array('' => '')),
|
||||
'#description' => $this->t('Select image styles with widths that range from the smallest amount of space this image will take up in the layout to the largest, bearing in mind that high resolution screens will need images 1.5x to 2x larger.'),
|
||||
'#default_value' => isset($image_style_mapping['image_mapping']['sizes_image_styles']) ? $image_style_mapping['image_mapping']['sizes_image_styles'] : array(),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Expand the details if "do not use this breakpoint" was not selected.
|
||||
if ($form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping_type']['#default_value'] != '_none') {
|
||||
$form['keyed_styles'][$breakpoint_id][$multiplier]['#open'] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['fallback_image_style'] = array(
|
||||
'#title' => $this->t('Fallback image style'),
|
||||
'#type' => 'select',
|
||||
'#default_value' => $responsive_image_style->getFallbackImageStyle(),
|
||||
'#options' => $image_styles,
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Select the smallest image style you expect to appear in this space. The fallback image style should only appear on the site if an error occurs.'),
|
||||
);
|
||||
|
||||
$form['#tree'] = TRUE;
|
||||
|
||||
return parent::form($form, $form_state, $responsive_image_style);
|
||||
|
|
@ -156,9 +203,6 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
// Remove the image style mappings since the breakpoint ID has changed.
|
||||
$form_state->unsetValue('keyed_styles');
|
||||
}
|
||||
// @todo Filter 'sizes_image_styles' to a normal array in
|
||||
// https://www.drupal.org/node/2334387. For an example see
|
||||
// \Drupal\Core\Block\BlockBase::validateConfigurationForm().
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +217,23 @@ class ResponsiveImageStyleForm extends EntityForm {
|
|||
if ($form_state->hasValue('keyed_styles')) {
|
||||
foreach ($form_state->getValue('keyed_styles') as $breakpoint_id => $multipliers) {
|
||||
foreach ($multipliers as $multiplier => $image_style_mapping) {
|
||||
$responsive_image_style->addImageStyleMapping($breakpoint_id, $multiplier, $image_style_mapping);
|
||||
if ($image_style_mapping['image_mapping_type'] === 'sizes') {
|
||||
$mapping = array(
|
||||
'image_mapping_type' => 'sizes',
|
||||
'image_mapping' => array(
|
||||
'sizes' => $image_style_mapping['sizes'],
|
||||
'sizes_image_styles' => array_keys(array_filter($image_style_mapping['sizes_image_styles'])),
|
||||
)
|
||||
);
|
||||
$responsive_image_style->addImageStyleMapping($breakpoint_id, $multiplier, $mapping);
|
||||
}
|
||||
elseif ($image_style_mapping['image_mapping_type'] === 'image_style') {
|
||||
$mapping = array(
|
||||
'image_mapping_type' => 'image_style',
|
||||
'image_mapping' => $image_style_mapping['image_style'],
|
||||
);
|
||||
$responsive_image_style->addImageStyleMapping($breakpoint_id, $multiplier, $mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ResponsiveImageStyleListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $this->getLabel($entity);
|
||||
$row['label'] = $entity->label();
|
||||
$row['id'] = $entity->id();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,10 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
$this->drupalGet('admin/config/media/responsive-image-style');
|
||||
$this->assertText('There is no Responsive image style yet.');
|
||||
|
||||
// Add a new responsive image style, our breakpoint set should be selected.
|
||||
// Add a responsive image style.
|
||||
$this->drupalGet('admin/config/media/responsive-image-style/add');
|
||||
$this->assertFieldByName('breakpoint_group', 'responsive_image_test_module');
|
||||
// The 'Responsive Image' breakpoint group should be selected by default.
|
||||
$this->assertFieldByName('breakpoint_group', 'responsive_image');
|
||||
|
||||
// Create a new group.
|
||||
$edit = array(
|
||||
|
|
@ -79,7 +80,15 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
|
||||
foreach ($cases as $case) {
|
||||
// Check if the radio buttons are present.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_mapping]', '');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_mapping_type]', '');
|
||||
// Check if the image style dropdowns are present.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_style]', '');
|
||||
// Check if the sizes textfields are present.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][sizes]', '');
|
||||
// Check if the image styles checkboxes are present.
|
||||
foreach (array_keys(image_style_options(FALSE)) as $image_style_name) {
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][sizes_image_styles][' . $image_style_name . ']');
|
||||
}
|
||||
}
|
||||
|
||||
// Save styles for 1x variant only.
|
||||
|
|
@ -87,24 +96,35 @@ class ResponsiveImageAdminUITest extends WebTestBase {
|
|||
'label' => 'Style One',
|
||||
'breakpoint_group' => 'responsive_image_test_module',
|
||||
'fallback_image_style' => 'thumbnail',
|
||||
'keyed_styles[responsive_image_test_module.mobile][1x][image_mapping]' => 'thumbnail',
|
||||
'keyed_styles[responsive_image_test_module.narrow][1x][image_mapping]' => 'medium',
|
||||
'keyed_styles[responsive_image_test_module.wide][1x][image_mapping]' => 'large',
|
||||
'keyed_styles[responsive_image_test_module.mobile][1x][image_mapping_type]' => 'image_style',
|
||||
'keyed_styles[responsive_image_test_module.mobile][1x][image_style]' => 'thumbnail',
|
||||
'keyed_styles[responsive_image_test_module.narrow][1x][image_mapping_type]' => 'sizes',
|
||||
'keyed_styles[responsive_image_test_module.narrow][1x][sizes]' => '(min-width: 700px) 700px, 100vw',
|
||||
'keyed_styles[responsive_image_test_module.narrow][1x][sizes_image_styles][large]' => 'large',
|
||||
'keyed_styles[responsive_image_test_module.narrow][1x][sizes_image_styles][medium]' => 'medium',
|
||||
'keyed_styles[responsive_image_test_module.wide][1x][image_mapping_type]' => 'image_style',
|
||||
'keyed_styles[responsive_image_test_module.wide][1x][image_style]' => 'large',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/media/responsive-image-style/style_one', $edit, t('Save'));
|
||||
$this->drupalGet('admin/config/media/responsive-image-style/style_one');
|
||||
|
||||
// Check the style for multipliers 1x and 2x for the mobile breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.mobile][1x][image_mapping]', 'thumbnail');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.mobile][2x][image_mapping]', '');
|
||||
// Check the mapping for multipliers 1x and 2x for the mobile breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.mobile][1x][image_style]', 'thumbnail');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.mobile][1x][image_mapping_type]', 'image_style');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.mobile][2x][image_mapping_type]', '_none');
|
||||
|
||||
// Check the style for multipliers 1x and 2x for the narrow breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.narrow][1x][image_mapping]', 'medium');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.narrow][2x][image_mapping]', '');
|
||||
// Check the mapping for multipliers 1x and 2x for the narrow breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.narrow][1x][image_mapping_type]', 'sizes');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.narrow][1x][sizes]', '(min-width: 700px) 700px, 100vw');
|
||||
$this->assertFieldChecked('edit-keyed-styles-responsive-image-test-modulenarrow-1x-sizes-image-styles-large');
|
||||
$this->assertFieldChecked('edit-keyed-styles-responsive-image-test-modulenarrow-1x-sizes-image-styles-medium');
|
||||
$this->assertNoFieldChecked('edit-keyed-styles-responsive-image-test-modulenarrow-1x-sizes-image-styles-thumbnail');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.narrow][2x][image_mapping_type]', '_none');
|
||||
|
||||
// Check the style for multipliers 1x and 2x for the wide breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.wide][1x][image_mapping]', 'large');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.wide][2x][image_mapping]', '');
|
||||
// Check the mapping for multipliers 1x and 2x for the wide breakpoint.
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.wide][1x][image_style]', 'large');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.wide][1x][image_mapping_type]', 'image_style');
|
||||
$this->assertFieldByName('keyed_styles[responsive_image_test_module.wide][2x][image_mapping_type]', '_none');
|
||||
|
||||
// Delete the style.
|
||||
$this->drupalGet('admin/config/media/responsive-image-style/style_one/delete');
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use Drupal\image\Tests\ImageFieldTestBase;
|
|||
use Drupal\image\Entity\ImageStyle;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -191,6 +192,41 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
$default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
|
||||
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
|
||||
|
||||
// Test field not being configured. This should not cause a fatal error.
|
||||
$display_options = array(
|
||||
'type' => 'responsive_image_test',
|
||||
'settings' => ResponsiveImageFormatter::defaultSettings(),
|
||||
);
|
||||
$display = $this->container->get('entity.manager')
|
||||
->getStorage('entity_view_display')
|
||||
->load('node.article.default');
|
||||
if (!$display) {
|
||||
$values = [
|
||||
'targetEntityType' => 'node',
|
||||
'bundle' => 'article',
|
||||
'mode' => 'default',
|
||||
'status' => TRUE,
|
||||
];
|
||||
$display = $this->container->get('entity.manager')->getStorage('entity_view_display')->create($values);
|
||||
}
|
||||
$display->setComponent($field_name, $display_options)->save();
|
||||
|
||||
$this->drupalGet('node/' . $nid);
|
||||
|
||||
// Test theme function for responsive image, but using the test formatter.
|
||||
$display_options = array(
|
||||
'type' => 'responsive_image_test',
|
||||
'settings' => array(
|
||||
'image_link' => 'file',
|
||||
'responsive_image_style' => 'style_one',
|
||||
),
|
||||
);
|
||||
$display = entity_get_display('node', 'article', 'default');
|
||||
$display->setComponent($field_name, $display_options)
|
||||
->save();
|
||||
|
||||
$this->drupalGet('node/' . $nid);
|
||||
|
||||
// Use the responsive image formatter linked to file formatter.
|
||||
$display_options = array(
|
||||
'type' => 'responsive_image',
|
||||
|
|
|
|||
Reference in a new issue