Issue #2086479 by tim.plunkett: Convert content_translation_delete_confirm() to the new form interface.

8.0.x
webchick 2013-12-03 21:15:01 -08:00
parent 39e76b0661
commit cc982b7794
4 changed files with 95 additions and 72 deletions

View File

@ -243,45 +243,3 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua
$entity->addTranslation($target->id, $source_translation->getPropertyValues()); $entity->addTranslation($target->id, $source_translation->getPropertyValues());
} }
} }
/**
* Form constructor for the translation deletion confirmation.
*
* @deprecated Use \Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation()
*/
function content_translation_delete_confirm(array $form, array $form_state, EntityInterface $entity, Language $language) {
$controller = content_translation_controller($entity->entityType());
$uri = $entity->uri('drupal:content-translation-overview');
return confirm_form(
$form,
t('Are you sure you want to delete the @language translation of %label?', array('@language' => $language->name, '%label' => $entity->label())),
$uri['path'],
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Form submission handler for content_translation_delete_confirm().
*/
function content_translation_delete_confirm_submit(array $form, array &$form_state) {
list($entity, $language) = $form_state['build_info']['args'];
$controller = content_translation_controller($entity->entityType());
// Remove the translated values.
$entity->removeTranslation($language->id);
$entity->save();
// Remove any existing path alias for the removed translation.
// @todo This should be taken care of by the Path module.
if (\Drupal::moduleHandler()->moduleExists('path')) {
$uri = $entity->uri();
$conditions = array('source' => $uri['path'], 'langcode' => $language->id);
\Drupal::service('path.crud')->delete($conditions);
}
$uri = $entity->uri('drupal:content-translation-overview');
$form_state['redirect'] = $uri['path'];
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @file
* Contains \Drupal\content_translation\Form\ContentTranslationDeleteForm.
*/
namespace Drupal\content_translation\Form;
use Drupal\Core\Form\ConfirmFormBase;
/**
* Temporary form controller for content_translation module.
*/
class ContentTranslationDeleteForm extends ConfirmFormBase {
/**
* The entity whose translation is being deleted.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* The language of the translation being deleted.
*
* @var \Drupal\Core\Language\Language
*/
protected $language;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'content_translation_delete_confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $_entity_type = NULL, $language = NULL) {
$this->entity = $this->getRequest()->attributes->get($_entity_type);
$uri = $this->entity->uri('drupal:content-translation-overview');
$this->language = language_load($language);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->name, '%label' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelRoute() {
$entity_info = $this->entity->entityInfo();
return array(
'route_name' => $entity_info['links']['drupal:content-translation-overview'],
'route_parameters' => array(
$this->entity->entityType() => $this->entity->id(),
),
);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
// Remove the translated values.
$this->entity->removeTranslation($this->language->id);
$this->entity->save();
// Remove any existing path alias for the removed translation.
// @todo This should be taken care of by the Path module.
if (\Drupal::moduleHandler()->moduleExists('path')) {
$uri = $this->entity->uri();
$conditions = array('source' => $uri['path'], 'langcode' => $this->language->id);
\Drupal::service('path.crud')->delete($conditions);
}
$form_state['redirect_route'] = $this->getCancelRoute();
}
}

View File

@ -1,29 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\content_translation\Form\ContentTranslationForm.
*/
namespace Drupal\content_translation\Form;
use Drupal\Core\Language\Language;
use Symfony\Component\HttpFoundation\Request;
/**
* Temporary form controller for content_translation module.
*/
class ContentTranslationForm {
/**
* Wraps content_translation_delete_confirm().
*
* @todo Remove content_translation_delete_confirm().
*/
public function deleteTranslation(Request $request, $language) {
$entity = $request->attributes->get($request->attributes->get('_entity_type'));
module_load_include('pages.inc', 'content_translation');
$language = language_load($language);
return drupal_get_form('content_translation_delete_confirm', $entity, $language);
}
}

View File

@ -140,7 +140,7 @@ class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
$route = new Route( $route = new Route(
$path . '/delete/{language}', $path . '/delete/{language}',
array( array(
'_content' => '\Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation', '_form' => '\Drupal\content_translation\Form\ContentTranslationDeleteForm',
'language' => NULL, 'language' => NULL,
'_title' => 'Delete', '_title' => 'Delete',
'_entity_type' => $entity_type, '_entity_type' => $entity_type,