Author: Jonathan.Wage
Date: 2010-01-14 20:43:37 +0100 (Thu, 14 Jan 2010)
New Revision: 26648
Modified:
plugins/sfSympalPlugin/trunk/config/app.yml
plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
plugins/sfSympalPlugin/trunk/lib/user/sfSympalUser.class.php
Log:
[1.4][sfSympalPlugin][1.0] Adding functionality to allow changing the theme for
the current session with a request parameter
Modified: plugins/sfSympalPlugin/trunk/config/app.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-14 19:16:39 UTC (rev
26647)
+++ plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-14 19:43:37 UTC (rev
26648)
@@ -1,5 +1,11 @@
all:
sympal_config:
+ # Configure whether or not to allow the theme to be changed with a
+ # parameter in the url named sf_sympal_theme. Example:
?sf_sympal_theme=wordpress_default
+ # The value will also be remembered in the users session
+ allow_changing_theme_by_url: true
+ theme_request_parameter_name: sf_sympal_theme
+
# Configure the modules which are Sympal admin modules. This allows us to
# automatically load the admin theme for these modules.
admin_modules:
Modified: plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
2010-01-14 19:16:39 UTC (rev 26647)
+++ plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
2010-01-14 19:43:37 UTC (rev 26648)
@@ -6,6 +6,7 @@
$_dispatcher,
$_projectConfiguration,
$_sympalContext,
+ $_symfonyContext,
$_bootstrap,
$_plugins = array(),
$_modules = array(),
@@ -90,7 +91,8 @@
$this->_cache = new sfSympalCache($this);
- $this->_sympalContext =
sfSympalContext::createInstance($event->getSubject(), $this);
+ $this->_symfonyContext = $event->getSubject();
+ $this->_sympalContext =
sfSympalContext::createInstance($this->_symfonyContext, $this);
$this->_enableModules();
@@ -240,33 +242,51 @@
return sfSympalConfig::get($model, 'content_templates', array());
}
- public function getThemeForRequest(sfWebRequest $request)
+ public function getThemeForRequest()
{
+ $request = $this->_symfonyContext->getRequest();
+
+ if (sfSympalConfig::get('allow_changing_theme_by_url'))
+ {
+ $user = $this->_symfonyContext->getUser();
+
+ if ($theme =
$request->getParameter(sfSympalConfig::get('theme_request_parameter_name',
null, 'sf_sympal_theme')))
+ {
+ $user->setCurrentTheme($theme);
+ return $theme;
+ }
+
+ if ($theme = $user->getCurrentTheme())
+ {
+ return $theme;
+ }
+ }
+
$module = $request->getParameter('module');
$adminModules = sfSympalConfig::get('admin_modules');
if (in_array($module, $adminModules))
{
return sfSympalConfig::get('admin_theme', null, 'admin');
}
- $theme = sfSympalConfig::get($module, 'theme');
- if (!$theme)
+
+ if ($theme = sfSympalConfig::get($module, 'theme'))
{
- $theme =
sfSympalConfig::get(sfContext::getInstance()->getRouting()->getCurrentRouteName(),
'theme');
+ return $theme;
}
- if (!$theme)
+
+ if ($theme = $theme =
sfSympalConfig::get(sfContext::getInstance()->getRouting()->getCurrentRouteName(),
'theme'))
{
- $theme = sfSympalConfig::get('default_theme');
+ return $theme;
}
- return $theme;
+
+ return sfSympalConfig::get('default_theme');
}
public function initializeTheme()
{
- $request = sfContext::getInstance()->getRequest();
-
- if (!$request->isXmlHttpRequest())
+ if (!$this->_symfonyContext->getRequest()->isXmlHttpRequest())
{
- $this->_sympalContext->loadTheme($this->getThemeForRequest($request));
+ $this->_sympalContext->loadTheme($this->getThemeForRequest());
}
}
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-14 19:16:39 UTC (rev 26647)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-14 19:43:37 UTC (rev 26648)
@@ -47,7 +47,11 @@
$this->_loadMetaData($this->_response);
- $this->_sympalContext->loadTheme($content->getThemeToRenderWith());
+ if (!$this->_user->getCurrentTheme() ||
!sfSympalConfig::get('allow_changing_theme_by_url'))
+ {
+ $this->_sympalContext->loadTheme($content->getThemeToRenderWith());
+ }
+
$this->_sympalContext->setCurrentContent($content);
// Handle custom action
Modified: plugins/sfSympalPlugin/trunk/lib/user/sfSympalUser.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/user/sfSympalUser.class.php
2010-01-14 19:16:39 UTC (rev 26647)
+++ plugins/sfSympalPlugin/trunk/lib/user/sfSympalUser.class.php
2010-01-14 19:43:37 UTC (rev 26648)
@@ -39,4 +39,14 @@
}
return $access;
}
+
+ public function setCurrentTheme($theme)
+ {
+ $this->setAttribute('sympal_current_theme', $theme);
+ }
+
+ public function getCurrentTheme()
+ {
+ return $this->getAttribute('sympal_current_theme');
+ }
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.