From 1cd9076721538704dc87a16d23eb35fd136a246f Mon Sep 17 00:00:00 2001 From: Svante Richter Date: Sat, 6 Feb 2016 15:50:35 +0100 Subject: [PATCH] Bugfixes that I missed... --- Extension.php | 27 +-- README.md | 2 +- assets/views/twig/_localeswitcher.twig | 5 +- routing.yml.dist | 184 ------------------ .../{Content.php => LocalizedContent.php} | 1 - ...lizedMenu.php => LocalizedMenuBuilder.php} | 0 6 files changed, 19 insertions(+), 200 deletions(-) delete mode 100644 routing.yml.dist rename src/Content/{Content.php => LocalizedContent.php} (98%) rename src/Menu/{LocalizedMenu.php => LocalizedMenuBuilder.php} (100%) diff --git a/Extension.php b/Extension.php index 80a2c20..e529d60 100755 --- a/Extension.php +++ b/Extension.php @@ -32,6 +32,8 @@ public function initialize() $locales = $this->app['config']->get('general/locales'); + $this->app['htmlsnippets'] = true; + if($locales){ $this->app['config']->getFields()->addField(new Field\LocaleField()); $this->app['twig.loader.filesystem']->addPath(__DIR__.'/assets/views'); @@ -229,17 +231,20 @@ public function translateForm($form = null) */ public function getSlugFromLocale($content, $locale) { - if(is_a($content, "Bolt\Content")){ - $query = "select value from bolt_translation where field = 'slug' and locale = ? and content_type = ? and content_type_id = ? "; - $stmt = $this->app['db']->prepare($query); - $stmt->bindValue(1, $locale); - $stmt->bindValue(2, $content->contenttype['slug']); - $stmt->bindValue(3, $content->id); - $stmt->execute(); - $slug = $stmt->fetch(); - if(!empty($slug)){ - return $slug['value']; - } + if(!isset($content->contenttype['slug'])){ + return false; + } + $query = "select value from bolt_translation where field = 'slug' and locale = ? and content_type = ? and content_type_id = ? "; + $stmt = $this->app['db']->prepare($query); + $stmt->bindValue(1, $locale); + $stmt->bindValue(2, $content->contenttype['slug']); + $stmt->bindValue(3, $content->id); + $stmt->execute(); + $slug = $stmt->fetch(); + if(isset($slug['value'])){ + return $slug['value']; + } + if(isset($content->delocalizedValues['slug'])){ return $content->delocalizedValues['slug']; } return false; diff --git a/README.md b/README.md index 6d94328..c550b3d 100755 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ pages: slug: pages singular_name: Page singular_slug: page - class: Bolt\Extension\Animal\Translate\Content\LocalizedContent + class: \Bolt\Extension\Animal\Translate\Content\LocalizedContent fields: locale: type: locale diff --git a/assets/views/twig/_localeswitcher.twig b/assets/views/twig/_localeswitcher.twig index 25fa2a0..5052cf3 100755 --- a/assets/views/twig/_localeswitcher.twig +++ b/assets/views/twig/_localeswitcher.twig @@ -6,9 +6,8 @@
  • + app.request.get('_route_params')|merge({_locale: locale.slug, slug: newslug ?: record.slug}) + )}}"> {{ locale.label }} {% endfor %} diff --git a/routing.yml.dist b/routing.yml.dist deleted file mode 100644 index 1165c76..0000000 --- a/routing.yml.dist +++ /dev/null @@ -1,184 +0,0 @@ -# This file defines user-definable routes for the frontend of your Bolt website. -# Check below for examples, or read the documentation at -# http://docs.bolt.cm/templates-routes#routing - -# ------------------------------------------------------------------------------ -# Place your own routes here, that have a HIGHER priority than the default routes. - -homepage: - path: '/{_locale}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::homepage' - requirements: - _locale: "^[a-zA-Z_]{2,5}$" - -sitemapxml_with_locale: - path: /{_locale}/sitemap.xml - defaults: - _locale: sv - _controller: 'Bolt\Extension\Bolt\Sitemap\Extension::sitemapXml' - requirements: - _locale: "^[a-zA-Z_]{2,5}$" - -sitemaphtml_with_locale: - path: /{_locale}/sitemap - defaults: - _locale: sv - _controller: 'Bolt\Extension\Bolt\Sitemap\Extension::sitemap' - requirements: - _locale: "^[a-zA-Z_]{2,5}$" - -# ------------------------------------------------------------------------------ -# These are the routes defining the default behaviour of Bolt's frontend. -# Changing these might give unexpected results or even break your website. If -# possible, only add NEW routes above or below these. - -search: - path: '/{_locale}/search' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::search' - requirements: - _locale: "^[a-zA-Z_]{2,5}$" - -preview: - path: '/{_locale}/preview/{contenttypeslug}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::preview' - requirements: - contenttypeslug: 'Bolt\Controllers\Routing::getAnyContentTypeRequirement' - _locale: "^[a-zA-Z_]{2,5}$" - -contentlink: - path: '/{_locale}/{contenttypeslug}/{slug}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::record' - requirements: - contenttypeslug: 'Bolt\Controllers\Routing::getAnyContentTypeRequirement' - _locale: "^[a-zA-Z_]{2,5}$" - -taxonomylink: - path: '/{_locale}/{taxonomytype}/{slug}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::taxonomy' - requirements: - taxonomytype: 'Bolt\Controllers\Routing::getAnyTaxonomyTypeRequirement' - _locale: "^[a-zA-Z_]{2,5}$" - -contentlisting: - path: '/{_locale}/{contenttypeslug}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::listing' - requirements: - contenttypeslug: 'Bolt\Controllers\Routing::getPluralContentTypeRequirement' - _locale: "^[a-zA-Z_]{2,5}$" - -# ------------------------------------------------------------------------------ -# Place your own routes here, that have a LOWER priority than the default routes. - -pagebinding: - path: '/{_locale}/{slug}' - defaults: - _locale: sv - _controller: 'Bolt\Extension\Animal\Translate\Frontend\LocalizedFrontend::record' - contenttypeslug: 'sida' - contenttype: sidor - requirements: - _locale: "^[a-zA-Z_]{2,5}$" - -# ------------------------------------------------------------------------------ -# Routes examples: - -# Example to route old '.html' pages to pages genereated by bolt. - -# oldpages: -# path: '/{slug}.html' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'page' -# requirements: -# slug: '[a-z0-9-_]+' - - -# Example route with a host requirement - -# example: -# path: '/example' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'page' -# slug: 'example' -# host: 'www.mydomain.org' - - -# Example override for a specific contenttype - -# pagebinding: -# path: '/{slug}' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'page' -# contenttype: pages - - - -# Example single record override - -# aboutbinding: -# path: '/about' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'page' -# slug: 'about' -# recordslug: 'page/about' - - - -# Example: Use the following to add a route for contenttypes in your URL scheme. In this example we -# add routing for the 'chapter' taxonomy, so we can link to /meta/lorum-ipsum or /main/foo-bar. -# note that the 'showcase' in the defaults and requirements determine the fallback, for when -# no option is specified in a specifid record. Basically, this makes the route respond to the -# default route /showcase/foo-bar as well. - -# chapterbinding: -# path: '/{chapters}/{slug}' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'showcases' -# chapters: 'showcase' -# requirements: -# chapters: [ 'Bolt\Controllers\Routing::getTaxonomyRequirement', ['chapters', 'showcase'] ] -# contenttype: showcases - -# categorybinding: -# path: '/{categories}/{slug}' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::record' -# contenttypeslug: 'showcases' -# categories': 'none' -# requirements: -# categories: [ 'Bolt\Controllers\Routing::getTaxonomyRequirement', ['categories', 'none'] ] -# contenttype: showcases - - -# Supported internal defaults are: -# _controller the controller class::method to be called -# _before the before to call, if non-existent the 'before()' of the controller will be called -# _after the after to call, if non-existent the 'after()' of the controller will be called -# -# Both _before and _after support a shortcut notation which re-uses the controller class: '::before' - - -# Example: rendering a "static" template from the current theme with no associated record/content. -# Note that you can still load and render content from within the template. - -# templatebinding: -# path: '/static-page/' -# defaults: -# _controller: 'Bolt\Extension\Animal\Translate\LocalizedFrontend::template' -# template: 'static-page' diff --git a/src/Content/Content.php b/src/Content/LocalizedContent.php similarity index 98% rename from src/Content/Content.php rename to src/Content/LocalizedContent.php index 7a7bb76..3f49d5c 100644 --- a/src/Content/Content.php +++ b/src/Content/LocalizedContent.php @@ -2,7 +2,6 @@ namespace Bolt\Extension\Animal\Translate\Content; -use Bolt\Extension\Animal\Translate\Extension as Extension; use Bolt\Library as Lib; class LocalizedContent extends \Bolt\Content diff --git a/src/Menu/LocalizedMenu.php b/src/Menu/LocalizedMenuBuilder.php similarity index 100% rename from src/Menu/LocalizedMenu.php rename to src/Menu/LocalizedMenuBuilder.php