Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override display of custom fields in category list view #23227

Closed
denvarel opened this issue Dec 4, 2018 · 2 comments
Closed

Override display of custom fields in category list view #23227

denvarel opened this issue Dec 4, 2018 · 2 comments

Comments

@denvarel
Copy link

denvarel commented Dec 4, 2018

Steps to reproduce the issue

Joomla category created - "Sample Category"
Custom fields group created for category - "Sample Group"
Custom fields type text created and assigned to "Sample Group" and to all categories - "Sample Custom Text Field"
Populated the Default value for the "Sample Custom Text Field" - "The default value of the sample custom text field"
Set the "Sample custom field" to be displayed AfterDisplay (It does not matter where. Is displayed just to check is correct. Using overrides it suppose to be hidden.
Edit the Sample Category by adding "The sample category custom text field" in the "Sample Custom Text Field"

Created overrides
/httpdocs/templates/protostar/html/com_content/category/blog.php
/httpdocs/templates/protostar/html/com_content/category/default.php
add

<?php
	$category   = JRequest::getInt('id');
	echo 'cat id is: '. $category;
	$currentCatFields = FieldsHelper::getFields('com_content.categories', $category, true);
	echo '<pre>',print_r($currentCatFields,1),'</pre>';
?>

add

<?php 
	foreach ($this->item->jcfields as $field) : 
	php echo $field->label . ':' . $field->value; 
	endforeach 
?>

Expected result

The $currentCatFields->value is suppose to be "The sample category custom text field".
The jcfields suppose to be rendered.
see the result at:
http://unicserv.joomla.com/joomla/category-blog.html
http://unicserv.joomla.com/joomla/category-list.html

Actual result

$currentCatFields->value is not existing at all. Strangely, some of the array is filled up, excepting the current values.

The rendering attempt have no results at all. See warning.
Warning: Invalid argument supplied for foreach() in /mnt/data/vhosts/casite-986486.cloudaccess.net/httpdocs/templates/protostar/html/com_content/category/blog.php on line 75

System information (as much as possible)

Joomla 3.9.1
PHP 7.0.32 (but it does not work on another versions as well.

Additional comments

How is suppose to access category's custom fields? The above trials where just a few from 2 days attempts of getting this work. There is no reference on internet excepting on how to get Article's custom fields on category list display. I need to access category's custom fields.

@JamesNGarrett
Copy link
Contributor

The $category passed as the second param of getFields should not be the category id, but instead the category object itself. eg. in the blog.php override

    $currentCatFields = FieldsHelper::getFields('com_content.categories', $this->category, true);
    echo '<pre>',print_r($currentCatFields,1),'</pre>';

This kind of question and answer can be found on the Joomla Stack Exchange, eg.
https://joomla.stackexchange.com/questions/23534/getting-categorys-custom-fields-in-a-blog-view

@joomla-cms-bot
Copy link

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants