image_style_options example


  public function testNumericStyleName() {
    $style_name = rand();
    $style_label = $this->randomString();
    $edit = [
      'name' => $style_name,
      'label' => $style_label,
    ];
    $this->drupalGet('admin/config/media/image-styles/add');
    $this->submitForm($edit, 'Create new style');
    $this->assertSession()->statusMessageContains("Style {$style_label} was created.", 'status');
    $options = image_style_options();
    $this->assertArrayHasKey($style_name$options);
  }

  /** * General test to add a style, add/remove/edit effects to it, then delete it. */
  public function testStyle() {
    $admin_path = 'admin/config/media/image-styles';

    // Setup a style to be created and effects to add to it.     $style_name = strtolower($this->randomMachineName(10));
    
'#default_value' => $entity->get('weight'),
    ];
    $form['style'] = [
      '#type' => 'select',
      '#title' => 'Image style',
      '#options' => [],
      '#default_value' => $entity->get('style'),
      '#access' => FALSE,
    ];
    if ($this->moduleHandler->moduleExists('image')) {
      $form['style']['#access'] = TRUE;
      $form['style']['#options'] = image_style_options();
    }

    // The main premise of entity forms is that we get to work with an entity     // object at all times instead of checking submitted values from the form     // state.     $size = $entity->get('size');

    $form['size_wrapper'] = [
      '#type' => 'container',
      '#attributes' => [
        'id' => 'size-wrapper',
      ],

    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $responsive_image_style->id(),
      '#machine_name' => [
        'exists' => '\Drupal\responsive_image\Entity\ResponsiveImageStyle::load',
        'source' => ['label'],
      ],
      '#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate',
    ];

    $image_styles = image_style_options(TRUE);
    $image_styles[ResponsiveImageStyleInterface::ORIGINAL_IMAGE] = $this->t('- None (original image) -');
    $image_styles[ResponsiveImageStyleInterface::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'] = [
      
'attribute' => 'lazy',
      ],
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form$form_state);

    $image_styles = image_style_options(FALSE);
    $description_link = Link::fromTextAndUrl(
      $this->t('Configure Image Styles'),
      Url::fromRoute('entity.image_style.collection')
    );
    $element['image_style'] = [
      '#title' => $this->t('Image style'),
      '#type' => 'select',
      '#default_value' => $this->getSetting('image_style'),
      '#empty_option' => $this->t('None (original image)'),
      '#options' => $image_styles,
      '#description' => $description_link->toRenderable() + [
        


  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form$form_state);

    $element['preview_image_style'] = [
      '#title' => $this->t('Preview image style'),
      '#type' => 'select',
      '#options' => image_style_options(FALSE),
      '#empty_option' => '<' . $this->t('no preview') . '>',
      '#default_value' => $this->getSetting('preview_image_style'),
      '#description' => $this->t('The preview image will be shown while editing the content.'),
      '#weight' => 15,
    ];

    return $element;
  }

  /** * {@inheritdoc} */
$cases = [
      ['mobile', '1x'],
      ['mobile', '2x'],
      ['narrow', '1x'],
      ['narrow', '2x'],
      ['wide', '1x'],
      ['wide', '2x'],
    ];
    $image_styles = array_merge(
      [ResponsiveImageStyleInterface::EMPTY_IMAGE, ResponsiveImageStyleInterface::ORIGINAL_IMAGE],
      array_keys(image_style_options(FALSE))
    );
    foreach ($cases as $case) {
      // Check if the radio buttons are present.       $this->assertSession()->fieldExists('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_mapping_type]');
      // Check if the image style dropdowns are present.       $this->assertSession()->fieldExists('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][image_style]');
      // Check if the sizes textfields are present.       $this->assertSession()->fieldExists('keyed_styles[responsive_image_test_module.' . $case[0] . '][' . $case[1] . '][sizes]');

      foreach ($image_styles as $image_style_name) {
        // Check if the image styles are available in the dropdowns.
parent::submitForm($form$form_state);
  }

  /** * Returns a list of image style replacement options. * * @return array * An option list suitable for the form select '#options'. */
  protected function getReplacementOptions() {
    if (!isset($this->replacementOptions)) {
      $this->replacementOptions = array_diff_key(image_style_options()[$this->getEntity()->id() => '']);
    }
    return $this->replacementOptions;
  }

}

  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form$form_state);

    unset($element['image_link']$element['image_loading']);

    $image_styles = image_style_options(FALSE);
    $description_link = Link::fromTextAndUrl(
      $this->t('Configure Image Styles'),
      Url::fromRoute('entity.image_style.collection')
    );
    $element['image_style'] = [
      '#title' => $this->t('Image style'),
      '#type' => 'select',
      '#default_value' => $this->getSetting('image_style'),
      '#empty_option' => $this->t('None (original image)'),
      '#options' => $image_styles,
      '#description' => $description_link->toRenderable() + [
        
Home | Imprint | This part of the site doesn't use cookies.