diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc index e1cbbbf..e8dfe20 100644 --- a/core/modules/image/image.admin.inc +++ b/core/modules/image/image.admin.inc @@ -71,22 +71,22 @@ function image_style_form($form, &$form_state, $style) { '#theme' => 'image_style_effects', ); if (!empty($style->effects)) { - foreach ($style->effects as $key => $effect) { - $effect_instance = $manager->getInstance($effect); + foreach ($style->effects as $key => $effect_info) { + $effect = $manager->getInstance($effect_info); $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL; $form['effects'][$key]['label'] = array( - '#markup' => check_plain($effect['label']), + '#markup' => check_plain($effect->label()), ); - $form['effects'][$key]['summary'] = $effect_instance->getSummary(); + $form['effects'][$key]['summary'] = $effect->getSummary(); $form['effects'][$key]['weight'] = array( '#type' => 'weight', - '#title' => t('Weight for @title', array('@title' => $effect['label'])), + '#title' => t('Weight for @title', array('@title' => $effect->label())), '#title_display' => 'invisible', - '#default_value' => $effect['weight'], + '#default_value' => $effect_info['weight'], ); $links = array(); - if (!$effect['no_form']) { + if ($effect->hasForm()) { $links['edit'] = array( 'title' => t('edit'), 'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key, @@ -104,7 +104,7 @@ function image_style_form($form, &$form_state, $style) { '#type' => 'link', '#title' => t('edit'), '#href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key, - '#access' => !$effect['no_form'], + '#access' => $effect->hasForm(), ); $form['effects'][$key]['remove'] = array( '#type' => 'link', @@ -264,112 +264,6 @@ function image_style_add_form_submit($form, &$form_state) { } /** - * Form builder; Form for adding and editing image effects. - * - * This form is used universally for editing all image effects. Each effect adds - * its own custom section to the form by overriding - * \Drupal\image\ImageEffectInterface::getForm(). - * - * @param $form_state - * An associative array containing the current state of the form. - * @param $style - * An image style array. - * @param $effect - * An image effect array. - * - * @ingroup forms - * - * @see image_effect_form_submit() - */ -function image_effect_form($form, &$form_state, $style, $effect) { - // If there's no configuration for this image effect, return to - // the image style page. - if ($effect['no_form']) { - return new RedirectResponse(url('admin/config/media/image-styles/manage/' . $style->id(), array('absolute' => TRUE))); - } - $form_state['image_style'] = $style; - $form_state['image_effect'] = $effect; - - if (!empty($effect['ieid'])) { - $title = t('Edit %label effect', array('%label' => $effect['label'])); - } - else{ - $title = t('Add %label effect', array('%label' => $effect['label'])); - } - drupal_set_title($title, PASS_THROUGH); - - $form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array(); - - $form['ieid'] = array( - '#type' => 'value', - '#value' => !empty($effect['ieid']) ? $effect['ieid'] : NULL, - ); - $form['id'] = array( - '#type' => 'value', - '#value' => $effect['id'], - ); - - $form['data'] = Drupal::service('plugin.manager.image.effect')->getInstance($effect)->getForm(); - $form['data']['#tree'] = TRUE; - - // Check the URL for a weight, then the image effect, otherwise use default. - $weight = Drupal::request()->query->get('weight'); - $form['weight'] = array( - '#type' => 'hidden', - '#value' => isset($weight) ? intval($weight) : (isset($effect['weight']) ? $effect['weight'] : count($style->effects)), - ); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => !empty($effect['ieid']) ? t('Update effect') : t('Add effect'), - ); - $form['actions']['cancel'] = array( - '#type' => 'link', - '#title' => t('Cancel'), - '#href' => 'admin/config/media/image-styles/manage/' . $style->id(), - ); - - return $form; -} - -/** - * Submit handler for updating an image effect. - */ -function image_effect_form_submit($form, &$form_state) { - form_state_values_clean($form_state); - - $effect = $form_state['values']; - $style = $form_state['image_style']; - image_effect_save($style, $effect); - - drupal_set_message(t('The image effect was successfully applied.')); - $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id(); -} - -/** - * Element validate handler to ensure a hexadecimal color value. - */ -function image_effect_color_validate($element, &$form_state) { - if ($element['#value'] != '') { - $hex_value = preg_replace('/^#/', '', $element['#value']); - if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) { - form_error($element, t('!name must be a hexadecimal color value.', array('!name' => $element['#title']))); - } - } -} - -/** - * Element validate handler to ensure that either a height or a width is - * specified. - */ -function image_effect_scale_validate($element, &$form_state) { - if (empty($element['width']['#value']) && empty($element['height']['#value'])) { - form_error($element, t('Width and height can not both be blank.')); - } -} - -/** * Returns HTML for the page containing the list of image styles. * * @param $variables diff --git a/core/modules/image/image.install b/core/modules/image/image.install index fd440da..78eabeb 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -133,6 +133,10 @@ function _image_update_get_style_with_effects(array $style) { $uuid = new Uuid(); $effect['ieid'] = $uuid->generate(); + // Use 'id' instead of 'name'. + $effect['id'] = $effect['name']; + unset($effect['name']); + $effects[$effect['ieid']] = $effect; } return $effects; diff --git a/core/modules/image/image.module b/core/modules/image/image.module index d3bb6ab..6ea2b92 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -9,6 +9,8 @@ use Drupal\Core\Language\Language; use Drupal\field\Plugin\Core\Entity\Field; use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\image\ImageEffectInterface; +use Drupal\image\ImageStyleInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -173,28 +175,20 @@ function image_menu() { 'weight' => 10, 'route_name' => 'image_style_delete', ); - $items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect'] = array( + $items['admin/config/media/image-styles/manage/%/effects/%'] = array( 'title' => 'Edit image effect', 'description' => 'Edit an existing effect within a style.', - 'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('image_effect_form', 5, 7), - 'access arguments' => array('administer image styles'), - 'file' => 'image.admin.inc', + 'route_name' => 'image_effect_edit_form', ); - $items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect/delete'] = array( + $items['admin/config/media/image-styles/manage/%image_style/effects/%/delete'] = array( 'title' => 'Delete image effect', 'description' => 'Delete an existing effect from a style.', 'route_name' => 'image_effect_delete', ); - $items['admin/config/media/image-styles/manage/%image_style/add/%image_effect_definition'] = array( + $items['admin/config/media/image-styles/manage/%/add/%'] = array( 'title' => 'Add image effect', 'description' => 'Add a new effect to a style.', - 'load arguments' => array(5), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('image_effect_form', 5, 7), - 'access arguments' => array('administer image styles'), - 'file' => 'image.admin.inc', + 'route_name' => 'image_effect_add_form', ); return $items; @@ -221,35 +215,45 @@ 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', ), 'image_style_preview' => array( 'variables' => array('style' => NULL), + 'file' => 'image.admin.inc', ), 'image_anchor' => array( 'render element' => 'element', + 'file' => 'image.admin.inc', ), 'image_resize_summary' => array( 'variables' => array('data' => NULL), + 'file' => 'image.admin.inc', ), 'image_scale_summary' => array( 'variables' => array('data' => NULL), + 'file' => 'image.admin.inc', ), 'image_crop_summary' => array( 'variables' => array('data' => NULL), + 'file' => 'image.admin.inc', ), 'image_rotate_summary' => array( 'variables' => array('data' => NULL), + 'file' => 'image.admin.inc', ), // Theme functions in image.field.inc. 'image_widget' => array( 'render element' => 'element', + 'file' => 'image.field.inc', ), 'image_formatter' => array( 'variables' => array('item' => NULL, 'path' => NULL, 'image_style' => NULL), + 'file' => 'image.field.inc', ), ); } @@ -749,8 +753,6 @@ function image_effect_definition_load($effect) { function image_effect_load($ieid, $style_name) { if (($style = entity_load('image_style', $style_name)) && isset($style->effects[$ieid])) { $effect = $style->effects[$ieid]; - $definition = Drupal::service('plugin.manager.image.effect')->getDefinition($effect['id']); - $effect = array_merge($definition, $effect); // @todo The effect's key name within the style is unknown. It *should* be // identical to the ieid, but that is in no way guaranteed. And of course, // the ieid key *within* the effect is senseless duplication in the first @@ -763,6 +765,12 @@ function image_effect_load($ieid, $style_name) { } return NULL; } +function image_effect_load_plugin($ieid, $style_name) { + if (($style = entity_load('image_style', $style_name)) && isset($style->effects[$ieid])) { + $effect = $style->effects[$ieid]; + return Drupal::service('plugin.manager.image.effect')->getInstance($effect); + } +} /** * Saves an image effect. @@ -794,20 +802,6 @@ function image_effect_save($style, &$effect) { } /** - * Deletes an image effect. - * - * @param ImageStyle $style - * The image style this effect belongs to. - * @param $effect - * An image effect array. - */ -function image_effect_delete($style, $effect) { - unset($style->effects[$effect['ieid']]); - $style->save(); - image_style_flush($style); -} - -/** * Returns HTML for an image using a specific image style. * * @param $variables diff --git a/core/modules/image/image.routing.yml b/core/modules/image/image.routing.yml index b178d33..01a7d53 100644 --- a/core/modules/image/image.routing.yml +++ b/core/modules/image/image.routing.yml @@ -11,3 +11,17 @@ image_effect_delete: _form: '\Drupal\image\Form\ImageEffectDeleteForm' requirements: _permission: 'administer image styles' + +image_effect_add_form: + pattern: '/admin/config/media/image-styles/manage/{image_style}/add/{image_effect}' + defaults: + _form: '\Drupal\image\Form\ImageEffectAddForm' + requirements: + _permission: 'administer image styles' + +image_effect_edit_form: + pattern: '/admin/config/media/image-styles/manage/{image_style}/effects/{image_effect}' + defaults: + _form: '\Drupal\image\Form\ImageEffectEditForm' + requirements: + _permission: 'administer image styles' diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php new file mode 100644 index 0000000..2bd65a2 --- /dev/null +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectAddForm.php @@ -0,0 +1,36 @@ +imageEffect = $this->effectManager->createInstance($image_effect); + if (!$this->imageEffect->hasForm()) { + return new RedirectResponse(url('admin/config/media/image-styles/manage/' . $image_style->id(), array('absolute' => TRUE))); + } + drupal_set_title(t('Add %label effect', array('%label' => $this->imageEffect->label())), PASS_THROUGH); + + $form = parent::buildForm($form, $form_state, $request, $image_style); + + $form['actions']['submit']['#value'] = t('Add effect'); + + return $form; + } + +} diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php index 50bf2bb..4bd2044 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php @@ -7,14 +7,22 @@ namespace Drupal\image\Form; +use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Form\ConfirmFormBase; +use Drupal\image\ImageEffectManager; use Drupal\image\Plugin\Core\Entity\ImageStyle; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** * Form for deleting an image effect. */ -class ImageEffectDeleteForm extends ConfirmFormBase { +class ImageEffectDeleteForm extends ConfirmFormBase implements ControllerInterface { + + /** + * @var \Drupal\image\ImageEffectManager + */ + protected $effectManager; /** * The image style containing the image effect to be deleted. @@ -26,15 +34,28 @@ class ImageEffectDeleteForm extends ConfirmFormBase { /** * The image effect to be deleted. * - * @var array; + * @var \Drupal\image\ImageEffectInterface */ protected $imageEffect; + 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 getQuestion() { - return t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect['label'])); + return t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect->label())); } /** @@ -63,7 +84,7 @@ public function getFormID() { */ public function buildForm(array $form, array &$form_state, $image_style = NULL, $image_effect = NULL, Request $request = NULL) { $this->imageStyle = $image_style; - $this->imageEffect = image_effect_load($image_effect, $this->imageStyle->id()); + $this->imageEffect = $this->effectManager->getInstance($this->imageStyle->effects[$image_effect]); return parent::buildForm($form, $form_state, $request); } @@ -72,8 +93,8 @@ public function buildForm(array $form, array &$form_state, $image_style = NULL, * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - image_effect_delete($this->imageStyle, $this->imageEffect); - drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $this->imageEffect['label']))); + $this->imageStyle->deleteImageEffect($this->imageEffect); + drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $this->imageEffect->label()))); $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->imageStyle->id(); } diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php new file mode 100644 index 0000000..501d7d0 --- /dev/null +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectEditForm.php @@ -0,0 +1,42 @@ +effects[$image_effect]; + $this->imageEffect = $this->effectManager->getInstance($image_effect_info); + if (!$this->imageEffect->hasForm()) { + return new RedirectResponse(url('admin/config/media/image-styles/manage/' . $image_style->id(), array('absolute' => TRUE))); + } + drupal_set_title(t('Edit %label effect', array('%label' => $this->imageEffect->label())), PASS_THROUGH); + + $form = parent::buildForm($form, $form_state, $request, $image_style); + + $form['actions']['submit']['#value'] = t('Update effect'); + + // If the weight is not specified in the URL, use the default. + if (isset($image_effect_info['weight']) && !$request->query->has('weight')) { + $form['weight']['#value'] = $image_effect_info['weight']; + } + + return $form; + } + +} diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php new file mode 100644 index 0000000..c1227e9 --- /dev/null +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectFormBase.php @@ -0,0 +1,113 @@ +effectManager = $effect_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.image.effect') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'image_effect_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Request $request = NULL, ImageStyleInterface $image_style = NULL) { + $this->imageStyle = $image_style; + + $form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array(); + $form['ieid'] = array( + '#type' => 'value', + '#value' => NULL, + ); + $form['id'] = array( + '#type' => 'value', + '#value' => $this->imageEffect->getPluginId(), + ); + + $form['data'] = $this->imageEffect->getForm(); + $form['data']['#tree'] = TRUE; + + // Check the URL for a weight, then the image effect, otherwise use default. + $form['weight'] = array( + '#type' => 'hidden', + '#value' => $request->query->has('weight') ? intval($request->query->get('weight')) : count($this->imageStyle->effects), + ); + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#button_type' => 'primary', + ); + $form['actions']['cancel'] = array( + '#type' => 'link', + '#title' => t('Cancel'), + '#href' => 'admin/config/media/image-styles/manage/' . $this->imageStyle->id(), + ); + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + form_state_values_clean($form_state); + + image_effect_save($this->imageStyle, $form_state['values']); + + drupal_set_message(t('The image effect was successfully applied.')); + $form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $this->imageStyle->id(); + } + +} diff --git a/core/modules/image/lib/Drupal/image/ImageEffectBase.php b/core/modules/image/lib/Drupal/image/ImageEffectBase.php index b3864e2..ce24699 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectBase.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectBase.php @@ -37,4 +37,18 @@ public function getForm() { return array(); } + public function hasForm() { + $definition = $this->getPluginDefinition(); + return !$definition['no_form']; + } + + public function label() { + $definition = $this->getPluginDefinition(); + return $definition['label']; + } + + public function getUuid() { + return isset($this->configuration['ieid']) ? $this->configuration['ieid'] : ''; + } + } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectInterface.php b/core/modules/image/lib/Drupal/image/ImageEffectInterface.php index 825b197..910c864 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectInterface.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectInterface.php @@ -7,10 +7,12 @@ namespace Drupal\image; +use Drupal\Component\Plugin\PluginInspectionInterface; + /** * @todo. */ -interface ImageEffectInterface { +interface ImageEffectInterface extends PluginInspectionInterface { /** * Applies an image effect to the image object. @@ -36,4 +38,10 @@ public function getSummary(); public function getForm(); + public function hasForm(); + + public function label(); + + public function getUuid(); + } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectManager.php b/core/modules/image/lib/Drupal/image/ImageEffectManager.php index 7fff8b1..b75c80c7 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectManager.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectManager.php @@ -50,7 +50,25 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac */ public function getInstance(array $options) { $options += array('data' => array()); + if (isset($options['ieid'])) { + $options['data']['ieid'] = $options['ieid']; + } return $this->createInstance($options['id'], $options['data']); } + /** + * Returns a preconfigured image effect plugin. + * + * @param string $plugin_id + * The ID of the plugin being instantiated. + * @param array $configuration + * An array of configuration relevant to the plugin instance. + * + * @return \Drupal\image\ImageEffectInterface + * An image effect plugin. + */ + public function createInstance($plugin_id, array $configuration = array()) { + return parent::createInstance($plugin_id, $configuration); + } + } diff --git a/core/modules/image/lib/Drupal/image/ImageStyleInterface.php b/core/modules/image/lib/Drupal/image/ImageStyleInterface.php index 87367d3..0607724 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleInterface.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleInterface.php @@ -8,10 +8,13 @@ namespace Drupal\image; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\image\ImageEffectInterface; /** * Provides an interface defining an image style entity. */ interface ImageStyleInterface extends ConfigEntityInterface { + public function deleteImageEffect(ImageEffectInterface $effect); + } diff --git a/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php b/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php index 8459d7a..64917d8 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleStorageController.php @@ -22,11 +22,13 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) { $manager = \Drupal::service('plugin.manager.image.effect'); foreach ($queried_entities as $style) { if (!empty($style->effects)) { + /* foreach ($style->effects as $ieid => $effect) { $definition = $manager->getDefinition($effect['id']); $effect = array_merge($definition, $effect); $style->effects[$ieid] = $effect; } + //*/ // Sort effects by weight. uasort($style->effects, 'drupal_sort_weight'); } 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 2e99768..abb8f21 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 @@ -11,6 +11,7 @@ use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\image\ImageEffectInterface; use Drupal\image\ImageStyleInterface; /** @@ -148,4 +149,10 @@ protected static function replaceImageStyle(ImageStyle $style) { } } + public function deleteImageEffect(ImageEffectInterface $effect) { + unset($this->effects[$effect->getUuid()]); + $this->save(); + image_style_flush($this); + } + } diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php index 5bf0d28..51ed51d 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/RotateImageEffect.php @@ -106,7 +106,7 @@ public function getForm() { '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'), '#size' => 7, '#maxlength' => 7, - '#element_validate' => array('image_effect_color_validate'), + '#element_validate' => array(array($this, 'validateColorEffect')), ); $form['random'] = array( '#type' => 'checkbox', @@ -117,4 +117,15 @@ public function getForm() { return $form; } + /** + * Validates to ensure a hexadecimal color value. + */ + public function validateColorEffect(array $element, array &$form_state) { + if ($element['#value'] != '') { + if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) { + form_error($element, t('!name must be a hexadecimal color value.', array('!name' => $element['#title']))); + } + } + } + } diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php index aab5ae8..45a6724 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php @@ -64,7 +64,7 @@ public function getSummary() { */ public function getForm() { $form = parent::getForm(); - $form['#element_validate'] = array('image_effect_scale_validate'); + $form['#element_validate'] = array(array($this, 'validateScaleEffect')); $form['width']['#required'] = FALSE; $form['height']['#required'] = FALSE; $form['upscale'] = array( @@ -76,4 +76,13 @@ public function getForm() { return $form; } + /** + * Validates to ensure that either a height or a width is specified. + */ + public function validateScaleEffect(array $element, array &$form_state) { + if (empty($element['width']['#value']) && empty($element['height']['#value'])) { + form_error($element, t('Width and height can not both be blank.')); + } + } + } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 1f842a1..23681b1 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -219,7 +219,8 @@ function testStyle() { $this->drupalPost($style_path . '/effects/' . $ieids['image_crop'] . '/delete', array(), t('Delete')); // Confirm that the form submission was successful. $this->assertResponse(200); - $this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $style->effects[$ieids['image_crop']]['label']))); + $image_crop_effect = $this->container->get('plugin.manager.image.effect')->getInstance($style->effects[$ieids['image_crop']]); + $this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $image_crop_effect->label()))); // Confirm that there is no longer a link to the effect. $this->assertNoLinkByHref($style_path . '/effects/' . $ieids['image_crop'] . '/delete'); // Refresh the image style information and verify that the effect was diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php index 802690d..b105628 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php @@ -212,6 +212,7 @@ function testImageDimensions() { ), 'weight' => 7, ); + $effect_plugin = $this->container->get('plugin.manager.image.effect')->getInstance($effect); image_effect_save($style, $effect); $img_tag = theme_image_style($variables); @@ -221,7 +222,7 @@ function testImageDimensions() { $this->assertResponse(200, 'Image was generated at the URL.'); $this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.'); - image_effect_delete($style, $effect); + $style->deleteImageEffect($effect_plugin); // Ensure that an effect with no dimensions callback unsets the dimensions. // This ensures compatibility with 7.0 contrib modules. diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php index 4ec5fb5..d5c8e9d 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageEffectsTest.php @@ -156,7 +156,7 @@ function testImageEffectsCaching() { // Second call should come from cache. drupal_static_reset('image_module_test_image_effect_info_alter'); $cached_effects = $manager->getDefinitions(); - $this->assertTrue(is_null($image_effect_definitions_called), 'image_effect_definitions() returned data from cache.'); + $this->assertTrue($image_effect_definitions_called === 0, 'image_effect_definitions() returned data from cache.'); $this->assertTrue($effects == $cached_effects, 'Cached effects are the same as generated effects.'); } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index 596816c..4a6491b 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -22,7 +22,6 @@ * image_style_flush() * image_effect_load() * image_effect_save() - * image_effect_delete() * image_filter_keyword() */