diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php index 0f621ce..76ab043 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php @@ -50,9 +50,8 @@ class Tour extends ConfigEntityBase { * The paths in which this tip can be displayed. * * @var array - * An array of paths. */ - protected $paths; + protected $paths = array(); /** * Holds the collection of tips that are attached to this tour. diff --git a/core/modules/tour_ui/lib/Drupal/tour_ui/Tests/TourUITest.php b/core/modules/tour_ui/lib/Drupal/tour_ui/Tests/TourUITest.php index 129954f..12db93f 100644 --- a/core/modules/tour_ui/lib/Drupal/tour_ui/Tests/TourUITest.php +++ b/core/modules/tour_ui/lib/Drupal/tour_ui/Tests/TourUITest.php @@ -14,6 +14,11 @@ */ class TourUITest extends WebTestBase { + /** + * Modules to enable. + * + * @var array + */ public static $modules = array('tour_ui', 'tour_test'); public static function getInfo() { @@ -34,23 +39,44 @@ public function testEdting() { $elements = $this->xpath('//table/tbody/tr'); $this->assertEqual(count($elements), 3); - // Edit and re-save an existing tour. - $this->clickLink(t('Edit')); - $this->assertTitle(t('Edit tour | @site-name', array('@site-name' => config('system.site')->get('name')))); - $this->drupalPost(NULL, array(), t('Save')); - $this->assertRaw(t('Updated the %tour tour', array('%tour' => 'Tour test english'))); - // Create a new tour. $edit = array( 'label' => $this->randomString(), 'id' => strtolower($this->randomName()), ); $this->drupalPost('admin/config/user-interface/tour/add', $edit, t('Save')); - $this->assertRaw(t('The %tour tour has been created.', array('%tour' => $edit['label']))); + $tours = $this->container->get('plugin.manager.entity')->getStorageController('tour')->load(array($edit['id'])); + $tour = $tours[$edit['id']]; + + $this->assertRaw(t('The %tour tour has been created.', array('%tour' => $tour->label()))); + $elements = $this->xpath('//table/tbody/tr'); + $this->assertEqual(count($elements), 4); + + // Ensure that the entity is the first in the list by altering its weight. + $tour->weight = -10; + $tour->save(); + + // Edit and re-save an existing tour. + $this->clickLink(t('Edit')); + $this->assertTitle(t('Edit tour | @site-name', array('@site-name' => config('system.site')->get('name')))); + $this->drupalPost(NULL, array(), t('Save')); + $this->assertRaw(t('Updated the %tour tour', array('%tour' => $tour->label()))); + // Reset the weight. + $tour->weight = -10; + $tour->save(); // Attempt to create a duplicate tour. $this->drupalPost('admin/config/user-interface/tour/add', $edit, t('Save')); $this->assertRaw(t('The machine-readable name is already in use. It must be unique.')); + + // Delete a tour. + $this->drupalGet('admin/config/user-interface/tour'); + $this->clickLink(t('Delete')); + $this->assertRaw(t('Are you sure you want to delete the %tour tour?', array('%tour' => $tour->label()))); + $this->drupalPost(NULL, NULL, t('Delete')); + $elements = $this->xpath('//table/tbody/tr'); + $this->assertEqual(count($elements), 3); + $this->assertRaw(t('Deleted the %tour tour.', array('%tour' => $tour->label()))); } } diff --git a/core/modules/tour_ui/lib/Drupal/tour_ui/TourDeleteForm.php b/core/modules/tour_ui/lib/Drupal/tour_ui/TourDeleteForm.php new file mode 100644 index 0000000..dd37661 --- /dev/null +++ b/core/modules/tour_ui/lib/Drupal/tour_ui/TourDeleteForm.php @@ -0,0 +1,74 @@ +entity = $tour; + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'tour_ui_confirm_delete'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + public function buildForm(array $form, array &$form_state) { + return confirm_form($form, + t('Are you sure you want to delete the %tour tour?', array('%tour' => $this->entity->label())), + 'admin/structure/tour', + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') + ); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $this->entity->delete(); + $form_state['redirect'] = 'admin/config/user-interface/tour'; + drupal_set_message(t('Deleted the %tour tour.', array('%tour' => $this->entity->label()))); + } + +} diff --git a/core/modules/tour_ui/lib/Drupal/tour_ui/TourFormController.php b/core/modules/tour_ui/lib/Drupal/tour_ui/TourFormController.php index 2901b6b..b0fac84 100644 --- a/core/modules/tour_ui/lib/Drupal/tour_ui/TourFormController.php +++ b/core/modules/tour_ui/lib/Drupal/tour_ui/TourFormController.php @@ -11,7 +11,7 @@ use Drupal\Core\Entity\EntityFormController; /** - * Form controller for the tour set entity edit forms. + * Form controller for the tour entity edit forms. */ class TourFormController extends EntityFormController { @@ -43,11 +43,10 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { '#languages' => LANGUAGE_ALL, '#default_value' => $entity->langcode, ); - $paths = $entity->getPaths(); $form['paths'] = array( '#type' => 'textarea', '#title' => t('Paths'), - '#default_value' => !empty($paths) ? implode("\n", $paths) : '', + '#default_value' => implode("\n", $entity->getPaths()), '#rows' => 5, '#description' => t('Provide a list of paths that this tour will be displayed on.'), ); @@ -63,6 +62,7 @@ public function submit(array $form, array &$form_state) { preg_replace('/(\r\n?|\n)/', '\n', $form_state['values']['paths']); $form_state['values']['paths'] = explode("\n", $form_state['values']['paths']); $form_state['values']['paths'] = array_map('trim', $form_state['values']['paths']); + $form_state['values']['paths'] = array_filter($form_state['values']['paths']); $entity = parent::submit($form, $form_state); $is_new = $entity->isNew(); @@ -79,13 +79,4 @@ public function submit(array $form, array &$form_state) { return $entity; } - /** - * Overrides \Drupal\Core\Entity\EntityFormController::actions(). - */ - protected function actions(array $form, array &$form_state) { - $actions = parent::actions($form, $form_state); - unset($actions['delete']); - return $actions; - } - } diff --git a/core/modules/tour_ui/tour_ui.module b/core/modules/tour_ui/tour_ui.module index 68ada6a..b98fa48 100644 --- a/core/modules/tour_ui/tour_ui.module +++ b/core/modules/tour_ui/tour_ui.module @@ -37,6 +37,11 @@ function tour_ui_menu() { 'page callback' => 'NOT_USED', 'access callback' => TRUE, ); + $items['admin/config/user-interface/tour/manage/%/delete'] = array( + 'title' => 'Delete tour', + 'page callback' => 'NOT_USED', + 'access callback' => TRUE, + ); return $items; } diff --git a/core/modules/tour_ui/tour_ui.routing.yml b/core/modules/tour_ui/tour_ui.routing.yml index edd842e..e1d9bb5 100644 --- a/core/modules/tour_ui/tour_ui.routing.yml +++ b/core/modules/tour_ui/tour_ui.routing.yml @@ -16,3 +16,9 @@ tour_ui_edit: _controller: 'tour_ui.controller:edit' requirements: _access: 'TRUE' +tour_ui_delete: + pattern: '/admin/config/user-interface/tour/manage/{tour}/delete' + defaults: + _controller: '\Drupal\tour_ui\TourDeleteForm::getForm' + requirements: + _access: 'TRUE'