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
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = taxonomy
files[] = xmlsitemap_taxonomy.module
files[] = xmlsitemap_taxonomy.install
files[] = xmlsitemap_taxonomy.test
......@@ -2,7 +2,7 @@
/**
* @file
* Install and uninstall schema and functions for the xmlsitemap_taxonomy module.
* Install and uninstall schema and functions for the xmlsitemap_taxonomy.
*/
/**
......
<?php
/**
* @file
* Main file for XML sitemap taxonomy.
*/
/**
* Implements hook_entity_info_alter().
*/
......@@ -43,7 +48,7 @@ function xmlsitemap_taxonomy_xmlsitemap_index_links($limit) {
/**
* Process taxonomy term sitemap links.
*
* @param $tids
* @param array $tids
* An array of taxonomy term IDs.
*/
function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids) {
......@@ -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) {
$link = xmlsitemap_taxonomy_create_link($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) {
$link = xmlsitemap_taxonomy_create_link($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) {
xmlsitemap_link_delete('taxonomy_term', $term->tid);
......@@ -143,9 +148,10 @@ function xmlsitemap_taxonomy_field_extra_fields() {
/**
* Create a sitemap link from a taxonomy term.
*
* @param $term
* @param object $term
* A taxonomy term object.
* @return
*
* @return array
* An array representing a sitemap link.
*/
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.
*
* 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.
*
* @param $term
* @param object $term
* A taxonomy term object.
* @return
*
* @return array
* The tree depth of the term.
*/
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.
*
* @param $term
* @param obejct $term
* A taxonomy term object.
* @return
*
* @return int
* The number of nodes associated with the term.
*
* @codingStandardsIgnoreStart
*/
function xmlsitemap_taxonomy_get_node_count(stdClass $term) {
// @codingStandardsIgnoreEnd
// @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();
}
......@@ -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'])) {
// 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();
// Convert vocabulary machine names to vocabulary IDs.
......
......@@ -5,10 +5,32 @@
* Unit tests for the xmlsitemap_taxonomy module.
*/
/**
* Functional Test.
*/
class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
/**
* Normal User.
*
* @var string
*
* @codingStandardsIgnoreStart
*/
protected $normal_user;
/**
* Terms.
*
* @var array
*/
protected $terms = array();
/**
* Get Info.
*
* @codingStandardsIgnoreEnd
*/
public static function getInfo() {
return array(
'name' => 'XML sitemap taxonomy',
......@@ -17,7 +39,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
);
}
function setUp($modules = array()) {
/**
* SetUp.
*/
public function setUp($modules = array()) {
$modules[] = 'xmlsitemap_taxonomy';
$modules[] = 'taxonomy';
parent::setUp($modules);
......@@ -26,7 +51,10 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
$this->normal_user = $this->drupalCreateUser(array('access content'));
}
function testTaxonomySettings() {
/**
* TaxonomySettings.
*/
public function testTaxonomySettings() {
$this->drupalLogin($this->admin_user);
$edit = array(
......@@ -46,4 +74,5 @@ class XMLSitemapTaxonomyFunctionalTest extends XMLSitemapTestHelper {
);
$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