diff --git a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php new file mode 100644 index 0000000000000000000000000000000000000000..10387007b8bff2f98c6c713c09d48198d53300d8 --- /dev/null +++ b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php @@ -0,0 +1,68 @@ +<?php + +/** + * @file + * Contains \Drupal\picture\Form\PictureMappingActionConfirm. + */ + +namespace Drupal\picture\Form; + +use Drupal\Core\Form\ConfirmFormBase; +use Drupal\Core\Entity\EntityInterface; + +class PictureMappingActionConfirmForm extends ConfirmFormBase { + + /** + * The picture mapping object to be deleted. + * + * @var type \Drupal\Core\Entity\EntityInterface + */ + protected $pictureMapping; + + /** + * {@inheritdoc} + */ + protected function getQuestion() { + return t('Are you sure you want to delete the picture_mapping %title?', array('%title' => $this->pictureMapping->label())); + } + + /** + * {@inheritdoc} + */ + protected function getCancelPath() { + return 'admin/config/media/picturemapping'; + } + + /** + * {@inheritdoc} + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'picture_mapping_action_confirm'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, EntityInterface $picture_mapping = NULL) { + $this->pictureMapping = $picture_mapping; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->pictureMapping->delete(); + drupal_set_message(t('Picture mapping %label has been deleted.', array('%label' => $this->pictureMapping->label()))); + watchdog('picture', 'Picture mapping %label has been deleted.', array('%label' => $this->pictureMapping->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/config/media/picturemapping'; + } +} diff --git a/core/modules/picture/picture.module b/core/modules/picture/picture.module index e5a66dd272b6a90a5f16326bc69ce139028715f2..9dc9a6f3866ef31aab909f6a7668d77e5a49afac 100644 --- a/core/modules/picture/picture.module +++ b/core/modules/picture/picture.module @@ -87,11 +87,7 @@ function picture_menu() { ); $items['admin/config/media/picturemapping/%picture_mapping/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('picture_mapping_action_confirm', 4, 5), - 'access callback' => 'user_access', - 'access arguments' => array('administer pictures'), - 'file' => 'picture_mapping.admin.inc', + 'route_name' => 'picture_mapping_action_confirm', ); return $items; diff --git a/core/modules/picture/picture.routing.yml b/core/modules/picture/picture.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..96da6d3a82b33fa32f9ea41d570f67268dc83d98 --- /dev/null +++ b/core/modules/picture/picture.routing.yml @@ -0,0 +1,6 @@ +picture_mapping_action_confirm: + pattern: '/admin/config/media/picturemapping/{picture_mapping}/delete' + defaults: + _form: '\Drupal\picture\Form\PictureMappingActionConfirmForm' + requirements: + _permission: 'administer pictures' diff --git a/core/modules/picture/picture_mapping.admin.inc b/core/modules/picture/picture_mapping.admin.inc index a3d6ade98585eee1833be08a24760d37e5a0e103..800a96cce1bf999341b7449c26a9c4148b35397c 100644 --- a/core/modules/picture/picture_mapping.admin.inc +++ b/core/modules/picture/picture_mapping.admin.inc @@ -64,46 +64,3 @@ function picture_mapping_page_add() { $form = entity_get_form($picture_mapping); return $form; } - -/** - * Page callback: Form constructor for picture action confirmation form. - * - * @param Drupal\picture\PictureMapping $picture_mapping - * @param string $action - * - * @see picture_menu() - */ -function picture_mapping_action_confirm($form, &$form_state, $picture_mapping, $action) { - // Always provide entity id in the same form key as in the entity edit form. - if (in_array($action, array('delete'))) { - $form['id'] = array('#type' => 'value', '#value' => $picture_mapping->id()); - $form['action'] = array('#type' => 'value', '#value' => $action); - $form_state['picture_mapping'] = $picture_mapping; - $form = confirm_form($form, - t('Are you sure you want to @action the picture_mapping %title?', array('@action' => $action, '%title' => $picture_mapping->label())), - 'admin/config/media/picturemapping', - $action == 'delete' ? t('This action cannot be undone.') : '', - t(drupal_ucfirst($action)), - t('Cancel') - ); - } - return $form; -} - -/** - * Form submission handler for picture_action_confirm(). - */ -function picture_mapping_action_confirm_submit($form, &$form_state) { - $picture_mapping = $form_state['picture_mapping']; - $action = $form_state['values']['action']; - $picture_mapping->{$action}(); - $verb = ''; - switch ($action) { - case 'delete': - $verb = 'deleted'; - break; - } - drupal_set_message(t('Picture mapping %label has been @action.', array('%label' => $picture_mapping->label(), '@action' => $verb))); - watchdog('picture', 'Picture mapping %label has been @action.', array('%label' => $picture_mapping->label(), '@action' => $verb), WATCHDOG_NOTICE); - $form_state['redirect'] = 'admin/config/media/picturemapping'; -}