diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index bee7504..2b91136 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -44,8 +44,6 @@ function aggregator_help($path, $arg) { return '

' . t('Categories allow feed items from different feeds to be grouped together. For example, several sport-related feeds may belong to a category named Sports. Feed items may be grouped automatically (by selecting a category when creating or editing a feed) or manually (via the Categorize page available from feed item listings). Each category provides its own feed page and block.') . '

'; case 'admin/config/services/aggregator/add/opml': return '

' . t('OPML is an XML format used to exchange multiple feeds between aggregators. A single OPML document may contain a collection of many feeds. Drupal can parse such a file and import all feeds at once, saving you the effort of adding them manually. You may either upload a local file from your computer or enter a URL where Drupal can download it.') . '

'; - case 'admin/config/services/aggregator/delete': - return; } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php index 81e2af3..0eab4df 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageController.php @@ -1,4 +1,5 @@ execute(); } + /** + * {@inheritdoc} + */ + public function isUnique($title, $cid = NULL) { + $query = $this->database->select('aggregator_category', 'ac') + ->fields('ac', array('title')) + ->condition('title', $title); + if (!empty($cid)) { + $query->condition('cid', $cid, '<>'); + } + $rows = $query->execute()->fetchColumn(); + return (empty($rows)); + } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php index b47f9c4..3d829ac 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/CategoryStorageControllerInterface.php @@ -1,4 +1,5 @@ request = $request; $category = (object) $this->categoryStorageController->load($cid); $form['title'] = array( '#type' => 'textfield', @@ -92,9 +102,15 @@ public function buildForm(array $form, array &$form_state, $cid = NULL) { '#default_value' => isset($category->description) ? $category->description : '', ); $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save')); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); if (!empty($category->cid)) { - $form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete')); + $form['actions']['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + ); $form['cid'] = array('#type' => 'hidden', '#value' => $category->cid); } @@ -107,14 +123,16 @@ public function buildForm(array $form, array &$form_state, $cid = NULL) { public function validateForm(array &$form, array &$form_state) { if ($form_state['values']['op'] == t('Save')) { // Check for duplicate titles. + $title = $form_state['values']['title']; if (isset($form_state['values']['cid'])) { - $category = $this->database->query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => $form_state['values']['title'], ':cid' => $form_state['values']['cid']))->fetchObject(); + // Exclude the current category ID when checking if it's unique. + $unique = $this->categoryStorageController->isUnique($title, $form_state['values']['cid']); } else { - $category = $this->database->query("SELECT cid FROM {aggregator_category} WHERE title = :title", array(':title' => $form_state['values']['title']))->fetchObject(); + $unique = $this->categoryStorageController->isUnique($title); } - if ($category) { - form_set_error('title', t('A category named %category already exists. Enter a unique title.', array('%category' => $form_state['values']['title']))); + if (!$unique) { + form_set_error('title', t('A category named %category already exists. Enter a unique title.', array('%category' => $title))); } } } @@ -142,7 +160,12 @@ public function submitForm(array &$form, array &$form_state) { $cid = $form_state['values']['cid']; $this->categoryStorageController->update($form_state['values']); drupal_set_message(t('The category %category has been updated.', array('%category' => $title))); - $form_state['redirect'] = arg(0) == 'admin' ? 'admin/config/services/aggregator/' : 'aggregator/categories/' . $cid; + if (preg_match('/^\/admin/', $this->request->getPathInfo())) { + $form_state['redirect'] = 'admin/config/services/aggregator/'; + } + else { + $form_state['redirect'] = 'aggregator/categories/' . $cid; + } $this->updateMenuLink('update', $link_path . $cid, $title); return; } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php index bb46850..474e499 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryDeleteForm.php @@ -1,4 +1,5 @@ category = $category; + $this->request = $request; return parent::buildForm($form, $form_state, $request); } @@ -149,7 +156,12 @@ public function submitForm(array &$form, array &$form_state) { $this->deleteBlocks($cid); watchdog('aggregator', 'Category %category deleted.', array('%category' => $title)); drupal_set_message(t('The category %category has been deleted.', array('%category' => $title))); - $form_state['redirect'] = arg(0) == 'admin' ? 'admin/config/services/aggregator' : 'aggregator'; + if (preg_match('/^\/admin/', $this->request->getPathInfo())) { + $form_state['redirect'] = 'admin/config/services/aggregator/'; + } + else { + $form_state['redirect'] = 'aggregator'; + } $this->updateMenuLink('delete', 'aggregator/categories/' . $cid, $title); }