summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-07-29 12:55:32 (GMT)
committerAlex Pott2013-07-29 12:55:32 (GMT)
commit5f317ad60629618e044cfbf1aeb35147f04436c3 (patch)
tree902f598a68343dae4a4e0be99c8b7c2b6ebc5375
parent42ebadcac2cbc446bb01cf160453d1611b811474 (diff)
Issue #1788542 by claudiu.cristea, andypost, tim-e, fubhy, speely, heyrocker: Use EntityFormController and EntityListController for image styles.
-rw-r--r--core/modules/image/image.admin.inc304
-rw-r--r--core/modules/image/image.module30
-rw-r--r--core/modules/image/image.routing.yml21
-rw-r--r--core/modules/image/lib/Drupal/image/Form/ImageStyleAddForm.php35
-rw-r--r--core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php256
-rw-r--r--core/modules/image/lib/Drupal/image/Form/ImageStyleFormBase.php103
-rw-r--r--core/modules/image/lib/Drupal/image/ImageStyleAccessController.php34
-rw-r--r--core/modules/image/lib/Drupal/image/ImageStyleListController.php104
-rw-r--r--core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php6
-rw-r--r--core/modules/image/lib/Drupal/image/Plugin/Menu/LocalAction/ImageStyleAddLocalAction.php24
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php12
11 files changed, 599 insertions, 330 deletions
diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc
index 1e2646f..ffde15d 100644
--- a/core/modules/image/image.admin.inc
+++ b/core/modules/image/image.admin.inc
@@ -5,310 +5,6 @@
* Administration pages for image settings.
*/
-use Drupal\Component\Utility\String;
-use Drupal\image\ConfigurableImageEffectInterface;
-use Drupal\image\ImageStyleInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-
-/**
- * Menu callback; Listing of all current image styles.
- */
-function image_style_list() {
- $page = array();
-
- $styles = entity_load_multiple('image_style');
- $page['image_style_list'] = array(
- '#markup' => theme('image_style_list', array('styles' => $styles)),
- '#attached' => array(
- 'css' => array(drupal_get_path('module', 'image') . '/css/image.admin.css' => array()),
- ),
- );
-
- return $page;
-
-}
-
-/**
- * Form builder; Edit an image style name and effects order.
- *
- * @param $form_state
- * An associative array containing the current state of the form.
- * @param $style
- * An image style array.
- * @ingroup forms
- * @see image_style_form_submit()
- */
-function image_style_form($form, &$form_state, ImageStyleInterface $style) {
- $title = t('Edit style %name', array('%name' => $style->label()));
- drupal_set_title($title, PASS_THROUGH);
-
- $form_state['image_style'] = $style;
- $form['#tree'] = TRUE;
- $form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
-
- // Show the thumbnail preview.
- $form['preview'] = array(
- '#type' => 'item',
- '#title' => t('Preview'),
- '#markup' => theme('image_style_preview', array('style' => $style)),
- );
-
- $form['label'] = array(
- '#type' => 'textfield',
- '#title' => t('Administrative label'),
- '#default_value' => $style->label(),
- '#required' => TRUE,
- );
- $form['name'] = array(
- '#type' => 'machine_name',
- '#default_value' => $style->id(),
- '#machine_name' => array(
- 'exists' => 'image_style_load',
- ),
- '#required' => TRUE,
- );
-
- // Build the list of existing image effects for this image style.
- $form['effects'] = array(
- '#theme' => 'image_style_effects',
- );
- foreach ($style->getEffects()->sort() as $effect) {
- $key = $effect->getUuid();
- $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
- $form['effects'][$key]['label'] = array(
- '#markup' => String::checkPlain($effect->label()),
- );
- $form['effects'][$key]['summary'] = $effect->getSummary();
- $form['effects'][$key]['weight'] = array(
- '#type' => 'weight',
- '#title' => t('Weight for @title', array('@title' => $effect->label())),
- '#title_display' => 'invisible',
- '#default_value' => $effect->getWeight(),
- );
-
- $links = array();
- $is_configurable = $effect instanceof ConfigurableImageEffectInterface;
- if ($is_configurable) {
- $links['edit'] = array(
- 'title' => t('edit'),
- 'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key,
- );
- }
- $links['delete'] = array(
- 'title' => t('delete'),
- 'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key . '/delete',
- );
- $form['effects'][$key]['operations'] = array(
- '#type' => 'operations',
- '#links' => $links,
- );
- $form['effects'][$key]['configure'] = array(
- '#type' => 'link',
- '#title' => t('edit'),
- '#href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key,
- '#access' => $is_configurable,
- );
- $form['effects'][$key]['remove'] = array(
- '#type' => 'link',
- '#title' => t('delete'),
- '#href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key . '/delete',
- );
- }
-
- // Build the new image effect addition form and add it to the effect list.
- $new_effect_options = array();
- $effects = Drupal::service('plugin.manager.image.effect')->getDefinitions();
- uasort($effects, function ($a, $b) {
- return strcasecmp($a['id'], $b['id']);
- });
- foreach ($effects as $effect => $definition) {
- $new_effect_options[$effect] = $definition['label'];
- }
- $form['effects']['new'] = array(
- '#tree' => FALSE,
- '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
- );
- $form['effects']['new']['new'] = array(
- '#type' => 'select',
- '#title' => t('Effect'),
- '#title_display' => 'invisible',
- '#options' => $new_effect_options,
- '#empty_option' => t('Select a new effect'),
- );
- $form['effects']['new']['weight'] = array(
- '#type' => 'weight',
- '#title' => t('Weight for new effect'),
- '#title_display' => 'invisible',
- '#default_value' => count($form['effects']) - 1,
- );
- $form['effects']['new']['add'] = array(
- '#type' => 'submit',
- '#value' => t('Add'),
- '#validate' => array('image_style_form_add_validate'),
- '#submit' => array('image_style_form_submit', 'image_style_form_add_submit'),
- );
-
- // Show the Override or Submit button for this style.
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update style'),
- );
-
- return $form;
-}
-
-/**
- * Validate handler for adding a new image effect to an image style.
- */
-function image_style_form_add_validate($form, &$form_state) {
- if (!$form_state['values']['new']) {
- form_error($form['effects']['new']['new'], t('Select an effect to add.'));
- }
-}
-
-/**
- * Submit handler for adding a new image effect to an image style.
- */
-function image_style_form_add_submit($form, &$form_state) {
- $style = $form_state['image_style'];
- // Check if this field has any configuration options.
- $effect = Drupal::service('plugin.manager.image.effect')->getDefinition($form_state['values']['new']);
-
- // Load the configuration form for this option.
- if (is_subclass_of($effect['class'], '\Drupal\image\ConfigurableImageEffectInterface')) {
- $path = 'admin/config/media/image-styles/manage/' . $style->id() . '/add/' . $form_state['values']['new'];
- $form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));
- }
- // If there's no form, immediately add the image effect.
- else {
- $effect = array(
- 'id' => $effect['id'],
- 'data' => array(),
- 'weight' => $form_state['values']['weight'],
- );
- $style->saveImageEffect($effect);
- drupal_set_message(t('The image effect was successfully applied.'));
- }
-}
-
-/**
- * Submit handler for saving an image style.
- */
-function image_style_form_submit($form, &$form_state) {
- $style = $form_state['image_style'];
-
- // Update image effect weights.
- if (!empty($form_state['values']['effects'])) {
- foreach ($form_state['values']['effects'] as $uuid => $effect_data) {
- if ($style->getEffects()->has($uuid)) {
- $style->getEffect($uuid)->setWeight($effect_data['weight']);
- }
- }
- }
-
- $style->set('name', $form_state['values']['name']);
- $style->set('label', $form_state['values']['label']);
- $status = $style->save();
-
- if ($status == SAVED_UPDATED) {
- drupal_set_message(t('Changes to the style have been saved.'));
- }
- $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
-}
-
-/**
- * Form builder; Form for adding a new image style.
- *
- * @ingroup forms
- * @see image_style_add_form_submit()
- */
-function image_style_add_form($form, &$form_state) {
- $form['label'] = array(
- '#type' => 'textfield',
- '#title' => t('Administrative label'),
- '#default_value' => '',
- '#required' => TRUE,
- );
- $form['name'] = array(
- '#type' => 'machine_name',
- '#machine_name' => array(
- 'exists' => 'image_style_load',
- ),
- '#default_value' => '',
- '#required' => TRUE,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Create new style'),
- );
-
- return $form;
-}
-
-/**
- * Submit handler for adding a new image style.
- */
-function image_style_add_form_submit($form, &$form_state) {
- $style = entity_create('image_style', array(
- 'name' => $form_state['values']['name'],
- 'label' => $form_state['values']['label'],
- ));
- $style->save();
- drupal_set_message(t('Style %name was created.', array('%name' => $style->label())));
- $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
-}
-
-/**
- * Returns HTML for the page containing the list of image styles.
- *
- * @param $variables
- * An associative array containing:
- * - styles: An array of all the image styles returned by image_get_styles().
- *
- * @see image_get_styles()
- * @ingroup themeable
- */
-function theme_image_style_list($variables) {
- $styles = $variables['styles'];
-
- $header = array(t('Style name'), t('Operations'));
- $rows = array();
-
- foreach ($styles as $style) {
- $row = array();
- $row[] = l($style->label(), 'admin/config/media/image-styles/manage/' . $style->id());
- $links = array();
- $links['edit'] = array(
- 'title' => t('edit'),
- 'href' => 'admin/config/media/image-styles/manage/' . $style->id(),
- 'class' => array('image-style-link'),
- );
- $links['delete'] = array(
- 'title' => t('delete'),
- 'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/delete',
- 'class' => array('image-style-link'),
- );
- $row[] = array(
- 'data' => array(
- '#type' => 'operations',
- '#links' => $links,
- ),
- );
- $rows[] = $row;
- }
-
- if (empty($rows)) {
- $rows[] = array(array(
- 'colspan' => 4,
- 'data' => t('There are currently no styles. <a href="!url">Add a new one</a>.', array('!url' => url('admin/config/media/image-styles/add'))),
- ));
- }
-
- return theme('table', array('header' => $header, 'rows' => $rows));
-}
-
/**
* Returns HTML for a listing of the effects within a specific image style.
*
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index fefbf00..c1918eb 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -96,42 +96,26 @@ function image_menu() {
$items['admin/config/media/image-styles'] = array(
'title' => 'Image styles',
'description' => 'Configure styles that can be used for resizing or adjusting images on display.',
- 'page callback' => 'image_style_list',
- 'access arguments' => array('administer image styles'),
- 'file' => 'image.admin.inc',
+ 'route_name' => 'image_style_list',
);
$items['admin/config/media/image-styles/list'] = array(
'title' => 'List',
'description' => 'List the current image styles on the site.',
- 'page callback' => 'image_style_list',
- 'access arguments' => array('administer image styles'),
'type' => MENU_DEFAULT_LOCAL_TASK,
- 'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/add'] = array(
- 'title' => 'Add style',
- 'description' => 'Add a new image style.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('image_style_add_form'),
- 'access arguments' => array('administer image styles'),
- 'type' => MENU_LOCAL_ACTION,
- 'weight' => 2,
- 'file' => 'image.admin.inc',
+ 'route_name' => 'image_style_add',
+ 'type' => MENU_SIBLING_LOCAL_TASK,
+ 'weight' => 1,
);
$items['admin/config/media/image-styles/manage/%image_style'] = array(
'title' => 'Edit style',
- 'title callback' => 'entity_page_label',
- 'title arguments' => array(5),
'description' => 'Configure an image style.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('image_style_form', 5),
- 'access arguments' => array('administer image styles'),
- 'file' => 'image.admin.inc',
+ 'route_name' => 'image_style_edit',
);
$items['admin/config/media/image-styles/manage/%image_style/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
);
$items['admin/config/media/image-styles/manage/%image_style/delete'] = array(
'title' => 'Delete',
@@ -178,10 +162,6 @@ function image_theme() {
),
// Theme functions in image.admin.inc.
- 'image_style_list' => array(
- 'variables' => array('styles' => NULL),
- 'file' => 'image.admin.inc',
- ),
'image_style_effects' => array(
'render element' => 'form',
'file' => 'image.admin.inc',
diff --git a/core/modules/image/image.routing.yml b/core/modules/image/image.routing.yml
index 3625dbe..c5b83ce 100644
--- a/core/modules/image/image.routing.yml
+++ b/core/modules/image/image.routing.yml
@@ -1,3 +1,17 @@
+image_style_add:
+ pattern: '/admin/config/media/image-styles/add'
+ defaults:
+ _entity_form: image_style.add
+ requirements:
+ _permission: 'administer image styles'
+
+image_style_edit:
+ pattern: '/admin/config/media/image-styles/manage/{image_style}'
+ defaults:
+ _entity_form: image_style.edit
+ requirements:
+ _permission: 'administer image styles'
+
image_style_delete:
pattern: 'admin/config/media/image-styles/manage/{image_style}/delete'
defaults:
@@ -12,6 +26,13 @@ image_effect_delete:
requirements:
_permission: 'administer image styles'
+image_style_list:
+ pattern: '/admin/config/media/image-styles'
+ defaults:
+ _entity_list: 'image_style'
+ requirements:
+ _permission: 'administer image styles'
+
image_style_private:
pattern: '/system/files/styles/{image_style}/{scheme}'
defaults:
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleAddForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleAddForm.php
new file mode 100644
index 0000000..8af0640
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleAddForm.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\Form\ImageStyleAddForm.
+ */
+
+namespace Drupal\image\Form;
+
+use Drupal\image\Form\ImageStyleFormBase;
+
+/**
+ * Controller for image style addition forms.
+ */
+class ImageStyleAddForm extends ImageStyleFormBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save(array $form, array &$form_state) {
+ parent::save($form, $form_state);
+ drupal_set_message($this->translator->translate('Style %name was created.', array('%name' => $this->entity->label())));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function actions(array $form, array &$form_state) {
+ $actions = parent::actions($form, $form_state);
+ $actions['submit']['#value'] = $this->translator->translate('Create new style');
+
+ return $actions;
+ }
+
+}
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php
new file mode 100644
index 0000000..0625cdd
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php
@@ -0,0 +1,256 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\Form\ImageStyleEditForm.
+ */
+
+namespace Drupal\image\Form;
+
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
+use Drupal\image\ConfigurableImageEffectInterface;
+use Drupal\image\Form\ImageStyleFormBase;
+use Drupal\image\ImageEffectManager;
+use Drupal\Component\Utility\String;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Controller for image style edit form.
+ */
+class ImageStyleEditForm extends ImageStyleFormBase {
+
+ /**
+ * The image effect manager service.
+ *
+ * @var \Drupal\image\ImageEffectManager
+ */
+ protected $imageEffectManager;
+
+ /**
+ * Constructs an ImageStyleEditForm object.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler service.
+ * @param \Drupal\Core\Entity\EntityStorageControllerInterface $image_style_storage
+ * The storage controller.
+ * @param \Drupal\image\ImageEffectManager $image_effect_manager
+ * The image effect manager service.
+ * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
+ * The translator service.
+ */
+ public function __construct(ModuleHandlerInterface $module_handler, EntityStorageControllerInterface $image_style_storage, TranslatorInterface $translator, ImageEffectManager $image_effect_manager) {
+ parent::__construct($module_handler, $image_style_storage, $translator);
+ $this->imageEffectManager = $image_effect_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
+ return new static(
+ $container->get('module_handler'),
+ $container->get('plugin.manager.entity')->getStorageController($entity_type),
+ $container->get('string_translation'),
+ $container->get('plugin.manager.image.effect')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function form(array $form, array &$form_state) {
+
+ // @todo Remove drupal_set_title() in http://drupal.org/node/1981644
+ $title = $this->translator->translate('Edit style %name', array('%name' => $this->entity->label()));
+ drupal_set_title($title, PASS_THROUGH);
+
+ $form['#tree'] = TRUE;
+ $form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
+
+ // Show the thumbnail preview.
+ $preview_arguments = array('#theme' => 'image_style_preview', '#style' => $this->entity);
+ $form['preview'] = array(
+ '#type' => 'item',
+ '#title' => $this->translator->translate('Preview'),
+ '#markup' => drupal_render($preview_arguments),
+ // Render preview above parent elements.
+ '#weight' => -5,
+ );
+
+ // Build the list of existing image effects for this image style.
+ $form['effects'] = array(
+ '#theme' => 'image_style_effects',
+ // Render effects below parent elements.
+ '#weight' => 5,
+ );
+ foreach ($this->entity->getEffects()->sort() as $effect) {
+ $key = $effect->getUuid();
+ $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
+ $form['effects'][$key]['label'] = array(
+ '#markup' => String::checkPlain($effect->label()),
+ );
+ $form['effects'][$key]['summary'] = $effect->getSummary();
+ $form['effects'][$key]['weight'] = array(
+ '#type' => 'weight',
+ '#title' => $this->translator->translate('Weight for @title', array('@title' => $effect->label())),
+ '#title_display' => 'invisible',
+ '#default_value' => $effect->getWeight(),
+ );
+
+ $links = array();
+ $is_configurable = $effect instanceof ConfigurableImageEffectInterface;
+ if ($is_configurable) {
+ $links['edit'] = array(
+ 'title' => $this->translator->translate('edit'),
+ 'href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key,
+ );
+ }
+ $links['delete'] = array(
+ 'title' => $this->translator->translate('delete'),
+ 'href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key . '/delete',
+ );
+ $form['effects'][$key]['operations'] = array(
+ '#type' => 'operations',
+ '#links' => $links,
+ );
+ $form['effects'][$key]['configure'] = array(
+ '#type' => 'link',
+ '#title' => $this->translator->translate('edit'),
+ '#href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key,
+ '#access' => $is_configurable,
+ );
+ $form['effects'][$key]['remove'] = array(
+ '#type' => 'link',
+ '#title' => $this->translator->translate('delete'),
+ '#href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key . '/delete',
+ );
+ }
+
+ // Build the new image effect addition form and add it to the effect list.
+ $new_effect_options = array();
+ $effects = $this->imageEffectManager->getDefinitions();
+ uasort($effects, function ($a, $b) {
+ return strcasecmp($a['id'], $b['id']);
+ });
+ foreach ($effects as $effect => $definition) {
+ $new_effect_options[$effect] = $definition['label'];
+ }
+ $form['effects']['new'] = array(
+ '#tree' => FALSE,
+ '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
+ );
+ $form['effects']['new']['new'] = array(
+ '#type' => 'select',
+ '#title' => $this->translator->translate('Effect'),
+ '#title_display' => 'invisible',
+ '#options' => $new_effect_options,
+ '#empty_option' => $this->translator->translate('Select a new effect'),
+ );
+ $form['effects']['new']['weight'] = array(
+ '#type' => 'weight',
+ '#title' => $this->translator->translate('Weight for new effect'),
+ '#title_display' => 'invisible',
+ '#default_value' => count($form['effects']) - 1,
+ );
+ $form['effects']['new']['add'] = array(
+ '#type' => 'submit',
+ '#value' => $this->translator->translate('Add'),
+ '#validate' => array(array($this, 'effectValidate')),
+ '#submit' => array(array($this, 'effectSave')),
+ );
+
+ return parent::form($form, $form_state);
+ }
+
+ /**
+ * Validate handler for image effect.
+ */
+ public function effectValidate($form, &$form_state) {
+ if (!$form_state['values']['new']) {
+ form_error($form['effects']['new']['new'], $this->translator->translate('Select an effect to add.'));
+ }
+ }
+
+ /**
+ * Submit handler for image effect.
+ */
+ public function effectSave($form, &$form_state) {
+
+ // Update image effect weights.
+ if (!empty($form_state['values']['effects'])) {
+ $this->updateEffectWeights($form_state['values']['effects']);
+ }
+
+ $this->entity->set('name', $form_state['values']['name']);
+ $this->entity->set('label', $form_state['values']['label']);
+
+ $status = parent::save($form, $form_state);
+
+ if ($status == SAVED_UPDATED) {
+ drupal_set_message($this->translator->translate('Changes to the style have been saved.'));
+ }
+
+ // Check if this field has any configuration options.
+ $effect = $this->imageEffectManager->getDefinition($form_state['values']['new']);
+
+ // Load the configuration form for this option.
+ if (is_subclass_of($effect['class'], '\Drupal\image\ConfigurableImageEffectInterface')) {
+ $path = 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/add/' . $form_state['values']['new'];
+ $form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));
+ }
+ // If there's no form, immediately add the image effect.
+ else {
+ $effect = array(
+ 'id' => $effect['id'],
+ 'data' => array(),
+ 'weight' => $form_state['values']['weight'],
+ );
+ $effect_id = $this->entity->saveImageEffect($effect);
+ if (!empty($effect_id)) {
+ drupal_set_message($this->translator->translate('The image effect was successfully applied.'));
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save(array $form, array &$form_state) {
+
+ // Update image effect weights.
+ if (!empty($form_state['values']['effects'])) {
+ $this->updateEffectWeights($form_state['values']['effects']);
+ }
+
+ parent::save($form, $form_state);
+ drupal_set_message($this->translator->translate('Changes to the style have been saved.'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function actions(array $form, array &$form_state) {
+ $actions = parent::actions($form, $form_state);
+ $actions['submit']['#value'] = $this->translator->translate('Update style');
+
+ return $actions;
+ }
+
+ /**
+ * Updates image effect weights.
+ *
+ * @param array $effects
+ * Associative array with effects having effect uuid as keys and and array
+ * with effect data as values.
+ */
+ protected function updateEffectWeights(array $effects) {
+ foreach ($effects as $uuid => $effect_data) {
+ if ($this->entity->getEffects()->has($uuid)) {
+ $this->entity->getEffect($uuid)->setWeight($effect_data['weight']);
+ }
+ }
+ }
+
+}
diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleFormBase.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleFormBase.php
new file mode 100644
index 0000000..a050434
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleFormBase.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\Form\ImageStyleFormBase.
+ */
+
+namespace Drupal\image\Form;
+
+use Drupal\Core\Entity\EntityControllerInterface;
+use Drupal\Core\Entity\EntityFormController;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Base form controller for image style add and edit forms.
+ */
+abstract class ImageStyleFormBase extends EntityFormController implements EntityControllerInterface {
+
+ /**
+ * The image style entity storage controller.
+ *
+ * @var \Drupal\Core\Entity\EntityStorageControllerInterface
+ */
+ protected $imageStyleStorage;
+
+ /**
+ * The translator service.
+ *
+ * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
+ */
+ protected $translator;
+
+ /**
+ * Constructs a base class for image style add and edit forms.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler service.
+ * @param \Drupal\Core\Entity\EntityStorageControllerInterface $image_style_storage
+ * The image style entity storage controller.
+ * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
+ * The translator service.
+ */
+ public function __construct(ModuleHandlerInterface $module_handler, EntityStorageControllerInterface $image_style_storage, TranslatorInterface $translator) {
+ parent::__construct($module_handler);
+ $this->imageStyleStorage = $image_style_storage;
+ $this->translator = $translator;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
+ return new static(
+ $container->get('module_handler'),
+ $container->get('plugin.manager.entity')->getStorageController($entity_type),
+ $container->get('string_translation')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function form(array $form, array &$form_state) {
+
+ $form['label'] = array(
+ '#type' => 'textfield',
+ '#title' => $this->translator->translate('Image style name'),
+ '#default_value' => $this->entity->label(),
+ '#required' => TRUE,
+ );
+ $form['name'] = array(
+ '#type' => 'machine_name',
+ '#machine_name' => array(
+ 'exists' => array($this->imageStyleStorage, 'load'),
+ ),
+ '#default_value' => $this->entity->id(),
+ '#required' => TRUE,
+ );
+
+ return parent::form($form, $form_state);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save(array $form, array &$form_state) {
+ $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->entity->id();
+ return $this->entity->save();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function actions(array $form, array &$form_state) {
+ $actions = parent::actions($form, $form_state);
+ unset($actions['delete']);
+ return $actions;
+ }
+
+}
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php b/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php
new file mode 100644
index 0000000..9d5fb5f
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\ImageStyleAccessController.
+ */
+
+namespace Drupal\image;
+
+use Drupal\Core\Entity\EntityAccessController;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines an access controller for the image style entity.
+ *
+ * @see \Drupal\image\Plugin\Core\Entity\ImageStyle
+ */
+class ImageStyleAccessController extends EntityAccessController {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
+ switch ($operation) {
+ case 'create':
+ case 'update':
+ case 'delete':
+ return $account->hasPermission('administer image styles');
+ break;
+ }
+ }
+
+}
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php
new file mode 100644
index 0000000..c4b7e64
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\ImageStyleListController.
+ */
+
+namespace Drupal\image;
+
+use Drupal\Core\Config\Entity\ConfigEntityListController;
+use Drupal\Core\Entity\EntityControllerInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Routing\PathBasedGeneratorInterface;
+use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Provides a listing of image styles.
+ */
+class ImageStyleListController extends ConfigEntityListController implements EntityControllerInterface {
+
+ /**
+ * The URL generator.
+ *
+ * @var \Drupal\Core\Routing\PathBasedGeneratorInterface
+ */
+ protected $urlGenerator;
+
+ /**
+ * The translation manager service.
+ *
+ * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
+ */
+ protected $translator;
+
+ /**
+ * Constructs a new ImageStyleListController object.
+ *
+ * @param string $entity_type
+ * The type of entity to be listed.
+ * @param array $entity_info
+ * An array of entity info for the entity type.
+ * @param \Drupal\Core\Entity\EntityStorageControllerInterface $image_style_storage
+ * The image style entity storage controller class.
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler to invoke hooks on.
+ * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator
+ * The URL generator.
+ * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
+ * The translation manager.
+ */
+ public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $image_style_storage, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, TranslatorInterface $translator) {
+ parent::__construct($entity_type, $entity_info, $image_style_storage, $module_handler);
+ $this->urlGenerator = $url_generator;
+ $this->translator = $translator;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
+ return new static(
+ $entity_type,
+ $entity_info,
+ $container->get('plugin.manager.entity')->getStorageController($entity_type),
+ $container->get('module_handler'),
+ $container->get('url_generator'),
+ $container->get('string_translation')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildHeader() {
+ $row = parent::buildHeader();
+ unset($row['id']);
+ $row['label'] = $this->translator->translate('Style name');
+ return $row;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildRow(EntityInterface $entity) {
+ $row = parent::buildRow($entity);
+ unset($row['id']);
+ return $row;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function render() {
+ $build = parent::render();
+ $build['#empty'] = $this->translator->translate('There are currently no styles. <a href="!url">Add a new one</a>.', array(
+ '!url' => $this->urlGenerator->generateFromPath('admin/config/media/image-styles/add'),
+ ));
+ return $build;
+ }
+
+}
diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php
index ed17dee..4683ff6 100644
--- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php
+++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php
@@ -27,9 +27,13 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
* module = "image",
* controllers = {
* "form" = {
+ * "add" = "Drupal\image\Form\ImageStyleAddForm",
+ * "edit" = "Drupal\image\Form\ImageStyleEditForm",
* "delete" = "Drupal\image\Form\ImageStyleDeleteForm"
* },
- * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
+ * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
+ * "list" = "Drupal\image\ImageStyleListController",
+ * "access" = "Drupal\image\ImageStyleAccessController"
* },
* uri_callback = "image_style_entity_uri",
* config_prefix = "image.style",
diff --git a/core/modules/image/lib/Drupal/image/Plugin/Menu/LocalAction/ImageStyleAddLocalAction.php b/core/modules/image/lib/Drupal/image/Plugin/Menu/LocalAction/ImageStyleAddLocalAction.php
new file mode 100644
index 0000000..0af82bf
--- /dev/null
+++ b/core/modules/image/lib/Drupal/image/Plugin/Menu/LocalAction/ImageStyleAddLocalAction.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\image\Plugin\Menu\ImageStyleAddLocalAction.
+ */
+
+namespace Drupal\image\Plugin\Menu\LocalAction;
+
+use Drupal\Core\Annotation\Translation;
+use Drupal\Core\Menu\LocalActionBase;
+use Drupal\Core\Annotation\Menu\LocalAction;
+
+/**
+ * @LocalAction(
+ * id = "image_style_add_action",
+ * route_name = "image_style_add",
+ * title = @Translation("Add image style"),
+ * appears_on = {"image_style_list"}
+ * )
+ */
+class ImageStyleAddLocalAction extends LocalActionBase {
+
+}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
index f34b246..6bcf733 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
@@ -390,4 +390,16 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
$this->assertEqual($this->getImageCount($style), 0, 'Image style was flushed after being deleted by config import.');
}
+ /**
+ * Tests access for the image style listing.
+ */
+ public function testImageStyleAccess() {
+ $style = entity_create('image_style', array('name' => 'style_foo', 'label' => $this->randomString()));
+ $style->save();
+
+ $this->drupalGet('admin/config/media/image-styles');
+ $this->clickLink(t('Edit'));
+ $this->assertRaw(t('Select a new effect'));
+ }
+
}