diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php index c6e1393768866..74d0b80fa2621 100644 --- a/administrator/components/com_contact/models/contact.php +++ b/administrator/components/com_contact/models/contact.php @@ -526,35 +526,6 @@ public function featured($pks, $value = 0) return true; } - /** - * Method to change the title & alias. - * - * @param integer $category_id The id of the parent. - * @param string $alias The alias. - * @param string $name The title. - * - * @return array Contains the modified title and alias. - * - * @since 3.1 - */ - protected function generateNewTitle($category_id, $alias, $name) - { - // Alter the title & alias - $table = $this->getTable(); - - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) - { - if ($name == $table->name) - { - $name = StringHelper::increment($name); - } - - $alias = StringHelper::increment($alias, 'dash'); - } - - return array($name, $alias); - } - /** * Is the user allowed to create an on the fly category? * diff --git a/administrator/components/com_contact/tables/contact.php b/administrator/components/com_contact/tables/contact.php index af11346448e3a..911a871e49379 100644 --- a/administrator/components/com_contact/tables/contact.php +++ b/administrator/components/com_contact/tables/contact.php @@ -38,6 +38,8 @@ public function __construct(&$db) { parent::__construct('#__contact_details', 'id', $db); + $this->setColumnAlias('title', 'name'); + JTableObserverTags::createObserver($this, array('typeAlias' => 'com_contact.contact')); JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_contact.contact')); } diff --git a/administrator/components/com_newsfeeds/models/newsfeed.php b/administrator/components/com_newsfeeds/models/newsfeed.php index d977387387e4c..9b4fba9d927fa 100644 --- a/administrator/components/com_newsfeeds/models/newsfeed.php +++ b/administrator/components/com_newsfeeds/models/newsfeed.php @@ -450,35 +450,6 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') parent::preprocessForm($form, $data, $group); } - /** - * Method to change the title & alias. - * - * @param integer $category_id The id of the parent. - * @param string $alias The alias. - * @param string $name The title. - * - * @return array Contains the modified title and alias. - * - * @since 3.1 - */ - protected function generateNewTitle($category_id, $alias, $name) - { - // Alter the title & alias - $table = $this->getTable(); - - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) - { - if ($name == $table->name) - { - $name = StringHelper::increment($name); - } - - $alias = StringHelper::increment($alias, 'dash'); - } - - return array($name, $alias); - } - /** * Is the user allowed to create an on the fly category? * diff --git a/administrator/components/com_newsfeeds/tables/newsfeed.php b/administrator/components/com_newsfeeds/tables/newsfeed.php index af9e65206d20f..130f452cd3b4f 100644 --- a/administrator/components/com_newsfeeds/tables/newsfeed.php +++ b/administrator/components/com_newsfeeds/tables/newsfeed.php @@ -35,6 +35,8 @@ public function __construct(&$db) { parent::__construct('#__newsfeeds', 'id', $db); + $this->setColumnAlias('title', 'name'); + JTableObserverTags::createObserver($this, array('typeAlias' => 'com_newsfeeds.newsfeed')); JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_newsfeeds.newsfeed')); } diff --git a/libraries/src/MVC/Model/AdminModel.php b/libraries/src/MVC/Model/AdminModel.php index 935156c4d9e41..88972aec460e7 100644 --- a/libraries/src/MVC/Model/AdminModel.php +++ b/libraries/src/MVC/Model/AdminModel.php @@ -913,11 +913,18 @@ public function delete(&$pks) protected function generateNewTitle($category_id, $alias, $title) { // Alter the title & alias - $table = $this->getTable(); + $table = $this->getTable(); + $aliasField = $table->getColumnAlias('alias'); + $catidField = $table->getColumnAlias('catid'); + $titleField = $table->getColumnAlias('title'); - while ($table->load(array('alias' => $alias, 'catid' => $category_id))) + while ($table->load(array($aliasField => $alias, $catidField => $category_id))) { - $title = StringHelper::increment($title); + if ($title === $table->$titleField) + { + $title = StringHelper::increment($title); + } + $alias = StringHelper::increment($alias, 'dash'); } @@ -1531,9 +1538,11 @@ protected function checkCategoryId($categoryId) public function generateTitle($categoryId, $table) { // Alter the title & alias - $data = $this->generateNewTitle($categoryId, $table->alias, $table->title); - $table->title = $data['0']; - $table->alias = $data['1']; + $titleField = $table->getColumnAlias('title'); + $aliasField = $table->getColumnAlias('alias'); + $data = $this->generateNewTitle($categoryId, $table->$aliasField, $table->$titleField); + $table->$titleField = $data['0']; + $table->$aliasField = $data['1']; } /**