diff --git a/system/ee/ExpressionEngine/Addons/channel/mod.channel.php b/system/ee/ExpressionEngine/Addons/channel/mod.channel.php index ab6f9582f8..3990159caf 100644 --- a/system/ee/ExpressionEngine/Addons/channel/mod.channel.php +++ b/system/ee/ExpressionEngine/Addons/channel/mod.channel.php @@ -444,7 +444,7 @@ public function fetch_categories() foreach ($query->result_array() as $row) { if ($val == $row['entry_id']) { - $this->temp_array[$row['cat_id']] = array($row['cat_id'], $row['parent_id'], $row['cat_name'], $row['cat_image'], $row['cat_description'], $row['group_id'], $row['cat_url_title']); + $this->temp_array[$row['cat_id']] = array($row['cat_id'], $row['parent_id'], $row['cat_name'], $row['cat_image'], $row['cat_description'], $row['group_id'], $row['cat_url_title'], $row['group_id'], $row['group_name'] ?? ''); foreach ($row as $k => $v) { if (strpos($k, 'field') !== false) { @@ -501,7 +501,7 @@ public function fetch_categories() $categories = ee('Model')->get('Category', $cats)->all(); foreach ($categories as $cat) { - $this->temp_array[$cat->cat_id] = array($cat->cat_id, $cat->parent_id, $cat->cat_name, $cat->cat_image, $cat->cat_description, $cat->group_id, $cat->cat_url_title); + $this->temp_array[$cat->cat_id] = array($cat->cat_id, $cat->parent_id, $cat->cat_name, $cat->cat_image, $cat->cat_description, $cat->group_id, $cat->cat_url_title, $cat->group_id, $cat->group_name ?? ''); if ($cat->parent_id > 0 && ! isset($this->temp_array[$cat->parent_id])) { $parents[$cat->parent_id] = ''; } @@ -2927,7 +2927,7 @@ public function categories() $this->cat_full_array = array_unique($this->cat_full_array); - $sql = "SELECT c.cat_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_image, c.cat_description {$field_sqla} + $sql = "SELECT c.cat_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_image, c.cat_description, c.group_id {$field_sqla} FROM exp_categories AS c {$field_sqlb} WHERE c.cat_id IN ("; @@ -2946,7 +2946,7 @@ public function categories() return ee()->TMPL->no_results(); } } else { - $sql = "SELECT c.cat_name, c.cat_url_title, c.cat_image, c.cat_description, c.cat_id, c.parent_id {$field_sqla} + $sql = "SELECT c.cat_name, c.cat_url_title, c.cat_image, c.cat_description, c.cat_id, c.parent_id, c.group_id {$field_sqla} FROM exp_categories AS c {$field_sqlb} WHERE c.group_id IN ('" . $group_ids_str . "') "; @@ -2986,7 +2986,7 @@ public function categories() continue; } - $this->temp_array[$row['cat_id']] = array($row['cat_id'], $row['parent_id'], '1', $row['cat_name'], $row['cat_description'], $row['cat_image'], $row['cat_url_title']); + $this->temp_array[$row['cat_id']] = array($row['cat_id'], $row['parent_id'], '1', $row['cat_name'], $row['cat_description'], $row['cat_image'], $row['cat_url_title'], $row['group_id'], $row['group_name'] ?? ''); foreach ($row as $key => $val) { if (strpos($key, 'field') !== false) { @@ -3031,6 +3031,8 @@ public function categories() 'category_image' => (string) $val[5], 'category_id' => $val[0], 'parent_id' => $val[1], + 'category_group_id' => $val[7], + 'category_group_name' => $val[8], 'has_children' => in_array($val[0], $parent_ids), 'active' => ($active_cat == $val[0] || $active_cat == $val[6]) ); @@ -3053,7 +3055,9 @@ public function categories() LD . 'category_description' . RD, LD . 'category_image' . RD, LD . 'category_id' . RD, - LD . 'parent_id' . RD + LD . 'parent_id' . RD, + LD . 'category_group_id' . RD, + LD . 'category_group_name' . RD ), array( ee()->functions->encode_ee_tags($cat_vars['category_name']), @@ -3061,7 +3065,9 @@ public function categories() ee()->functions->encode_ee_tags($cat_vars['category_description']), $cat_vars['category_image'], $cat_vars['category_id'], - $cat_vars['parent_id'] + $cat_vars['parent_id'], + $cat_vars['category_group_id'], + ee()->functions->encode_ee_tags($cat_vars['category_group_name']) ), $chunk ); @@ -3441,6 +3447,8 @@ public function category_archive() 'category_image' => (string) $row['cat_image'], 'category_id' => $row['cat_id'], 'parent_id' => $row['parent_id'], + 'category_group_id' => $row['group_id'], + 'category_group_name' => $row['group_name'] ?? '', 'has_children' => in_array($row['cat_id'], $parent_ids), 'active' => ($active_cat == $row['cat_id'] || $active_cat == $row['cat_url_title']) ); @@ -3458,7 +3466,9 @@ public function category_archive() LD . 'category_url_title' . RD, LD . 'category_image' . RD, LD . 'category_description' . RD, - LD . 'parent_id' . RD + LD . 'parent_id' . RD, + LD . 'category_group_id' . RD, + LD . 'category_group_name' . RD ), array( $cat_vars['category_id'], @@ -3466,7 +3476,9 @@ public function category_archive() $cat_vars['category_url_title'], $cat_vars['category_image'], ee()->functions->encode_ee_tags($cat_vars['category_description']), - $cat_vars['parent_id'] + $cat_vars['parent_id'], + $cat_vars['category_group_id'], + ee()->functions->encode_ee_tags($cat_vars['category_group_name']) ), $chunk ); @@ -3668,7 +3680,7 @@ public function category_tree($cdata = array()) $this->cat_full_array = array_unique($this->cat_full_array); - $sql = "SELECT c.cat_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_image, c.cat_description {$field_sqla} + $sql = "SELECT c.cat_id, c.parent_id, c.cat_name, c.cat_url_title, c.cat_image, c.cat_description, c.group_id {$field_sqla} FROM exp_categories AS c {$field_sqlb} WHERE c.cat_id IN ("; @@ -3727,7 +3739,7 @@ public function category_tree($cdata = array()) continue; } - $this->cat_array[$row['cat_id']] = array($row['parent_id'], $row['cat_name'], $row['cat_image'], $row['cat_description'], $row['cat_url_title']); + $this->cat_array[$row['cat_id']] = array($row['parent_id'], $row['cat_name'], $row['cat_image'], $row['cat_description'], $row['cat_url_title'], $row['group_id'], $row['group_name'] ?? ''); foreach ($row as $key => $val) { if (strpos($key, 'field') !== false) { @@ -3814,6 +3826,8 @@ public function category_subtree($cdata = array(), $active_cat = null) 'category_image' => (string) $val[2], 'category_id' => $key, 'parent_id' => $val[0], + 'category_group_id' => $val[5], + 'category_group_name' => $val[6], 'has_children' => in_array($key, $parent_ids), 'active' => ($active_cat == $key || $active_cat == $val[4]) ); @@ -3835,7 +3849,9 @@ public function category_subtree($cdata = array(), $active_cat = null) LD . 'category_url_title' . RD, LD . 'category_image' . RD, LD . 'category_description' . RD, - LD . 'parent_id' . RD + LD . 'parent_id' . RD, + LD . 'category_group_id' . RD, + LD . 'category_group_name' . RD ), array( $cat_vars['category_id'], @@ -3843,7 +3859,9 @@ public function category_subtree($cdata = array(), $active_cat = null) $cat_vars['category_url_title'], $cat_vars['category_image'], ee()->functions->encode_ee_tags($cat_vars['category_description']), - $cat_vars['parent_id'] + $cat_vars['parent_id'], + $cat_vars['category_group_id'], + ee()->functions->encode_ee_tags($cat_vars['category_group_name']) ), $chunk ); @@ -4283,11 +4301,11 @@ public function category_heading() list($field_sqla, $field_sqlb) = $this->generateCategoryFieldSQL($gquery->row('group_id')); } else { - $field_sqla = ''; - $field_sqlb = ''; + // no category fields, but we still might need the category group name + list($field_sqla, $field_sqlb) = $this->generateCategoryFieldSQL(); } - $query = ee()->db->query("SELECT c.cat_name, c.parent_id, c.cat_url_title, c.cat_description, c.cat_image {$field_sqla} + $query = ee()->db->query("SELECT c.cat_name, c.parent_id, c.cat_url_title, c.cat_description, c.cat_image, c.group_id {$field_sqla} FROM exp_categories AS c {$field_sqlb} WHERE c.cat_id = '" . ee()->db->escape_str($cat_id) . "'"); @@ -4306,7 +4324,9 @@ public function category_heading() 'category_description' => $query->row('cat_description'), 'category_image' => (string) $query->row('cat_image'), 'category_id' => $cat_id, - 'parent_id' => $query->row('parent_id') + 'parent_id' => $query->row('parent_id'), + 'category_group_id' => $query->row('group_id'), + 'category_group_name' => $query->row('group_name') ?? '' ); // add custom fields for conditionals prep @@ -4325,7 +4345,9 @@ public function category_heading() LD . 'category_url_title' . RD, LD . 'category_image' . RD, LD . 'category_description' . RD, - LD . 'parent_id' . RD + LD . 'parent_id' . RD, + LD . 'category_group_id' . RD, + LD . 'category_group_name' . RD ), array( $cat_vars['category_id'], @@ -4333,7 +4355,9 @@ public function category_heading() $cat_vars['category_url_title'], $cat_vars['category_image'], ee()->functions->encode_ee_tags($cat_vars['category_description']), - $cat_vars['parent_id'] + $cat_vars['parent_id'], + $cat_vars['category_group_id'], + ee()->functions->encode_ee_tags($cat_vars['category_group_name']) ), ee()->TMPL->tagdata ); @@ -5210,6 +5234,13 @@ public function combo_loader() private function generateCategoryFieldSQL($group_ids = '') { if ($this->enable['category_fields'] !== true) { + // make sure we get category group name if it's not already in the query + if (isset(ee()->TMPL->var_single['category_group_name'])) { + $field_sqla = ", cg.group_name "; + $field_sqlb = " LEFT JOIN exp_category_groups AS cg ON cg.group_id = c.group_id "; + return array($field_sqla, $field_sqlb); + } + return array('', ''); } @@ -5232,7 +5263,7 @@ private function generateCategoryFieldSQL($group_ids = '') $this->cacheCategoryFieldModels(); - $field_sqla = ", cg.field_html_formatting, fd.* "; + $field_sqla = ", cg.group_name, cg.field_html_formatting, fd.* "; $field_sqlb = " LEFT JOIN exp_category_field_data AS fd ON fd.cat_id = c.cat_id LEFT JOIN exp_category_groups AS cg ON cg.group_id = c.group_id "; diff --git a/system/ee/legacy/libraries/channel_entries_parser/components/Category.php b/system/ee/legacy/libraries/channel_entries_parser/components/Category.php index b095be4ac3..a222924df2 100644 --- a/system/ee/legacy/libraries/channel_entries_parser/components/Category.php +++ b/system/ee/legacy/libraries/channel_entries_parser/components/Category.php @@ -163,6 +163,8 @@ public function replace($tagdata, EE_Channel_data_parser $obj, $cat_chunk) // $v[4] = cat_description // $v[5] = group_id // $v[6] = cat_url_title + // $v[7] = group_id + // $v[8] = group_name ee()->load->library('file_field'); $cat_image = ee()->file_field->parse_field($v[3]); @@ -179,6 +181,8 @@ public function replace($tagdata, EE_Channel_data_parser $obj, $cat_chunk) 'category_group' => (isset($v[5])) ? $v[5] : '', 'category_image' => (isset($v[3])) ? (string) $v[3] : '', 'category_id' => $v[0], + 'category_group_id' => $v[7], + 'category_group_name' => $v[8], 'parent_id' => $v[1], 'active' => ($active_cat == $v[0] || $active_cat == $v[6]) ); diff --git a/tests/cypress/cypress/integration/channel/categories.ee6.js b/tests/cypress/cypress/integration/channel/categories.ee6.js index 8e4aac7574..8ebcc37531 100644 --- a/tests/cypress/cypress/integration/channel/categories.ee6.js +++ b/tests/cypress/cypress/integration/channel/categories.ee6.js @@ -544,6 +544,9 @@ context('Categories', () => { cy.get('#category-one .category_description').invoke('text').then((text) => { expect(text).equal('one description') }) + cy.get('#category-one .category_group_name').invoke('text').then((text) => { + expect(text).equal('News Categories') + }) cy.get('#category-one .custom_textfield').invoke('text').then((text) => { expect(text).equal('one textfield') }) @@ -577,6 +580,9 @@ context('Categories', () => { cy.get('#category-two .category_description').invoke('text').then((text) => { expect(text).equal('two description') }) + cy.get('#category-two .category_group_name').invoke('text').then((text) => { + expect(text).equal('News Categories') + }) cy.get('#category-two .custom_textfield').invoke('text').then((text) => { expect(text).equal('two textfield') }) diff --git a/tests/cypress/support/templates/default_site/cats.group/archive-nested.html b/tests/cypress/support/templates/default_site/cats.group/archive-nested.html index 031c6af53c..d7f5e8ed7a 100644 --- a/tests/cypress/support/templates/default_site/cats.group/archive-nested.html +++ b/tests/cypress/support/templates/default_site/cats.group/archive-nested.html @@ -5,6 +5,7 @@