Commit 87434066 authored by alexpott's avatar alexpott

Issue #1946414 by larowlan | mtift: Convert confirm_form() in forum.admin.inc...

Issue #1946414 by larowlan | mtift: Convert confirm_form() in forum.admin.inc to the new form interface.
parent ee1c53e5
......@@ -21,9 +21,6 @@
*/
function forum_form_main($type, $edit = array()) {
$edit = (array) $edit;
if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
return drupal_get_form('forum_confirm_delete', $edit['tid']);
}
switch ($type) {
case 'forum':
return drupal_get_form('forum_form_forum', $edit);
......@@ -73,12 +70,20 @@ function forum_form_forum($form, &$form_state, $edit = array()) {
$form['vid'] = array('#type' => 'hidden', '#value' => config('forum.settings')->get('vocabulary'));
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#button_type' => 'primary');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#button_type' => 'primary',
'#submit' => array('forum_form_submit')
);
if ($edit['tid']) {
$form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
$form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('forum_forum_delete'),
);
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
}
$form['#submit'][] = 'forum_form_submit';
$form['#theme'] = 'forum_form';
return $form;
......@@ -189,45 +194,30 @@ function forum_form_container($form, &$form_state, $edit = array()) {
'#type' => 'submit',
'#value' => t('Save'),
'#button_type' => 'primary',
'#submit' => array('forum_form_submit'),
);
if ($edit['tid']) {
$form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('forum_forum_delete'),
);
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
}
$form['#submit'][] = 'forum_form_submit';
$form['#theme'] = 'forum_form';
return $form;
}
/**
* Form constructor for confirming deletion of a forum taxonomy term.
* Form submission handler for forum_form_forum() and forum_form_container().
*
* @param $tid
* ID of the term to be deleted.
* Handler for when 'delete' is clicked.
*
* @see forum_confirm_delete_submit()
* @ingroup forms
* @see \Drupal\forum\Form\DeleteForm
*/
function forum_confirm_delete($form, &$form_state, $tid) {
$term = taxonomy_term_load($tid);
$form['tid'] = array('#type' => 'value', '#value' => $tid);
$form['name'] = array('#type' => 'value', '#value' => $term->label());
return confirm_form($form, t('Are you sure you want to delete the forum %label?', array('%label' => $term->label())), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));
}
/**
* Form submission handler for forum_confirm_delete().
*/
function forum_confirm_delete_submit($form, &$form_state) {
taxonomy_term_delete($form_state['values']['tid']);
drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name'])));
watchdog('content', 'forum: deleted %term and all its sub-forums.', array('%term' => $form_state['values']['name']));
$form_state['redirect'] = 'admin/structure/forum';
return;
function forum_forum_delete($form, &$form_state) {
$form_state['redirect'] = 'admin/structure/forum/delete/forum/' . $form_state['values']['tid'];
}
/**
......@@ -255,10 +245,16 @@ function forum_overview($form, &$form_state) {
if (in_array($form[$key]['#term']['tid'], $config->get('containers'))) {
$form[$key]['operations']['#links']['edit']['title'] = t('edit container');
$form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term['tid'];
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form[$key]['operations']['#links']['edit']['query']['destination']);
}
else {
$form[$key]['operations']['#links']['edit']['title'] = t('edit forum');
$form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form[$key]['operations']['#links']['edit']['query']['destination']);
}
}
}
......
......@@ -213,6 +213,18 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) {
}
}
/**
* Implements hook_menu_local_tasks_alter().
*
* Remove the 'Add Forum' and 'Add container' local tasks on the delete form.
*/
function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'admin/structure/forum' && !empty($router_item['map'][3]) &&
$router_item['map'][3] == 'delete') {
$data = array();
}
}
/**
* Implements hook_entity_bundle_info_alter().
*/
......
forum_delete:
pattern: 'admin/structure/forum/delete/forum/{taxonomy_term}'
defaults:
_form: 'Drupal\forum\Form\DeleteForm'
requirements:
_permission: 'administer forums'
forum_settings:
pattern: '/admin/structure/forum/settings'
defaults:
......
<?php
/**
* @file
* Contains \Drupal\forum\Form\DeleteForm.
*/
namespace Drupal\forum\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\taxonomy\Plugin\Core\Entity\Term;
/**
* Builds the form to delete a forum term.
*/
class DeleteForm extends ConfirmFormBase {
/**
* The taxonomy term being deleted.
*
* @var \Drupal\taxonomy\Plugin\Core\Entity\Term
*/
protected $taxonomyTerm;
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'forum_confirm_delete';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the forum %label?', array('%label' => $this->taxonomyTerm->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/forum';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Term $taxonomy_term = NULL) {
$this->taxonomyTerm = $taxonomy_term;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->taxonomyTerm->delete();
drupal_set_message(t('The forum %label and all sub-forums have been deleted.', array('%label' => $this->taxonomyTerm->label())));
watchdog('forum', 'forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/forum';
}
}
......@@ -425,6 +425,9 @@ function createForum($type, $parent = 0) {
function deleteForum($tid) {
// Delete the forum.
$this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete'));
$this->assertText('Are you sure you want to delete the forum');
$this->assertNoText('Add forum');
$this->assertNoText('Add forum container');
$this->drupalPost(NULL, array(), t('Delete'));
// Assert that the forum no longer exists.
......
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