Skip to content

Commit f7841da

Browse files
committed
implement sitemap and error handling of seo-bundle
1 parent 2d1a19d commit f7841da

File tree

15 files changed

+161
-93
lines changed

15 files changed

+161
-93
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends '::base.html.twig' %}
2+
3+
{% block content %}
4+
<h1>Oops! An Error Occurred</h1>
5+
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
6+
7+
<p>
8+
Something is broken. Please let us know what you were doing when this error occurred.
9+
We will fix it as soon as possible. Sorry for any inconvenience caused.
10+
</p>
11+
12+
<h3>Suggested pages</h3>
13+
14+
{% for group, list in best_matches if list is not empty %}
15+
<h4>{{ group|capitalize }}</h4>
16+
<ul>
17+
{% for match in list %}
18+
<li><a href="{{ path(match.id) }}">{{ match.content.title }}</a></li>
19+
{% endfor %}
20+
</ul>
21+
{% else %}
22+
<h4>No suggestions found</h4>
23+
{% endfor %}
24+
{% endblock %}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends '::base.html.twig' %}
2+
3+
{% block content %}
4+
<h1>Sitemap</h1>
5+
<ul class="cmf-sitemap">
6+
{% for url in urls %}
7+
<li{% if url.depth is not null %} class="indent-{{ url.depth }}"{% endif %}>
8+
<a href="{{ url.location }}" title="{{ url.label }}">{{ url.label }}</a>
9+
</li>
10+
{% endfor %}
11+
</ul>
12+
{% endblock %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
{% for url in urls %}
4+
<url>
5+
<loc>{{ url.location }}</loc>
6+
{% if url.lastModification %}
7+
<lastmod>{{ url.lastModification }}</lastmod>
8+
{% endif %}
9+
<changefreq>{{ url.changeFrequency }}</changefreq>
10+
{% if url.alternateLocales is defined and url.alternateLocales|length > 0 %}
11+
{% for locale in url.alternateLocales %}
12+
<xhtml:link rel="alternate" hreflang="{{ locale.hrefLocale }}" href="{{ locale.href }}"/>
13+
{% endfor %}
14+
{% endif %}
15+
</url>
16+
{% endfor %}
17+
</urlset>

app/config/config.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ framework:
2222
twig:
2323
debug: '%kernel.debug%'
2424
strict_variables: '%kernel.debug%'
25-
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
25+
exception_controller: cmf_seo.error.suggestion_provider.controller:listAction
2626

2727
# Assetic Configuration
2828
assetic:
@@ -113,6 +113,23 @@ cmf_seo:
113113
title: 'CMF Sandbox - %%content_title%%'
114114
description: 'The Content Management Framework. %%content_description%%'
115115
alternate_locale: ~
116+
error:
117+
enable_parent_provider: true
118+
enable_sibling_provider: true
119+
templates:
120+
html: ":error:index.html.twig"
121+
exclusion_rules:
122+
- { path: 'excluded' }
123+
sitemap:
124+
defaults:
125+
default_change_frequency: never
126+
templates:
127+
xml: ':sitemap:index.xml.twig'
128+
html: ':sitemap:index.html.twig'
129+
configurations:
130+
sitemap: ~
131+
frequent:
132+
default_change_frequency: always
116133

117134
cmf_menu:
118135
voters:

app/config/routing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ block_cache:
5252
cmf_resource:
5353
resource: '@CmfResourceRestBundle/Resources/config/routing.yml'
5454
prefix: /admin
55+
56+
sitemaps:
57+
prefix: /sitemaps
58+
resource: "@CmfSeoBundle/Resources/config/routing/sitemap.xml"

app/config/services.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ services:
33
class: AppBundle\Controller\ContentController
44
parent: cmf_content.controller
55

6-
app.exception_listener:
7-
class: AppBundle\EventListener\SandboxExceptionListener
8-
calls:
9-
- [setContainer, ['@service_container']]
10-
tags:
11-
- { name: kernel.event_subscriber }
12-
136
app.twig.menu_extension:
147
class: AppBundle\Twig\MenuExtension
158
arguments: ['@knp_menu.helper', '@knp_menu.matcher']

src/AppBundle/DataFixtures/PHPCR/LoadMenuData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function load(ObjectManager $manager)
8585
$this->createMenuNode($manager, $seo, 'simple-seo-example', array('en' => 'Seo-Simple-Content'), $manager->find(null, "$content_path/simple-seo-example"));
8686
$this->createMenuNode($manager, $seo, 'demo-seo-extractor', array('en' => 'Seo-Extractor'), $manager->find(null, "$content_path/demo-seo-extractor"));
8787
$this->createMenuNode($manager, $seo, 'simple-seo-property', array('en' => 'Seo-Extra-Properties'), $manager->find(null, "$content_path/simple-seo-property"));
88+
$this->createMenuNode($manager, $seo, 'seo-sitemap', 'Sitemap', null, '/sitemaps/sitemap.html');
8889

8990
$this->createMenuNode($manager, $main, 'routing-auto-item', array('en' => 'Auto routing example', 'de' => 'Auto routing beispiel', 'fr' => 'Auto routing exemple'), $manager->find(null, "$content_path/news/RoutingAutoBundle generates routes!"));
9091

src/AppBundle/DataFixtures/PHPCR/LoadNewsData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function load(ObjectManager $manager)
5151
See the routing auto <a href="https://github.com/symfony-cmf/cmf-sandbox/blob/master/src/AppBundle/Resources/config/cmf_routing_auto.yml">configuration file</a> to see how this works.
5252
EOT
5353
);
54+
$news->setIsVisibleForSitemap(true);
5455

5556
$manager->persist($news);
5657
$manager->flush();

src/AppBundle/DataFixtures/PHPCR/LoadStaticPageData.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPCR\Util\NodeHelper;
1919
use AppBundle\Document\DemoSeoContent;
2020
use Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr\SeoMetadata;
21+
use Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface;
2122
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
2223
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2324
use Symfony\Component\Yaml\Parser;
@@ -95,6 +96,10 @@ public function load(ObjectManager $manager)
9596
$this->loadBlock($manager, $page, $name, $block);
9697
}
9798
}
99+
100+
if ($page instanceof SitemapAwareInterface) {
101+
$page->setIsVisibleForSitemap(true);
102+
}
98103
}
99104

100105
//add a loading for a simple seo aware page
@@ -114,6 +119,7 @@ public function load(ObjectManager $manager)
114119
EOH
115120
);
116121
$seoDemo->setParentDocument($parent);
122+
$seoDemo->setIsVisibleForSitemap(true);
117123

118124
$seoMetadata = new SeoMetadata();
119125
$seoMetadata->setTitle('Simple seo example');
@@ -146,6 +152,7 @@ public function load(ObjectManager $manager)
146152
$seoMetadata->addExtraName('robots', 'index, follow');
147153
$seoMetadata->addExtraProperty('og:title', 'extra title');
148154
$seoDemo->setSeoMetadata($seoMetadata);
155+
$seoDemo->setIsVisibleForSitemap(true);
149156
$manager->persist($seoDemo);
150157

151158
$manager->bindTranslation($seoDemo, 'en');

src/AppBundle/Document/DemoClassContent.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace AppBundle\Document;
1313

1414
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
15+
use Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface;
1516
use Symfony\Component\Validator\Constraints as Assert;
1617
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
1718

@@ -20,7 +21,7 @@
2021
*
2122
* @PHPCRODM\Document(referenceable=true)
2223
*/
23-
class DemoClassContent implements RouteReferrersReadInterface
24+
class DemoClassContent implements RouteReferrersReadInterface, SitemapAwareInterface
2425
{
2526
/**
2627
* to create the document at the specified location. read only for existing documents.
@@ -62,6 +63,13 @@ class DemoClassContent implements RouteReferrersReadInterface
6263
*/
6364
public $routes;
6465

66+
/**
67+
* @var bool
68+
*
69+
* @PHPCRODM\Field(type="boolean", property="visible_for_sitemap")
70+
*/
71+
private $isVisibleForSitemap;
72+
6573
public function getName()
6674
{
6775
return $this->name;
@@ -117,4 +125,25 @@ public function getRoutes()
117125
{
118126
return $this->routes->toArray();
119127
}
128+
129+
/**
130+
* Decision whether a document should be visible
131+
* in sitemap or not.
132+
*
133+
* @param $sitemap
134+
*
135+
* @return bool
136+
*/
137+
public function isVisibleInSitemap($sitemap)
138+
{
139+
return $this->isVisibleForSitemap;
140+
}
141+
142+
/**
143+
* @param boolean $isVisibleForSitemap
144+
*/
145+
public function setIsVisibleForSitemap($isVisibleForSitemap)
146+
{
147+
$this->isVisibleForSitemap = $isVisibleForSitemap;
148+
}
120149
}

0 commit comments

Comments
 (0)