diff --git a/core/modules/responsive_image/config/install/responsive_image.settings.yml b/core/modules/responsive_image/config/install/responsive_image.settings.yml new file mode 100644 index 0000000..57c9aaf --- /dev/null +++ b/core/modules/responsive_image/config/install/responsive_image.settings.yml @@ -0,0 +1 @@ +suppress_polyfill: false diff --git a/core/modules/responsive_image/config/schema/responsive_image.schema.yml b/core/modules/responsive_image/config/schema/responsive_image.schema.yml index f05a8e2..2a79202 100644 --- a/core/modules/responsive_image/config/schema/responsive_image.schema.yml +++ b/core/modules/responsive_image/config/schema/responsive_image.schema.yml @@ -1,4 +1,11 @@ # Schema for the configuration files of the Responsive Image module. +responsive_image.settings: + type: config_object + label: 'Responsive image settings' + mapping: + suppress_polyfill: + type: boolean + label: 'Do not use the polyfill' responsive_image.styles.*: type: config_entity diff --git a/core/modules/responsive_image/responsive_image.links.task.yml b/core/modules/responsive_image/responsive_image.links.task.yml index d5e69d6..2a1e443 100644 --- a/core/modules/responsive_image/responsive_image.links.task.yml +++ b/core/modules/responsive_image/responsive_image.links.task.yml @@ -3,3 +3,13 @@ entity.responsive_image_style.edit_form: route_name: entity.responsive_image_style.edit_form base_route: entity.responsive_image_style.edit_form weight: -10 +entity.responsive_image_style.collection: + title: List + base_route: entity.responsive_image_style.collection + route_name: entity.responsive_image_style.collection + weight: -11 +responsive_image_style.admin_settings: + title: Settings + route_name: responsive_image_style.admin_settings + base_route: entity.responsive_image_style.collection + weight: -10 diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 89ac37f..1b10a8c 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -508,7 +508,9 @@ function _responsive_image_image_style_url($style_name, $path) { * Load responsive_image.js whenever ajax is added. */ function responsive_image_library_info_alter(array &$libraries, $module) { - if ($module === 'core' && isset($libraries['drupal.ajax'])) { - $libraries['drupal.ajax']['dependencies'][] = 'responsive_image/ajax'; + if (!\Drupal::config('responsive_image.settings')->get('suppress_polyfill')) { + if ($module === 'core' && isset($libraries['drupal.ajax'])) { + $libraries['drupal.ajax']['dependencies'][] = 'responsive_image/ajax'; + } } } diff --git a/core/modules/responsive_image/responsive_image.routing.yml b/core/modules/responsive_image/responsive_image.routing.yml index 6a00ff6..0b07655 100644 --- a/core/modules/responsive_image/responsive_image.routing.yml +++ b/core/modules/responsive_image/responsive_image.routing.yml @@ -6,6 +6,14 @@ entity.responsive_image_style.collection: requirements: _permission: 'administer responsive images' +responsive_image_style.admin_settings: + path: '/admin/config/media/responsive-image-style/settings' + defaults: + _form: '\Drupal\responsive_image\Form\SettingsForm' + _title: 'Responsive image settings' + requirements: + _permission: 'administer responsive images' + responsive_image.style_page_add: path: '/admin/config/media/responsive-image-style/add' defaults: diff --git a/core/modules/responsive_image/src/Element/ResponsiveImage.php b/core/modules/responsive_image/src/Element/ResponsiveImage.php index 2c6f677..65d9230 100644 --- a/core/modules/responsive_image/src/Element/ResponsiveImage.php +++ b/core/modules/responsive_image/src/Element/ResponsiveImage.php @@ -15,12 +15,19 @@ class ResponsiveImage extends RenderElement { * {@inheritdoc} */ public function getInfo() { - return [ - '#theme' => 'responsive_image', - '#attached' => [ - 'library' => ['core/picturefill'], - ], - ]; + if (\Drupal::config('responsive_image.settings')->get('suppress_polyfill')) { + return [ + '#theme' => 'responsive_image', + ]; + } + else { + return [ + '#theme' => 'responsive_image', + '#attached' => [ + 'library' => ['core/picturefill'], + ], + ]; + } } } diff --git a/core/modules/responsive_image/src/Form/SettingsForm.php b/core/modules/responsive_image/src/Form/SettingsForm.php new file mode 100644 index 0000000..a30e703 --- /dev/null +++ b/core/modules/responsive_image/src/Form/SettingsForm.php @@ -0,0 +1,57 @@ +config('responsive_image.settings'); + $form['suppress_polyfill'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Do not use the polyfill'), + '#default_value' => $config->get('suppress_polyfill'), + '#description' => $this->t('Suppress the output of the polyfill and rely on the native behavior of the picture element.'), + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $values = $form_state->getValues(); + $this->config('responsive_image.settings') + ->set('suppress_polyfill', $values['suppress_polyfill']) + ->save(); + + parent::submitForm($form, $form_state); + } + +}