You are here

ImageEffectAddForm.php in Zircon Profile 8.0

Same filename and directory in other branches
  1. 8 core/modules/image/src/Form/ImageEffectAddForm.php

Namespace

Drupal\image\Form

File

core/modules/image/src/Form/ImageEffectAddForm.php
View source
<?php

/**
 * @file
 * Contains \Drupal\image\Form\ImageEffectAddForm.
 */
namespace Drupal\image\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\image\ImageEffectManager;
use Drupal\image\ImageStyleInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides an add form for image effects.
 */
class ImageEffectAddForm extends ImageEffectFormBase {

  /**
   * The image effect manager.
   *
   * @var \Drupal\image\ImageEffectManager
   */
  protected $effectManager;

  /**
   * Constructs a new ImageEffectAddForm.
   *
   * @param \Drupal\image\ImageEffectManager $effect_manager
   *   The image effect manager.
   */
  public function __construct(ImageEffectManager $effect_manager) {
    $this->effectManager = $effect_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('plugin.manager.image.effect'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, ImageStyleInterface $image_style = NULL, $image_effect = NULL) {
    $form = parent::buildForm($form, $form_state, $image_style, $image_effect);
    $form['#title'] = $this
      ->t('Add %label effect', array(
      '%label' => $this->imageEffect
        ->label(),
    ));
    $form['actions']['submit']['#value'] = $this
      ->t('Add effect');
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareImageEffect($image_effect) {
    $image_effect = $this->effectManager
      ->createInstance($image_effect);

    // Set the initial weight so this effect comes last.
    $image_effect
      ->setWeight(count($this->imageStyle
      ->getEffects()));
    return $image_effect;
  }

}

Classes

Namesort descending Description
ImageEffectAddForm Provides an add form for image effects.