/**
  * Overrides Drupal\Core\Entity\EntityForm::form().
  *
  * @param array $form
  *   A nested array form elements comprising the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return array
  *   The array containing the complete form.
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     if ($this->operation == 'duplicate') {
         $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 responsive image mapping</em> @label', array('@label' => $this->entity->label()));
     }
     /** @var \Drupal\responsive_image\ResponsiveImageMappingInterface $responsive_image_mapping */
     $responsive_image_mapping = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#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' => $responsive_image_mapping->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageMapping::load', 'source' => array('label')), '#disabled' => (bool) $responsive_image_mapping->id() && $this->operation != 'duplicate');
     if ((bool) $responsive_image_mapping->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 mappings.");
     } else {
         $description = $this->t('Select a breakpoint group from the installed themes.');
     }
     $form['breakpointGroup'] = array('#type' => 'select', '#title' => $this->t('Breakpoint group'), '#default_value' => $responsive_image_mapping->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 -');
     $breakpoints = $this->breakpointManager->getBreakpointsByGroup($responsive_image_mapping->getBreakpointGroup());
     foreach ($breakpoints as $breakpoint_id => $breakpoint) {
         foreach ($breakpoint->getMultipliers() as $multiplier) {
             $label = $multiplier . ' ' . $breakpoint->getLabel() . ' [' . $breakpoint->getMediaQuery() . ']';
             $form['keyed_mappings'][$breakpoint_id][$multiplier] = array('#type' => 'select', '#title' => $label, '#options' => $image_styles, '#default_value' => $responsive_image_mapping->getImageStyle($breakpoint_id, $multiplier), '#description' => $this->t('Select an image style for this breakpoint.'));
         }
     }
     $form['#tree'] = TRUE;
     return parent::form($form, $form_state, $responsive_image_mapping);
 }
예제 #2
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::form().
  *
  * @param array $form
  *   A nested array form elements comprising the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return array
  *   The array containing the complete form.
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     if ($this->operation == 'duplicate') {
         $form['#title'] = $this->t('<em>Duplicate responsive image style</em> @label', array('@label' => $this->entity->label()));
         $this->entity = $this->entity->createDuplicate();
     }
     if ($this->operation == 'edit') {
         $form['#title'] = $this->t('<em>Edit responsive image style</em> @label', array('@label' => $this->entity->label()));
     }
     /** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $responsive_image_style */
     $responsive_image_style = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $responsive_image_style->label(), '#description' => $this->t("Example: 'Hero image' or 'Author image'."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $responsive_image_style->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageStyle::load', 'source' => array('label')), '#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate');
     $image_styles = image_style_options(TRUE);
     $image_styles[RESPONSIVE_IMAGE_ORIGINAL_IMAGE] = $this->t('- None (original image) -');
     $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -');
     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', '#title' => $this->t('Breakpoint group'), '#default_value' => $responsive_image_style->getBreakpointGroup() ?: 'responsive_image', '#options' => $this->breakpointManager->getGroups(), '#required' => TRUE, '#description' => $description, '#ajax' => array('callback' => '::breakpointMappingFormAjax', 'wrapper' => 'responsive-image-style-breakpoints-wrapper'));
     $form['keyed_styles'] = array('#type' => 'container', '#attributes' => array('id' => 'responsive-image-style-breakpoints-wrapper'));
     // By default, breakpoints are ordered from smallest weight to largest:
     // the smallest weight is expected to have the smallest breakpoint width,
     // while the largest weight is expected to have the largest breakpoint
     // 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' => 'details', '#title' => $label);
             $image_style_mapping = $responsive_image_style->getImageStyleMapping($breakpoint_id, $multiplier);
             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('#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_style'] = array('#type' => 'select', '#title' => $this->t('Image style'), '#options' => $image_styles, '#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'] : '100vw', '#description' => $this->t('Enter the value for the sizes attribute, for example: %example_sizes.', ['%example_sizes' => '(min-width:700px) 700px, 100vw']), '#states' => array('visible' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes')), 'required' => 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')), 'required' => 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);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $group = $input->getArgument('group');
     if ($group) {
         $breakPointData = $this->getBreakpointByName($group);
         foreach ($breakPointData as $key => $breakPoint) {
             $io->comment($key, false);
             $io->block(Yaml::dump($breakPoint));
         }
         return 0;
     }
     $groups = array_keys($this->breakpointManager->getGroups());
     $tableHeader = [$this->trans('commands.breakpoints.debug.messages.name')];
     $io->table($tableHeader, $groups, 'compact');
     return 0;
 }
예제 #4
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::form().
  *
  * @param array $form
  *   A nested array form elements comprising the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return array
  *   The array containing the complete form.
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     if ($this->operation == 'duplicate') {
         $form['#title'] = $this->t('<em>Duplicate responsive image style</em> @label', array('@label' => $this->entity->label()));
         $this->entity = $this->entity->createDuplicate();
     }
     if ($this->operation == 'edit') {
         $form['#title'] = $this->t('<em>Edit responsive image style</em> @label', array('@label' => $this->entity->label()));
     }
     /** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $responsive_image_style */
     $responsive_image_style = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $responsive_image_style->label(), '#description' => $this->t("Example: 'Hero image' or 'Author image'."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $responsive_image_style->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageStyle::load', 'source' => array('label')), '#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'), '#type' => 'select', '#default_value' => $responsive_image_style->getFallbackImageStyle(), '#options' => $image_styles, '#required' => TRUE);
     // By default, breakpoints are ordered from smallest weight to largest:
     // the smallest weight is expected to have the smallest breakpoint width,
     // while the largest weight is expected to have the largest breakpoint
     // 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');
             $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.
             $form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping_type'] = array('#type' => 'value', '#value' => 'image_style');
             $form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping'] = array('#type' => 'select', '#title' => $label, '#options' => $image_styles, '#default_value' => isset($image_style_mapping['image_mapping']) ? $image_style_mapping['image_mapping'] : array(), '#description' => $this->t('Select an image style for this breakpoint.'));
         }
     }
     $form['#tree'] = TRUE;
     return parent::form($form, $form_state, $responsive_image_style);
 }