|
|
| (6 intermediate revisions by 2 users not shown) |
| Line 7: |
Line 7: |
| * https://github.com/zero-24 | | * https://github.com/zero-24 |
| * https://volunteers.joomla.org/joomlers/tobias-zulauf | | * https://volunteers.joomla.org/joomlers/tobias-zulauf |
|
| |
| -------
| |
|
| |
|
| |
| == How to use custom fields in your overrides ==
| |
|
| |
| === Introdutuin ===
| |
|
| |
| The real power of custom fields is that you can use it in your own overrides. Here is a example how you can do that.
| |
|
| |
| === Getting custom fields in your override ===
| |
|
| |
| Basicly you have all custom fields coresponding to the current item accessible via a new property in your <code>$item</code> variable called <code>jcfields</code>.
| |
| The <code>$item->jcfields</code> property is a array that holds the following data per field, where one field looks like this example:
| |
|
| |
| <source lang="php">
| |
| Array
| |
| (
| |
| [4] => stdClass Object
| |
| (
| |
| [id] => 4
| |
| [title] => article-editor
| |
| [name] => article-editor
| |
| [checked_out] => 0
| |
| [checked_out_time] => 0000-00-00 00:00:00
| |
| [note] =>
| |
| [state] => 1
| |
| [access] => 1
| |
| [created_time] => 2017-04-07 12:08:59
| |
| [created_user_id] => 856
| |
| [ordering] => 0
| |
| [language] => *
| |
| [fieldparams] => Joomla\Registry\Registry Object
| |
| (
| |
| [data:protected] => stdClass Object
| |
| (
| |
| [buttons] =>
| |
| [width] =>
| |
| [height] =>
| |
| [filter] =>
| |
| )
| |
|
| |
| [initialized:protected] => 1
| |
| [separator] => .
| |
| )
| |
|
| |
| [params] => Joomla\Registry\Registry Object
| |
| (
| |
| [data:protected] => stdClass Object
| |
| (
| |
| [hint] =>
| |
| [render_class] =>
| |
| [class] =>
| |
| [showlabel] => 1
| |
| [disabled] => 0
| |
| [readonly] => 0
| |
| [show_on] =>
| |
| [display] => 2
| |
| )
| |
|
| |
| [initialized:protected] => 1
| |
| [separator] => .
| |
| )
| |
|
| |
| [type] => editor
| |
| [default_value] =>
| |
| [context] => com_content.article
| |
| [group_id] => 0
| |
| [label] => article-editor
| |
| [description] =>
| |
| [required] => 0
| |
| [language_title] =>
| |
| [language_image] =>
| |
| [editor] =>
| |
| [access_level] => Public
| |
| [author_name] => Super User
| |
| [group_title] =>
| |
| [group_access] =>
| |
| [group_state] =>
| |
| [value] => Bar
| |
| [rawvalue] => Bar
| |
| )
| |
|
| |
| )
| |
| </source>
| |
|
| |
| === Render the field using the default ===
| |
|
| |
| To render the field you can use <code>FieldsHelper::render()</code> by passing the needed values.
| |
|
| |
| <source lang="php">
| |
| /**
| |
| * Renders the layout file and data on the context and does a fall back to
| |
| * Fields afterwards.
| |
| *
| |
| * @param string $context The context of the content passed to the helper
| |
| * @param string $layoutFile layoutFile
| |
| * @param array $displayData displayData
| |
| *
| |
| * @return NULL|string
| |
| *
| |
| * @since 3.7.0
| |
| */
| |
| public static function render($context, $layoutFile, $displayData)
| |
| </source>
| |
|
| |
| ==== Example code for the override ====
| |
|
| |
| <source lang="PHP">
| |
| // Load the FieldsHelper
| |
| <?php JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); ?>
| |
|
| |
| <?php foreach ($this->item->jcfields as $field) : ?>
| |
| // Render the field using the fields render method
| |
| <?php echo FieldsHelper::render($field->context, 'field.render', array('field' => $field)); ?>
| |
| <?php endforeach ?>
| |
| </source>
| |
Tobias Zulauf - zero24
I'm a specialist for system integration in Germany. I'm involved with Joomla! since 2011.