public function BlazyAdminBase::breakpointsForm in Blazy 8
Same name and namespace in other branches
- 8.2 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::breakpointsForm()
- 7 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::breakpointsForm()
Defines re-usable breakpoints form.
See also
https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-sr...
http://ericportis.com/posts/2014/srcset-sizes/
http://www.sitepoint.com/how-to-build-responsive-images-with-srcset/
1 call to BlazyAdminBase::breakpointsForm()
- BlazyAdminFormatter::buildSettingsForm in src/
Form/ BlazyAdminFormatter.php - Defines re-usable form elements.
File
- src/
Form/ BlazyAdminBase.php, line 206
Class
- BlazyAdminBase
- A base for blazy admin integration to have re-usable methods in one place.
Namespace
Drupal\blazy\FormCode
public function breakpointsForm(array &$form, $definition = []) {
$settings = isset($definition['settings']) ? $definition['settings'] : [];
$title = $this
->t('Leave Breakpoints empty to disable multi-serving images. <small>If provided, Blazy lazyload applies. Ignored if core Responsive image is provided.<br /> If only two is needed, simply leave the rest empty. At any rate, the last should target the largest monitor. <br />It uses <strong>max-width</strong>, not <strong>min-width</strong>.</small>');
$form['sizes'] = [
'#type' => 'textfield',
'#title' => $this
->t('Sizes'),
'#description' => $this
->t('E.g.: (min-width: 1290px) 1290px, 100vw. Use sizes to implement different size image (different height, width) on different screen sizes along with the <strong>w (width)</strong> descriptor below. Ignored by Responsive image.'),
'#weight' => 114,
'#attributes' => [
'class' => [
'form-text--sizes',
'js-expandable',
],
],
'#wrapper_attributes' => [
'class' => [
'form-item--sizes',
],
],
'#prefix' => '<h2 class="form__title form__title--breakpoints">' . $title . '</h2>',
];
$form['breakpoints'] = [
'#type' => 'table',
'#tree' => TRUE,
'#header' => [
$this
->t('Breakpoint'),
$this
->t('Image style'),
$this
->t('Max-width/Descriptor'),
],
'#attributes' => [
'class' => [
'form-wrapper--table',
'form-wrapper--table-breakpoints',
],
],
'#weight' => 115,
'#enforced' => TRUE,
];
// Unlike D7, D8 form states seem to not recognize individual field form.
$vanilla = ':input[name$="[vanilla]"]';
if (isset($definition['field_name'])) {
$vanilla = ':input[name="fields[' . $definition['field_name'] . '][settings_edit_form][settings][vanilla]"]';
}
if (!empty($definition['_views'])) {
$vanilla = ':input[name="options[settings][vanilla]"]';
}
$breakpoints = $this
->breakpointElements($definition);
foreach ($breakpoints as $breakpoint => $elements) {
foreach ($elements as $key => $element) {
$form['breakpoints'][$breakpoint][$key] = $element;
if (!empty($definition['vanilla'])) {
$form['breakpoints'][$breakpoint][$key]['#states']['enabled'][$vanilla] = [
'checked' => FALSE,
];
}
$value = isset($settings['breakpoints'][$breakpoint][$key]) ? $settings['breakpoints'][$breakpoint][$key] : '';
$form['breakpoints'][$breakpoint][$key]['#default_value'] = $value;
}
}
}