3 namespace Drupal\image\Form;
5 use Drupal\Core\Entity\EntityForm;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Base form for image style add and edit forms.
13 abstract class ImageStyleFormBase extends EntityForm {
16 * The entity being used by this form.
18 * @var \Drupal\image\ImageStyleInterface
23 * The image style entity storage.
25 * @var \Drupal\Core\Entity\EntityStorageInterface
27 protected $imageStyleStorage;
30 * Constructs a base class for image style add and edit forms.
32 * @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
33 * The image style entity storage.
35 public function __construct(EntityStorageInterface $image_style_storage) {
36 $this->imageStyleStorage = $image_style_storage;
42 public static function create(ContainerInterface $container) {
44 $container->get('entity.manager')->getStorage('image_style')
51 public function form(array $form, FormStateInterface $form_state) {
54 '#type' => 'textfield',
55 '#title' => $this->t('Image style name'),
56 '#default_value' => $this->entity->label(),
60 '#type' => 'machine_name',
62 'exists' => [$this->imageStyleStorage, 'load'],
64 '#default_value' => $this->entity->id(),
68 return parent::form($form, $form_state);
74 public function save(array $form, FormStateInterface $form_state) {
75 parent::save($form, $form_state);
76 $form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));