$displayData - is the black box of the layouts

243 views
Skip to first unread message

Fedir

unread,
Feb 23, 2014, 5:05:24 AM2/23/14
to joomla-...@googlegroups.com
for anyone who do new or edit existing layout  I would suggest add description for $displayData parameter,

at least:
/**
 * @package     Joomla.Site
 * @subpackage  Layout
 * 
 * @param JTable $displayData
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

at most:

/**
 * @package     Joomla.Site
 * @subpackage  Layout
 * 
 * @param array $displayData:
 * 		$displayData['title'] - some title
 * 		$displayData['params'] - some JRegistry params
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

hope reason is clear

Michael Babker

unread,
Feb 23, 2014, 2:45:34 PM2/23/14
to joomla-...@googlegroups.com
As part of the file header, that would break our code style rules.  However, there is no issue with using a second doc block (basically the same as a class header for the files containing classes) to document that stuff if you or anyone wanted to take the time to do so.


--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send an email to joomla-...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/groups/opt_out.

Gary Mort

unread,
Feb 23, 2014, 5:44:28 PM2/23/14
to joomla-...@googlegroups.com


On Sunday, February 23, 2014 5:05:24 AM UTC-5, Fedir wrote:
for anyone who do new or edit existing layout  I would suggest add description for $displayData parameter,

Personally, I like the way Drupal handles all template issues:

  1. /**
  2. * @file
  3. * Default theme implementation for comments.
  4. *
  5. * Available variables:
  6. * - $author: Comment author. Can be link or plain text.
  7. * - $content: An array of comment items. Use render($content) to print them all, or
  8. * print a subset such as render($content['field_example']). Use
  9. * hide($content['field_example']) to temporarily suppress the printing of a
  10. * given element.
  11. * - $created: Formatted date and time for when the comment was created.
  12. * Preprocess functions can reformat it by calling format_date() with the
  13. * desired parameters on the $comment->created variable.
  14. * - $changed: Formatted date and time for when the comment was last changed.
 ....


It's much cleaner code wise to use variables and not arrays or objects.  The nice thing is that it is easy to do so with arrays, just use extract:

// Set up local data
extract($displayData);


Since the layout/template is being executed from within an object method, all the variables will be scoped to that method - not globally - and thus removed when the method ends.


As an added plus, if you stick to very basic PHP functions in templates/layouts than you can use the same templates in PHP and Javascript.

Roberto Segura

unread,
Feb 23, 2014, 8:59:08 PM2/23/14
to joomla-...@googlegroups.com
Good point Fedir. I agree it's important. Michael's suggestion is perfect I think.

I'll add those blocks in all my edited files from now in advance.

Thanks!

Roberto Segura

unread,
Feb 23, 2014, 9:06:20 PM2/23/14
to joomla-...@googlegroups.com
Awesome suggestion. That will be perfect for most layouts. The problem now is that in some parts we are passing directly an object in $displayData (mostly views I think). That's not a good practice IMO because it makes harder to add future information to the layout without breaking BC. I prefer to add 'view' => $this than directly pass $this.

Thanks for your suggestion.

Fedir

unread,
Feb 25, 2014, 5:40:43 AM2/25/14
to joomla-...@googlegroups.com
as a second doc block also good,
can please someone add this to the coding standard? 
my english not very good for write a clear explanation :)  

Понеділок, 24 лютого 2014 р. 04:06:20 UTC+2 користувач Roberto Segura написав:
Reply all
Reply to author
Forward
0 new messages