joomla-projects / cms-naked

[READ-ONLY] This repo is no longer in active development. Please see https://github.com/joomla/joomla-cms | Repository for the Frontend Working Group
GNU General Public License v2.0
3 stars 12 forks source link

Use JRendererJlayout in plugins #60

Closed wilsonge closed 9 years ago

phproberto commented 10 years ago

One of the things I found useful while working with this is to create a different function to get the layout data. This is better because:

Example for base field:

/**
 * Get the data that is going to be passed to the layout
 *
 * @return  array
 */
protected function getLayoutData()
{
    return array(
        'autofocus' => $this->autofocus,
        'class'     => $this->class,
        'disabled'  => $this->disabled,
        'element'   => $this->element,
        'field'     => $this,
        'id'        => $this->id,
        'multiple'  => $this->multiple,
        'name'      => $this->name,
        'readonly'  => $this->readonly,
        'required'  => $this->required,
        'size'      => $this->size,
        'value'     => $this->value
    );
}

Example override in child field:

/**
 * Get the data that is going to be passed to the layout
 *
 * @return  array
 */
protected function getLayoutData()
{
    $baseData = parent::getLayoutData();

    $htmlType = !empty($this->element['html_type']) ? $this->element['html_type'] : 'text';

    $extraData = array(
        'type'                => $htmlType,
        'attributes'          => $this->element->attributes(),
        'forbiddenAttributes' => $this->forbiddenAttributes
    );

    return array_merge($baseData, $extraData);
}

Another good example is the current view.html.php files where the display method contains everything. If we use the getLayoutData() function most views will only change that function which simplifies everything a lot.

wilsonge commented 10 years ago

I agree. But that would be for form fields. For plugins (for example) that wouldn't be needed as we just have one view. people aren't gonna be overriding the inputs

phproberto commented 10 years ago

Don't you extend JPlugin class in your own plugins?

This would allow you to:

If I'm right most plugins will only have the getLayoutData method. So you can override the renderer in a base plugin class and use the same renderer in all your plugins for example. On 3 Sep 2014 23:16, "George Wilson" notifications@github.com wrote:

I agree. But that would be for form fields. For plugins (for example) that wouldn't be needed as we just have one view. people aren't gonna be overriding the inputs

— Reply to this email directly or view it on GitHub https://github.com/joomla-projects/cms-naked/pull/60#issuecomment-54368684 .

wilsonge commented 10 years ago

OK so your saying that you have a common plugin class

commonPlugin extends JPlugin
{
   abstract public function getLayoutData

  public function getRenderer($path)
  {
      new JLayoutFile($path);
  }
}

and a specific plugin from there with just the getLayoutData function in?

Myrealplugin extends commonPlugin
{
// plugin code here with overrides as necessary.
}
phproberto commented 10 years ago

I'm better explaining things with code :octocat:

https://github.com/wilsonge/cms-naked/pull/1

phproberto commented 10 years ago

New PR with quickicons cleanup https://github.com/wilsonge/cms-naked/pull/2

phproberto commented 10 years ago

After that I think we have to merge this to start using the renderer on the other sections (fields, libraries, modules, etc.).