Commit 2ba6140a authored by catch's avatar catch
Browse files

Issue #1946450 by ayelet_Cr: Convert confirm_form() in...

Issue #1946450 by ayelet_Cr: Convert confirm_form() in picture_mapping.admin.inc to the new form interface.
parent 53f4afe3
<?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';
}
}
......@@ -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;
......
picture_mapping_action_confirm:
pattern: '/admin/config/media/picturemapping/{picture_mapping}/delete'
defaults:
_form: '\Drupal\picture\Form\PictureMappingActionConfirmForm'
requirements:
_permission: 'administer pictures'
......@@ -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';
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment