diff --git a/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php b/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php
index 02c43df..9d5fb5f 100644
--- a/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php
+++ b/core/modules/image/lib/Drupal/image/ImageStyleAccessController.php
@@ -7,9 +7,9 @@
namespace Drupal\image;
-use \Drupal\Core\Entity\EntityAccessController;
-use \Drupal\Core\Entity\EntityInterface;
-use \Drupal\Core\Session\AccountInterface;
+use Drupal\Core\Entity\EntityAccessController;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
/**
* Defines an access controller for the image style entity.
@@ -30,4 +30,5 @@ public function checkAccess(EntityInterface $entity, $operation, $langcode, Acco
break;
}
}
+
}
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleAddFormController.php b/core/modules/image/lib/Drupal/image/ImageStyleAddFormController.php
index 996c5df..48b543c 100644
--- a/core/modules/image/lib/Drupal/image/ImageStyleAddFormController.php
+++ b/core/modules/image/lib/Drupal/image/ImageStyleAddFormController.php
@@ -7,12 +7,46 @@
namespace Drupal\image;
+use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityFormController;
+use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base form controller for image style addition forms.
*/
-class ImageStyleAddFormController extends EntityFormController {
+class ImageStyleAddFormController extends EntityFormController implements EntityControllerInterface {
+
+ /**
+ * The translator service.
+ *
+ * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
+ */
+ protected $translator;
+
+ /**
+ * Constructs an ImageStyleAddFormController object.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler service.
+ * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
+ * The translator service.
+ */
+ public function __construct(ModuleHandlerInterface $module_handler, TranslatorInterface $translator) {
+ $this->moduleHandler = $module_handler;
+ $this->translator = $translator;
+ parent::__construct($this->moduleHandler);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
+ return new static(
+ $container->get('module_handler'),
+ $container->get('string_translation')
+ );
+ }
/**
* {@inheritdoc}
@@ -22,7 +56,7 @@ public function form(array $form, array &$form_state) {
$form['label'] = array(
'#type' => 'textfield',
- '#title' => t('Administrative label'),
+ '#title' => $this->translator->translate('Administrative label'),
'#default_value' => $this->entity->label(),
'#required' => TRUE,
'#weight' => 20,
@@ -45,9 +79,9 @@ public function form(array $form, array &$form_state) {
*/
public function save(array $form, array &$form_state) {
$this->entity->save();
- drupal_set_message(t('Style %name was created.', array('%name' => $this->entity->label())));
+ drupal_set_message($this->translator->translate('Style %name was created.', array('%name' => $this->entity->label())));
$uri = $this->entity->uri();
- watchdog('image', 'Style %name was created.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
+ watchdog('image', 'Style %name was created.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE, l($this->translator->translate('Edit'), $uri['path']));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->entity->id();
}
@@ -57,7 +91,7 @@ public function save(array $form, array &$form_state) {
public function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
- $actions['submit']['#value'] = t('Create new style');
+ $actions['submit']['#value'] = $this->translator->translate('Create new style');
unset($actions['delete']);
return $actions;
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleFormController.php b/core/modules/image/lib/Drupal/image/ImageStyleFormController.php
index e27f4ab..cd76f6e 100644
--- a/core/modules/image/lib/Drupal/image/ImageStyleFormController.php
+++ b/core/modules/image/lib/Drupal/image/ImageStyleFormController.php
@@ -7,14 +7,73 @@
namespace Drupal\image;
+use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityFormController;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\StringTranslation\Translator\TranslatorInterface;
+use Drupal\image\ImageEffectManager;
use Drupal\image\ImageStyleInterface;
use Drupal\Component\Utility\String;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base form controller for image style edit forms.
*/
-class ImageStyleFormController extends EntityFormController {
+class ImageStyleFormController extends EntityFormController implements EntityControllerInterface {
+
+ /**
+ * The entity manager service.
+ *
+ * @var \Drupal\Core\Entity\EntityManager
+ */
+ protected $entityManager;
+
+ /**
+ * The image effect manager service.
+ *
+ * @var \Drupal\image\ImageEffectManager
+ */
+ protected $imageEffectManager;
+
+ /**
+ * The translator service.
+ *
+ * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
+ */
+ protected $translator;
+
+ /**
+ * Constructs an ImageStyleFormController object.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ * The module handler service.
+ * @param \Drupal\Core\Entity\EntityManager $entity_manager
+ * The entity manager.
+ * @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, EntityManager $entity_manager, ImageEffectManager $image_effect_manager, TranslatorInterface $translator) {
+ $this->moduleHandler = $module_handler;
+ $this->entityManager = $entity_manager;
+ $this->imageEffectManager = $image_effect_manager;
+ $this->translator = $translator;
+ parent::__construct($this->moduleHandler);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
+ return new static(
+ $container->get('module_handler'),
+ $container->get('plugin.manager.entity'),
+ $container->get('plugin.manager.image.effect'),
+ $container->get('string_translation')
+ );
+ }
/**
* {@inheritdoc}
@@ -22,32 +81,33 @@ class ImageStyleFormController extends EntityFormController {
public function form(array $form, array &$form_state) {
$form = parent::form($form, $form_state);
$style = $this->entity;
+ $storage_controller = $this->entityManager->getStorageController('image_style');
// @todo Remove drupal_set_title() in http://drupal.org/node/1981644
- $title = t('Edit style %name', array('%name' => $style->label()));
+ $title = $this->translator->translate('Edit style %name', array('%name' => $style->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.
- form_load_include($form_state, 'inc', 'image', 'image.admin');
+ $preview_arguments = array('#theme' => 'image_style_preview', '#style' => $style);
$form['preview'] = array(
'#type' => 'item',
- '#title' => t('Preview'),
- '#markup' => theme('image_style_preview', array('style' => $style)),
+ '#title' => $this->translator->translate('Preview'),
+ '#markup' => drupal_render($preview_arguments),
);
$form['label'] = array(
'#type' => 'textfield',
- '#title' => t('Image style name'),
+ '#title' => $this->translator->translate('Image style name'),
'#default_value' => $style->label(),
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'machine_name',
'#machine_name' => array(
- 'exists' => 'image_style_load',
+ 'exists' => array($storage_controller, 'load'),
),
'#default_value' => $style->id(),
'#required' => TRUE,
@@ -66,7 +126,7 @@ public function form(array $form, array &$form_state) {
$form['effects'][$key]['summary'] = $effect->getSummary();
$form['effects'][$key]['weight'] = array(
'#type' => 'weight',
- '#title' => t('Weight for @title', array('@title' => $effect->label())),
+ '#title' => $this->translator->translate('Weight for @title', array('@title' => $effect->label())),
'#title_display' => 'invisible',
'#default_value' => $effect->getWeight(),
);
@@ -75,12 +135,12 @@ public function form(array $form, array &$form_state) {
$is_configurable = $effect instanceof ConfigurableImageEffectInterface;
if ($is_configurable) {
$links['edit'] = array(
- 'title' => t('edit'),
+ 'title' => $this->translator->translate('edit'),
'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key,
);
}
$links['delete'] = array(
- 'title' => t('delete'),
+ 'title' => $this->translator->translate('delete'),
'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key . '/delete',
);
$form['effects'][$key]['operations'] = array(
@@ -89,20 +149,20 @@ public function form(array $form, array &$form_state) {
);
$form['effects'][$key]['configure'] = array(
'#type' => 'link',
- '#title' => t('edit'),
+ '#title' => $this->translator->translate('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'),
+ '#title' => $this->translator->translate('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();
+ $effects = $this->imageEffectManager->getDefinitions();
uasort($effects, function ($a, $b) {
return strcasecmp($a['id'], $b['id']);
});
@@ -115,20 +175,20 @@ public function form(array $form, array &$form_state) {
);
$form['effects']['new']['new'] = array(
'#type' => 'select',
- '#title' => t('Effect'),
+ '#title' => $this->translator->translate('Effect'),
'#title_display' => 'invisible',
'#options' => $new_effect_options,
- '#empty_option' => t('Select a new effect'),
+ '#empty_option' => $this->translator->translate('Select a new effect'),
);
$form['effects']['new']['weight'] = array(
'#type' => 'weight',
- '#title' => t('Weight for new effect'),
+ '#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' => t('Add'),
+ '#value' => $this->translator->translate('Add'),
'#validate' => array(array($this, 'effectValidate')),
'#submit' => array(array($this, 'effectSave')),
);
@@ -141,7 +201,7 @@ public function form(array $form, array &$form_state) {
*/
public function effectValidate($form, &$form_state) {
if (!$form_state['values']['new']) {
- form_error($form['effects']['new']['new'], t('Select an effect to add.'));
+ form_error($form['effects']['new']['new'], $this->translator->translate('Select an effect to add.'));
}
}
@@ -161,11 +221,11 @@ public function effectSave($form, &$form_state) {
$status = $style->save();
if ($status == SAVED_UPDATED) {
- drupal_set_message(t('Changes to the style have been saved.'));
+ drupal_set_message($this->translator->translate('Changes to the style have been saved.'));
}
// Check if this field has any configuration options.
- $effect = \Drupal::service('plugin.manager.image.effect')->getDefinition($form_state['values']['new']);
+ $effect = $this->imageEffectManager->getDefinition($form_state['values']['new']);
// Load the configuration form for this option.
if (is_subclass_of($effect['class'], '\Drupal\image\ConfigurableImageEffectInterface')) {
@@ -181,7 +241,7 @@ public function effectSave($form, &$form_state) {
);
$effect_id = $style->saveImageEffect($effect);
if (!empty($effect_id)) {
- drupal_set_message(t('The image effect was successfully applied.'));
+ drupal_set_message($this->translator->translate('The image effect was successfully applied.'));
}
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
@@ -197,11 +257,11 @@ public function save(array $form, array &$form_state) {
if (!empty($form_state['values']['effects'])) {
$this->updateEffectWeights($style, $form_state['values']['effects']);
}
-
+
$style->save();
- drupal_set_message(t('Changes to the style have been saved.'));
+ drupal_set_message($this->translator->translate('Changes to the style have been saved.'));
$uri = $this->entity->uri();
- watchdog('image', 'Style %label has been updated.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path']));
+ watchdog('image', 'Style %label has been updated.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE, l($this->translator->translate('Edit'), $uri['path']));
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->entity->id();
}
@@ -211,7 +271,7 @@ public function save(array $form, array &$form_state) {
public function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
- $actions['submit']['#value'] = t('Update style');
+ $actions['submit']['#value'] = $this->translator->translate('Update style');
unset($actions['delete']);
return $actions;
@@ -226,7 +286,7 @@ public function actions(array $form, array &$form_state) {
* Associative array with effects having effect uuid as keys and and array
* with effect data as values.
*/
- protected function updateEffectWeights(ImageStyleInterface $style, array $effects) {
+ protected function updateEffectWeights(ImageStyleInterface $style, array $effects) {
foreach ($effects as $uuid => $effect_data) {
if ($style->getEffects()->has($uuid)) {
$style->getEffect($uuid)->setWeight($effect_data['weight']);
diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php
index 78659df..c0ca439 100644
--- a/core/modules/image/lib/Drupal/image/ImageStyleListController.php
+++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php
@@ -9,13 +9,13 @@
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityControllerInterface;
-use Drupal\Core\Routing\PathBasedGeneratorInterface;
-use Drupal\Core\StringTranslation\TranslationManager;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Routing\PathBasedGeneratorInterface;
+use Drupal\Core\StringTranslation\TranslationManager;
use Drupal\Component\Utility\String;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a listing of image styles.
@@ -32,9 +32,9 @@ class ImageStyleListController extends ConfigEntityListController implements Ent
/**
* The translation manager service.
*
- * @var \Drupal\Core\StringTranslation\TranslationManager
+ * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface
*/
- protected $translationManager;
+ protected $translator;
/**
* Constructs a new ImageStyleListController object.
@@ -49,13 +49,13 @@ class ImageStyleListController extends ConfigEntityListController implements Ent
* The module handler to invoke hooks on.
* @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator
* The URL generator.
- * @param \Drupal\Core\StringTranslation\TranslationManager $translation_manager
+ * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
* The translation manager.
*/
- public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, TranslationManager $translation_manager) {
+ public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, TranslatorInterface $translator) {
parent::__construct($entity_type, $entity_info, $storage, $module_handler);
$this->urlGenerator = $url_generator;
- $this->translationManager = $translation_manager;
+ $this->translator = $translator;
}
/**
@@ -78,7 +78,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ
public function buildHeader() {
$row = parent::buildHeader();
unset($row['id']);
- $row['label'] = $this->translationManager->translate('Style name');
+ $row['label'] = $this->translator->translate('Style name');
return $row;
}
@@ -97,7 +97,7 @@ public function buildRow(EntityInterface $entity) {
*/
public function render() {
$build = parent::render();
- $build['#empty'] = $this->translationManager->translate('There are currently no styles. Add a new one.', array(
+ $build['#empty'] = $this->translator->translate('There are currently no styles. Add a new one.', array(
'!url' => $this->urlGenerator->generateFromPath('admin/config/media/image-styles/add'),
));
return $build;