Commit d51b2d6e authored by RenatoG's avatar RenatoG Committed by RenatoG

Issue #2906594 by RenatoG: Resolve all items Drupal Best practices for XML sitemap taxonomy

parent bf78c2ec
...@@ -4,6 +4,4 @@ package = XML sitemap ...@@ -4,6 +4,4 @@ package = XML sitemap
core = 7.x core = 7.x
dependencies[] = xmlsitemap dependencies[] = xmlsitemap
dependencies[] = taxonomy dependencies[] = taxonomy
files[] = xmlsitemap_taxonomy.module
files[] = xmlsitemap_taxonomy.install
files[] = xmlsitemap_taxonomy.test files[] = xmlsitemap_taxonomy.test
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Install and uninstall schema and functions for the xmlsitemap_taxonomy module. * Install and uninstall schema and functions for the xmlsitemap_taxonomy.
*/ */
/** /**
......
<?php <?php
/**
* @file
* Main file for XML sitemap taxonomy.
*/
/** /**
* Implements hook_entity_info_alter(). * Implements hook_entity_info_alter().
*/ */
...@@ -43,7 +48,7 @@ function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) { ...@@ -43,7 +48,7 @@ function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) {
/** /**
* Process taxonomy term sitemap links. * Process taxonomy term sitemap links.
* *
* @param $tids * @param array $tids
* An array of taxonomy term IDs. * An array of taxonomy term IDs.
*/ */
function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids) { function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids) {
...@@ -103,7 +108,7 @@ function xmlsitemap_taxonomy_vocabulary_update(stdClass $vocabulary) { ...@@ -103,7 +108,7 @@ function xmlsitemap_taxonomy_vocabulary_update(stdClass $vocabulary) {
} }
/** /**
* Implements hook_taxonomy_term_insert() { * Implements hook_taxonomy_term_insert().
*/ */
function xmlsitemap_taxonomy_term_insert(stdClass $term) { function xmlsitemap_taxonomy_term_insert(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term); $link = xmlsitemap_taxonomy_create_link($term);
...@@ -111,7 +116,7 @@ function xmlsitemap_taxonomy_term_insert(stdClass $term) { ...@@ -111,7 +116,7 @@ function xmlsitemap_taxonomy_term_insert(stdClass $term) {
} }
/** /**
* Implements hook_taxonomy_term_update() { * Implements hook_taxonomy_term_update().
*/ */
function xmlsitemap_taxonomy_term_update(stdClass $term) { function xmlsitemap_taxonomy_term_update(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term); $link = xmlsitemap_taxonomy_create_link($term);
...@@ -119,7 +124,7 @@ function xmlsitemap_taxonomy_term_update(stdClass $term) { ...@@ -119,7 +124,7 @@ function xmlsitemap_taxonomy_term_update(stdClass $term) {
} }
/** /**
* Implements hook_taxonomy_term_delete() { * Implements hook_taxonomy_term_delete().
*/ */
function xmlsitemap_taxonomy_term_delete(stdClass $term) { function xmlsitemap_taxonomy_term_delete(stdClass $term) {
xmlsitemap_link_delete('taxonomy_term', $term->tid); xmlsitemap_link_delete('taxonomy_term', $term->tid);
...@@ -143,9 +148,10 @@ function xmlsitemap_taxonomy_field_extra_fields() { ...@@ -143,9 +148,10 @@ function xmlsitemap_taxonomy_field_extra_fields() {
/** /**
* Create a sitemap link from a taxonomy term. * Create a sitemap link from a taxonomy term.
* *
* @param $term * @param object $term
* A taxonomy term object. * A taxonomy term object.
* @return *
* @return array
* An array representing a sitemap link. * An array representing a sitemap link.
*/ */
function xmlsitemap_taxonomy_create_link(stdClass &$term) { function xmlsitemap_taxonomy_create_link(stdClass &$term) {
...@@ -182,20 +188,22 @@ function xmlsitemap_taxonomy_create_link(stdClass &$term) { ...@@ -182,20 +188,22 @@ function xmlsitemap_taxonomy_create_link(stdClass &$term) {
/** /**
* Calculate the priority of a taxonomy term based on depth and weight. * Calculate the priority of a taxonomy term based on depth and weight.
*
* Function xmlsitemap_taxonomy_calculate_term_priority(stdClass $term) {
* // Calculate priority.
* // Min weight = -128
* // Max weight = 127
* // Max depth = ?
* }
*/ */
//function xmlsitemap_taxonomy_calculate_term_priority(stdClass $term) {
// // Calculate priority.
// // Min weight = -128
// // Max weight = 127
// // Max depth = ?
//}
/** /**
* Find the tree depth of a taxonomy term. * Find the tree depth of a taxonomy term.
* *
* @param $term * @param object $term
* A taxonomy term object. * A taxonomy term object.
* @return *
* @return array
* The tree depth of the term. * The tree depth of the term.
*/ */
function xmlsitemap_taxonomy_get_term_depth(stdClass $term) { function xmlsitemap_taxonomy_get_term_depth(stdClass $term) {
...@@ -221,12 +229,16 @@ function xmlsitemap_taxonomy_get_term_depth(stdClass $term) { ...@@ -221,12 +229,16 @@ function xmlsitemap_taxonomy_get_term_depth(stdClass $term) {
/** /**
* Find the number of nodes that are associated with a taxonomy term. * Find the number of nodes that are associated with a taxonomy term.
* *
* @param $term * @param obejct $term
* A taxonomy term object. * A taxonomy term object.
* @return *
* @return int
* The number of nodes associated with the term. * The number of nodes associated with the term.
*
* @codingStandardsIgnoreStart
*/ */
function xmlsitemap_taxonomy_get_node_count(stdClass $term) { function xmlsitemap_taxonomy_get_node_count(stdClass $term) {
// @codingStandardsIgnoreEnd
// @todo Use db_rewrite_sql() w/ switch user. // @todo Use db_rewrite_sql() w/ switch user.
return db_query_range("SELECT COUNT(ti.nid) FROM {taxonomy_index} ti LEFT JOIN {node n} USING (nid) WHERE ti.tid = :tid AND n.status = 1", 0, 1, array(':tid' => $term->tid))->fetchField(); return db_query_range("SELECT COUNT(ti.nid) FROM {taxonomy_index} ti LEFT JOIN {node n} USING (nid) WHERE ti.tid = :tid AND n.status = 1", 0, 1, array(':tid' => $term->tid))->fetchField();
} }
...@@ -243,7 +255,13 @@ function xmlsitemap_taxonomy_entity_query_alter($query) { ...@@ -243,7 +255,13 @@ function xmlsitemap_taxonomy_entity_query_alter($query) {
if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) { if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) {
// We can only support the operators that are explicit in values. // We can only support the operators that are explicit in values.
if (in_array($conditions['bundle']['operator'], array(NULL, '=', '!=', 'IN', 'NOT IN'))) { if (in_array($conditions['bundle']['operator'], array(
NULL,
'=',
'!=',
'IN',
'NOT IN',
))) {
$vids = array(); $vids = array();
// Convert vocabulary machine names to vocabulary IDs. // Convert vocabulary machine names to vocabulary IDs.
......
...@@ -5,10 +5,32 @@ ...@@ -5,10 +5,32 @@
* Unit tests for the xmlsitemap_taxonomy module. * Unit tests for the xmlsitemap_taxonomy module.
*/ */
/**
* Functional Test.
*/
class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper { class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user; protected $normal_user;
/**
* Terms.
*
* @var array
*/
protected $terms = array(); protected $terms = array();
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'XML sitemap taxonomy', 'name' => 'XML sitemap taxonomy',
...@@ -17,7 +39,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper { ...@@ -17,7 +39,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
); );
} }
function setUp($modules = array()) { /**
* SetUp.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_taxonomy'; $modules[] = 'xmlsitemap_taxonomy';
$modules[] = 'taxonomy'; $modules[] = 'taxonomy';
parent::setUp($modules); parent::setUp($modules);
...@@ -26,7 +51,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper { ...@@ -26,7 +51,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
$this->normal_user = $this->drupalCreateUser(array('access content')); $this->normal_user = $this->drupalCreateUser(array('access content'));
} }
function testTaxonomySettings() { /**
* TaxonomySettings.
*/
public function testTaxonomySettings() {
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->admin_user);
$edit = array( $edit = array(
...@@ -46,4 +74,5 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper { ...@@ -46,4 +74,5 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
); );
$this->drupalPost("admin/structure/taxonomy/{$vocabulary->machine_name}/add", $edit, 'Save'); $this->drupalPost("admin/structure/taxonomy/{$vocabulary->machine_name}/add", $edit, 'Save');
} }
} }
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