Commit 82f5d076 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Adding some error catching for erroreous plugins.

parent 77f29dc2
......@@ -41,7 +41,7 @@ function simplesitemap_schema() {
*/
function simplesitemap_install() {
$base_url = $GLOBALS['base_url'];
drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>content type</a> and <a href='@taxonomy_vocabulary_url' target='_blank'>taxonomy vocabulary</a> pages.<br/>Custom links can be added on <a href='@config_url' target='_blank'>this configuration page</a>.)", array('@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@taxonomy_vocabulary_url' => "$base_url/admin/structure/taxonomy", '@config_url' => "$base_url/admin/config/search/simplesitemap/custom")));
drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>content type</a>, <a href='@taxonomy_vocabulary_url' target='_blank'>taxonomy vocabulary</a>, <a href='@menu_url' target='_blank'>menu</a> and <a href='@user_url' target='_blank'>user</a> pages.)<br/>Custom links can be added on <a href='@config_url' target='_blank'>this configuration page</a>.", array('@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@taxonomy_vocabulary_url' => "$base_url/admin/structure/taxonomy", '@menu_url' => "$base_url/admin/structure/menu", '@user_url' => "$base_url/admin/config/people/accounts", '@config_url' => "$base_url/admin/config/search/simplesitemap/custom")));
}
/**
......
......@@ -11,16 +11,32 @@ use Drupal\Component\Plugin\PluginBase;
abstract class LinkGeneratorBase extends PluginBase implements LinkGeneratorInterface {
private $entity_paths = array();
private $current_entity_type;
const PLUGIN_ERROR_MESSAGE = "The simplesitemap @plugin plugin has been omitted, as it does not return the required numeric array of path data sets. Each data sets must contain the required path element and optionally other elements, like lastmod.";
/**
* {@inheritdoc}
*/
public function get_entity_paths($entity_type, $bundles) {
$this->current_entity_type = $entity_type;
$i = 0;
foreach($bundles as $bundle => $bundle_settings) {
if (!$bundle_settings['index'])
continue;
foreach ($this->get_entity_bundle_paths($bundle) as $id => $path) {
$paths = $this->get_entity_bundle_paths($bundle);
if (!is_array($paths)) { // Some error catching.
$this->register_error(self::PLUGIN_ERROR_MESSAGE);
return $this->entity_paths;
}
foreach($paths as $id => $path) {
// Some error catching.
if (!isset($path['path']) || !is_string($path['path'])) { // Error catching; careful, path can be empty.
$this->register_error(self::PLUGIN_ERROR_MESSAGE);
return $this->entity_paths;
}
$this->entity_paths[$i]['path'] = $path['path'];
$this->entity_paths[$i]['priority'] = !empty($path['priority']) ? $path['priority'] : $bundle_settings['priority'];
$this->entity_paths[$i]['lastmod'] = !empty($path['lastmod']) ? date_iso8601($path['lastmod']) : NULL;
......@@ -30,14 +46,25 @@ abstract class LinkGeneratorBase extends PluginBase implements LinkGeneratorInte
return $this->entity_paths;
}
private function register_error($message) {
$message = str_replace('@plugin', $this->current_entity_type, t($message));
\Drupal::logger('simplesitemap')->notice($message);
drupal_set_message($message, 'error');
}
/**
* Returns an array of all urls to this bundle.
* Returns an array of all urls and their data of a bundle.
*
* @param string $bundle
* Machine name of the bundle, eg. 'page'.
*
* @return array $paths
* A numeric array of Drupal internal paths like node/1/edit or user/1
* A numeric array of Drupal internal path data sets containing the path and
* lastmod info:
* array(
* path => 'drupal/internal/path/to/content', // required
* lastmod => '1234567890' // content changed unix date, optional
* )
*
* @abstract
*/
......
......@@ -28,12 +28,12 @@ class Menu extends LinkGeneratorBase {
$routes = db_query("SELECT mlid, route_name, route_parameters FROM {menu_tree} WHERE menu_name = :menu_name and enabled = 1", array(':menu_name' => $bundle))
->fetchAllAssoc('mlid');
//todo: Use Url::getRouteParameters()?
$paths = array();
foreach ($routes as $id => $entity) {
if (empty($entity->route_name))
continue;
//todo: Use Url::getRouteParameters()?
$options = !empty($route_parameters = unserialize($entity->route_parameters))
? array(key($route_parameters) => $route_parameters[key($route_parameters)]) : array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment