Author: Jonathan.Wage
Date: 2010-02-10 21:24:11 +0100 (Wed, 10 Feb 2010)
New Revision: 27849
Added:
plugins/sfSympalPlugin/trunk/lib/route/
plugins/sfSympalPlugin/trunk/lib/route/sfSympalContentRouteObject.class.php
Modified:
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content/config/generator.yml
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/modules/sympal_menu_items/lib/Basesympal_menu_itemsActions.class.php
Log:
[1.4][sfSympalPlugin][1.0] Refactored content routing to standalone class so it
can be used and cached with the menus
Modified:
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -12,7 +12,8 @@
$_routeObject,
$_mainMenuItem,
$_editableSlotsExistOnPage = false,
- $_slotsByName = null;
+ $_slotsByName = null,
+ $_contentRouteObject = null;
/**
* Initializes a new sfSympalContent for the given type
@@ -206,6 +207,18 @@
$result = $this->_table->hasField($name);
if (!$result)
{
+ $className = get_class($this);
+ if (sfSympalConfig::isI18nEnabled($className))
+ {
+ $table = Doctrine_Core::getTable($className.'Translation');
+ if ($table->hasField($name))
+ {
+ $result = true;
+ }
+ }
+ }
+ if (!$result)
+ {
$className = $this->getType()->getName();
$table = Doctrine_Core::getTable($className);
if ($table->hasField($name))
@@ -482,135 +495,43 @@
return $this->getId().'-'.$this->getSlug();
}
- public function getRouteName()
- {
- if ($this->get('custom_path', false) || $this->get('module', false) ||
$this->get('action', false))
- {
- return '@sympal_content_' . $this->getUnderscoredSlug();
- }
- else if ($this['Type']['default_path'])
- {
- return $this['Type']['route_name'];
- }
- else if ($this['slug'])
- {
- return '@sympal_content_view';
- }
- }
-
public function hasCustomPath()
{
return $this->custom_path ? true : false;
}
- public function getRoutePath()
+ public function getContentRouteObject()
{
- // If content has a custom path then lets use it
- if ($this->hasCustomPath())
+ if (!$this->_contentRouteObject)
{
- $path = $this->custom_path;
- if ($path != '/')
- {
- $path .= '.:sf_format';
- }
- return $path;
+ $this->_contentRouteObject = new sfSympalContentRouteObject($this);
}
- // If content has a custom module or action then we need a route for it
- // so generate a path for this content to use in the route
- else if ($this->get('module', false) || $this->get('action', false))
- {
- $values = $this->_buildRouteValues();
- $values['sf_culture'] = ':sf_culture';
- $values['sf_format'] = ':sf_format';
- return $this->getRouteObject()->generate($values);
- }
- // Otherwise fallback and get route path from the content type
- else if ($path = $this->getType()->getRoutePath())
- {
- return $path;
- }
- // Default if nothing else can be found
- else if ($this['slug'])
- {
- return '/content/:slug';
- }
+ return $this->_contentRouteObject;
}
- public function getRouteObject()
+ public function getRoute()
{
- if (!$this->_routeObject)
- {
- // Generate a route object for this content only if it has a custom path
- if ($this->hasCustomPath())
- {
- $this->_routeObject = new sfRoute($this->getRoutePath(), array(
- 'sf_format' => 'html',
- 'sf_culture' => sfConfig::get('default_culture')
- ));
- // Otherwise get it from the content type
- } else {
- $this->_routeObject = $this->getType()->getRouteObject();
- }
- }
- return $this->_routeObject;
+ return $this->getContentRouteObject()->getRoute();
}
- public function getRoute()
+ public function getRoutePath()
{
- if (!$this->_route)
- {
- if (!$this->exists() || !$this['slug'])
- {
- return false;
- }
-
- if (method_exists($this->getContentTypeClassName(), 'getRoute'))
- {
- return $this->getRecord()->getRoute();
- }
-
- $this->_route = $this->_fillRoute($this->getRouteName());
- }
-
- return $this->_route;
+ return $this->getContentRouteObject()->getRoutePath();
}
- public function getEvaluatedRoutePath()
+ public function getRouteName()
{
- $values = $this->_buildRouteValues();
- $values['sf_culture'] = sfContext::getInstance()->getUser()->getCulture();
- return $this->getRouteObject()->generate($values);
+ return $this->getContentRouteObject()->getRouteName();
}
- protected function _fillRoute($route)
+ public function getRouteObject()
{
- $values = $this->_buildRouteValues();
- if (!empty($values))
- {
- return $route.'?'.http_build_query($values);
- } else {
- return $route;
- }
+ return $this->getContentRouteObject()->getRouteObject();
}
- protected function _buildRouteValues()
+ public function getEvaluatedRoutePath()
{
- $variables = $this->getRouteObject()->getVariables();
- $isI18nEnabled = sfSympalConfig::isI18nEnabled();
-
- $values = array();
- foreach (array_keys($variables) as $name)
- {
- if ($isI18nEnabled && $name == 'slug' && $this->hasField('i18n_slug') &&
$i18nSlug = $this->i18n_slug)
- {
- $values[$name] = $i18nSlug;
- } else if ($this->hasField($name)) {
- $values[$name] = $this->$name;
- } else if (method_exists($this, $method =
'get'.sfInflector::camelize($name))) {
- $values[$name] = $this->$method();
- }
- }
- return $values;
+ return $this->getContentRouteObject()->getEvaluatedRoutePath();
}
public function trySettingTitleProperty($value)
Modified:
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContentTable.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -166,7 +166,7 @@
$user = sfContext::getInstance()->getUser();
- if (!$user->hasCredential('ManageContent'))
+ if (!$user->isEditMode())
{
$q = $this->addPublishedQuery($alias, $q);
}
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content/config/generator.yml
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content/config/generator.yml
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_content/config/generator.yml
2010-02-10 20:24:11 UTC (rev 27849)
@@ -16,7 +16,7 @@
fields: ~
form:
display:
- "Content": [TypeForm, custom_path, date_published, slug]
+ "Content": [TypeForm, custom_path, date_published, slug, i18n_slug]
"Settings": [content_type_id, created_by_id, groups_list,
edit_groups_list, publicly_editable]
"Rendering Options": [template, theme, module, action]
"Search Engine Optimization": [page_title, meta_keywords,
meta_description]
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -3,6 +3,7 @@
class sfSympalMenuSite extends sfSympalMenu
{
protected
+ $_contentRouteObject = null,
$_menuItem = null,
$_cacheKey = null;
@@ -131,8 +132,22 @@
return $label;
}
+ public function getRoute()
+ {
+ if ($this->_contentRouteObject)
+ {
+ return $this->_contentRouteObject->getRoute();
+ } else {
+ return parent::getRoute();
+ }
+ }
+
public function setMenuItem($menuItem)
{
+ if ($content = $menuItem->getRelatedContent())
+ {
+ $this->_contentRouteObject = $content->getContentRouteObject();
+ }
$this->_menuItem = $this->_prepareMenuItem($menuItem);
$this->setRoute($this->_menuItem['item_route']);
$this->requiresAuth($this->_menuItem['requires_auth']);
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -255,7 +255,7 @@
foreach ($hierarchy as $menuItem)
{
- $new = $menu->addChild($menuItem->getSlug(), $menuItem->getItemRoute());
+ $new = $menu->addChild($menuItem->getSlug());
$new->setName($menuItem->getName());
$new->setMenuItem($menuItem);
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -122,7 +122,7 @@
$content = $this->getContent();
if ($content instanceof sfSympalContent)
{
- $route = $this->getContent()->getRoute();
+ $route = $content->getRoute();
}
}
return $route;
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/modules/sympal_menu_items/lib/Basesympal_menu_itemsActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/modules/sympal_menu_items/lib/Basesympal_menu_itemsActions.class.php
2010-02-10 20:01:30 UTC (rev 27848)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/modules/sympal_menu_items/lib/Basesympal_menu_itemsActions.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -125,12 +125,6 @@
$this->roots = $table->getTree()->fetchRoots();
}
- public function executeView()
- {
- $this->menuItem = $this->getRoute()->getObject();
- $this->redirect($this->menuItem->getItemRoute());
- }
-
public function executeEdit(sfWebRequest $request)
{
$this->sf_sympal_menu_item = $this->_getMenuItem($request);
Added:
plugins/sfSympalPlugin/trunk/lib/route/sfSympalContentRouteObject.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/route/sfSympalContentRouteObject.class.php
(rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/route/sfSympalContentRouteObject.class.php
2010-02-10 20:24:11 UTC (rev 27849)
@@ -0,0 +1,175 @@
+<?php
+
+class sfSympalContentRouteObject
+{
+ protected
+ $_content,
+ $_routeName,
+ $_routePath,
+ $_routeObject,
+ $_routeValues;
+
+ public function __construct(sfSympalContent $content)
+ {
+ $this->compile($content);
+ }
+
+ public function compile(sfSympalContent $content)
+ {
+ $this->_routeName = $this->_buildRouteName($content);
+ $this->_routePath = $this->_buildRoutePath($content);
+ $this->_routeObject = $this->_buildRouteObject($content);
+ $this->_routeValues = $this->_buildRouteValues($content);
+ }
+
+ public function getRoute()
+ {
+ $values = $this->getCultureRouteValues();
+
+ if (!empty($values))
+ {
+ return $this->_routeName.'?'.http_build_query($values);
+ } else {
+ return $this->_routeName;
+ }
+ }
+
+ public function getRouteName()
+ {
+ return $this->_routeName;
+ }
+
+ public function getRoutePath()
+ {
+ return $this->_routePath;
+ }
+
+ public function getRouteObject()
+ {
+ return $this->_routeObject;
+ }
+
+ public function getRouteValues()
+ {
+ return $this->_routeValues;
+ }
+
+ public function getCultureRouteValues($culture = null)
+ {
+ if ($culture === null)
+ {
+ $culture = $this->getCurrentCulture();
+ }
+ return $culture && isset($this->_routeValues[$culture]) ?
$this->_routeValues[$culture] : current($this->_routeValues);
+ }
+
+ public function getCurrentCulture()
+ {
+ if ($user = sfContext::getInstance()->getUser())
+ {
+ return $user->getCulture();
+ } else {
+ return sfConfig::get('sf_default_culture');
+ }
+ }
+
+ public function getEvaluatedRoutePath()
+ {
+ $values = $this->getCultureRouteValues();
+ $values['sf_culture'] = $this->getCurrentCulture();
+ return $this->getRouteObject()->generate($values);
+ }
+
+ protected function _buildRouteValues(sfSympalContent $content)
+ {
+ $variables = $this->getRouteObject()->getVariables();
+ $isI18nEnabled = sfSympalConfig::isI18nEnabled();
+
+ $languageCodes = $isI18nEnabled ? sfSympalConfig::getLanguageCodes() :
array($this->getCurrentCulture());
+ $values = array();
+ foreach ($languageCodes as $code)
+ {
+ foreach (array_keys($variables) as $name)
+ {
+ if ($isI18nEnabled && $name == 'slug' && $i18nSlug =
$content->Translation[$code]->i18n_slug)
+ {
+ $values[$code][$name] = $i18nSlug;
+ } else if ($content->hasField($name)) {
+ if ($isI18nEnabled && isset($content->Translation[$code]->$name))
+ {
+ $values[$code][$name] = $content->Translation[$code]->$name;
+ } else {
+ $values[$code][$name] = $content->$name;
+ }
+ } else if (method_exists($content, $method =
'get'.sfInflector::camelize($name))) {
+ $values[$code][$name] = $content->$method();
+ }
+ }
+ }
+ return $values;
+ }
+
+ protected function _buildRouteName(sfSympalContent $content)
+ {
+ if ($content->get('custom_path', false) || $content->get('module', false)
|| $content->get('action', false))
+ {
+ return '@sympal_content_' . $content->getUnderscoredSlug();
+ }
+ else if ($content->getType()->getDefaultPath())
+ {
+ return $content->getType()->getRouteName();
+ }
+ else if ($content->getSlug())
+ {
+ return '@sympal_content_view';
+ }
+ }
+
+ protected function _buildRouteObject(sfSympalContent $content)
+ {
+ // Generate a route object for this content only if it has a custom path
+ if ($content->hasCustomPath())
+ {
+ return new sfRoute($this->getRoutePath(), array(
+ 'sf_format' => 'html',
+ 'sf_culture' => sfConfig::get('default_culture')
+ ));
+ // Otherwise get it from the content type
+ } else {
+ return $content->getType()->getRouteObject();
+ }
+ }
+
+ protected function _buildRoutePath(sfSympalContent $content)
+ {
+ // If content has a custom path then lets use it
+ if ($content->hasCustomPath())
+ {
+ $path = $content->custom_path;
+ if ($path != '/')
+ {
+ $path .= '.:sf_format';
+ }
+ return $path;
+ }
+ // If content has a custom module or action then we need a route for it
+ // so generate a path for this content to use in the route
+ else if ($content->get('module', false) || $content->get('action', false))
+ {
+ $values = $this->getCultureRouteValues();
+ $values['sf_culture'] = ':sf_culture';
+ $values['sf_format'] = ':sf_format';
+ return $this->getRouteObject()->generate($values);
+ }
+ // Otherwise fallback and get route path from the content type
+ else if ($path = $content->getType()->getRoutePath())
+ {
+ return $path;
+ }
+ // Default if nothing else can be found
+ else if ($content->getSlug())
+ {
+ return '/content/:slug';
+ }
+ }
+}
\ 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.