Skip to content
This repository

[IMP] Plugin get overridable layout #1408

Merged
merged 6 commits into from over 1 year ago

6 participants

Roberto Segura Michael Babker Piotr AmyStephen Louis Landry Sam Moffatt
Roberto Segura
Owner

Helper function to ease the plugin layout overrides based on the JModuleHelper getLayoutPath function.

For example the plugin Content - Pagenavigation will search his overrides in:

template/YOUR_TEMPLATE/html/plg_content_pagenavigation

And the default layout would be:

plugins/content/pagenavigation/tmpl

Michael Babker
Owner

I'd be supportive of something like this. I currently use some internal code in a plugin that allows users to override the output, and I know of a few other plugins doing similar workarounds.

Piotr

I guess plugins were meant to not output any HTML, so there was not override functionality built in (this has been discussed few times already), but there are exceptional cases.
Most JoomlaWorks plugins have this functionality built in since Joomla 1.5 and it's great.

I'm for this to be in core.

@phproberto: Consider replacing DIRECTORY_SEPARATOR with /. I think this is the convention in the platform as PHP deals perfectly fine with both types of slashes in paths and this makes code more readable.

Roberto Segura
Owner

You are true @piotr-cz

I forgot to remove the DIRECTORY_SEPARATOR's. I'll modify it ASAP.

Thanks for the advice and support !

Roberto Segura
Owner

I've fixed the DIRECTORY_SEPARATOR with slashes.

Thank you all for your feedback.

Roberto Segura
Owner

Any news about this? Will be great to see it approved and submitted to joomla-cms to be in Joomla! 3.0

AmyStephen

This makes good sense, to me. It's just one more step towards getting rendering more flexible. Probably dozens of ways to do this but this looks suitable to me, inline with how other output rendering is handled. Even if a new approach is used with the new Integrated Content system, having this for 3.N series would be good.

Thanks Roberto!

Piotr

Just hope it's not too late to include it in the 3.0 trunk. Probably most forces are on Bootstrap integration.

Sam Moffatt pasamio commented on the diff August 17, 2012
libraries/joomla/plugin/helper.php
@@ -27,6 +27,49 @@
27 27
 	protected static $plugins = null;
28 28
 
29 29
 	/**
  30
+	 * Get the path to a layout from a Plugin
  31
+	 *
  32
+	 * @param   string  $type    Plugin type
  33
+	 * @param   string  $name    Plugin name
  34
+	 * @param   string  $layout  Layout name
  35
+	 *
  36
+	 * @return  string  Layout path
2
Sam Moffatt
pasamio added a note August 17, 2012

Can you add a @since 12.2

Roberto Segura Owner

Done ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Louis Landry

Why wouldn't you just use JViewHtml to support this functionality? You have layouts and overrides just built into that. It's very lightweight as well. It then keeps the clear separation of presentation responsibilities independent of the event handling system.

Roberto Segura
Owner

@LouisLandry This is based on the same method already existent for module layouts. I've been watching the JViewHtml class and you are right, it's better prepared for layouts but that will probably be harder than create a simple method.

AmyStephen

Core code needs to be inline with architectural directions.

Roberto Segura
Owner

Any news about this? :(

Sam Moffatt pasamio merged commit 49f4a29 into from September 22, 2012
Sam Moffatt pasamio closed this September 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 45 additions and 0 deletions. Show diff stats Hide diff stats

  1. 45  libraries/joomla/plugin/helper.php
45  libraries/joomla/plugin/helper.php
@@ -27,6 +27,51 @@
27 27
 	protected static $plugins = null;
28 28
 
29 29
 	/**
  30
+	 * Get the path to a layout from a Plugin
  31
+	 *
  32
+	 * @param   string  $type    Plugin type
  33
+	 * @param   string  $name    Plugin name
  34
+	 * @param   string  $layout  Layout name
  35
+	 *
  36
+	 * @return  string  Layout path
  37
+	 *
  38
+	 * @since   12.2
  39
+	 */
  40
+	public static function getLayoutPath($type, $name, $layout = 'default')
  41
+	{
  42
+		$template = JFactory::getApplication()->getTemplate();
  43
+		$defaultLayout = $layout;
  44
+
  45
+		if (strpos($layout, ':') !== false)
  46
+		{
  47
+			// Get the template and file name from the string
  48
+			$temp = explode(':', $layout);
  49
+			$template = ($temp[0] == '_') ? $template : $temp[0];
  50
+			$layout = $temp[1];
  51
+			$defaultLayout = ($temp[1]) ? $temp[1] : 'default';
  52
+		}
  53
+
  54
+		// Build the template and base path for the layout
  55
+		$tPath = JPATH_THEMES . '/' . $template . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
  56
+		$bPath = JPATH_BASE . '/plugins/' . $type . '/' . $name . '/tmpl/' . $defaultLayout . '.php';
  57
+		$dPath = JPATH_BASE . '/plugins/' . $type . '/' . $name . '/tmpl/' . 'default.php';
  58
+
  59
+		// If the template has a layout override use it
  60
+		if (file_exists($tPath))
  61
+		{
  62
+			return $tPath;
  63
+		}
  64
+		elseif (file_exists($bPath))
  65
+		{
  66
+			return $bPath;
  67
+		}
  68
+		else
  69
+		{
  70
+			return $dPath;
  71
+		}
  72
+	}
  73
+
  74
+	/**
30 75
 	 * Get the plugin data of a specific type if no specific plugin is specified
31 76
 	 * otherwise only the specific plugin data is returned.
32 77
 	 *
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.