Commit 8db7dc16 authored by janoka's avatar janoka Committed by tatarbj

Issue #2991956 by janoka, tatarbj: Clean up the code base

parent 6311fa6c
......@@ -85,4 +85,3 @@ MAINTAINERS
Supporting organization:
* Hook 42 - https://www.drupal.org/hook-42
<?php
/**
* @file
* API documentation file for Easy Breadcrumb.
*/
/**
* Allows modules to alter the path to calculate the breadcrumb.
*
* @param string $path
* The current drupal path returned by drupal_get_path_alias().
*/
function hook_easy_breadcrumb_path_alter(&$path) {
// Replace the path to calculate the breadcrumb for
// the printmail page in the print module.
$args = arg();
if ($args[0] == 'printmail') {
$args[] = array_shift($args);
$path = implode('/', $args);
}
}
/**
* Allows modules to alter the breadcrumb displayed in the block.
*
* @param array $breadcrumb
* The breadcrumb array returned to render in the block.
*/
function hook_easy_breadcrumb_breadcrumb_alter(&$breadcrumb) {
// Remove the last breadcrumb element for node pages.
$args = arg();
if ($args[0] == 'node') {
array_pop($breadcrumb);
}
}
<?php
/**
* @file
* API documentation file for Easy Breadcrumb.
*/
/**
* Allows modules to alter the path to calculate the breadcrumb.
*
* @param string $path
* The current drupal path returned by drupal_get_path_alias().
*/
function hook_easy_breadcrumb_path_alter(&$path) {
// Replace the path to calculate the breadcrumb for.
// The printmail page in the print module.
$args = arg();
if ($args[0] == 'printmail') {
$args[] = array_shift($args);
$path = implode('/', $args);
}
}
/**
* Allows modules to alter the breadcrumb displayed in the block.
*
* @param array $breadcrumb
* The breadcrumb array returned to render in the block.
*/
function hook_easy_breadcrumb_breadcrumb_alter(array &$breadcrumb) {
// Remove the last breadcrumb element for node pages.
$args = arg();
if ($args[0] == 'node') {
array_pop($breadcrumb);
}
}
<?php
/**
* @file
* Install hooks.
......@@ -29,4 +30,4 @@ function easy_breadcrumb_uninstall() {
*/
function easy_breadcrumb_update_7001() {
drupal_theme_rebuild();
}
\ No newline at end of file
}
<?php
/**
* @file
* The Easy Breadcrumb module provides a block to be embedded in any page,
* typically at some place near the page's header.
* The Easy Breadcrumb module provides a block to be embedded in any page.
*
* Typically at some place near the page's header.
* Easy Breadcrumb uses the URL (path alias) and the current page's title
* (when available) to obtain the breadcrumb's segments and its respective
* links. The resulting block will be something like:
......@@ -183,7 +185,8 @@ function _easy_breadcrumb_build_items() {
$breadcrumb[] = _easy_breadcrumb_build_item($front_text, $segments_classes, '<front>');
}
// There won't be more segments if visiting the front page, the don't waste resources.
// There won't be more segments if visiting the front page,
// the don't waste resources.
if (!drupal_is_front_page()) {
// Gets the flag saying the capitalizator mode.
$capitalizator_mode = variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_MODE, 'ucwords');
......@@ -222,7 +225,6 @@ function _easy_breadcrumb_build_items() {
// Allow the alias to be altered.
drupal_alter('easy_breadcrumb_path', $alias);
// Get the segments of the current path.
$alias_arr = explode('/', $alias);
......@@ -241,7 +243,8 @@ function _easy_breadcrumb_build_items() {
// first iteration this array will be array('blog'), the second
// (and last in that case) the array will be array('blog','article').
$segment_url_arr[] = $alias_arr[$idx_0];
// String with the potential-path of the segment being processed (e.g. 'blog/article').
// String with the potential-path of the segment being processed
// (e.g. 'blog/article').
$segment_url = implode('/', $segment_url_arr);
// Jump to the next segment if this url is configured to be excluded.
......@@ -269,7 +272,7 @@ function _easy_breadcrumb_build_items() {
// Get the segment's raw text from the URL.
$segment_text = $alias_arr[$idx_0];
// Normalized segment's text (e.g. 'Blog');
// Normalized segment's text (e.g. 'Blog');.
$segment_title = _easy_breadcrumb_obtain_segment_title($segment_normal_path, $segment_valid_path, $segment_text);
_easy_breadcrumb_check_replaced_title($segment_title);
......@@ -292,7 +295,8 @@ function _easy_breadcrumb_build_items() {
// Adds the page's title to the breadcrumb.
if ($include_page_title_segment) {
// Marks the page's-title-segment with an identifier class (useful for CSS).
// Marks the page's-title-segment with an identifier class
// (useful for CSS).
$segments_classes[1] = 'easy-breadcrumb_segment-title';
// The title is the last segment in the URL.
$segment_text = $alias_arr[$segments_quantity - 1];
......@@ -320,9 +324,7 @@ function _easy_breadcrumb_build_items() {
*/
function _easy_breadcrumb_obtain_home_title() {
$front_text = variable_get(EasyBreadcrumbConstants::DB_VAR_HOME_SEGMENT_TITLE);
if (isset($front_text) && $front_text !== '') {
$front_text = t($front_text);
} else {
if (!isset($front_text) || $front_text === '') {
$front_text = t('Home');
}
return $front_text;
......@@ -354,18 +356,18 @@ function _easy_breadcrumb_obtain_page_title($page_text) {
* Build a breadcrumb item.
*
* @param string $item_title
* title of the item.
* Title of the item.
* @param array $item_classes
* classes.
* Classes.
* @param string $item_url
* url of the item.
* @param boolean $as_link
* denotes if the item is an url or plain text.
* Url of the item.
* @param bool $as_link
* Denotes if the item is an url or plain text.
*
* @return array
* the generated breadcrumb item.
*/
function _easy_breadcrumb_build_item($item_title, $item_classes, $item_url, $as_link = TRUE) {
function _easy_breadcrumb_build_item($item_title, array $item_classes, $item_url, $as_link = TRUE) {
if (variable_get(EasyBreadcrumbConstants::DB_VAR_TRUNCATOR_MODE, FALSE)) {
$item_title = truncate_utf8(
$item_title,
......@@ -390,10 +392,10 @@ function _easy_breadcrumb_build_item($item_title, $item_classes, $item_url, $as_
* Check if the given segment is a valid path.
*
* @param string $segment_path
* path of the segment.
* Path of the segment.
*
* @return bool
* true if the segment is a valid path, false otherwise.
* True if the segment is a valid path, false otherwise.
*/
function _easy_breadcrumb_validate_segment_path($segment_path) {
$is_valid_path = drupal_valid_path($segment_path);
......@@ -436,7 +438,7 @@ function _easy_breadcrumb_check_replaced_title(&$segment_title) {
* @param string $url
* URL to be verified.
*
* @return boolean
* @return bool
* TRUE if should be excluded, FALSE otherwise.
*/
function _easy_breadcrumb_check_excluded_path($url) {
......@@ -471,7 +473,8 @@ function _easy_breadcrumb_check_excluded_path($url) {
* segment title.
*/
function _easy_breadcrumb_obtain_segment_title($normal_path, $valid_path, $segment_text) {
// If path is valid then try to obtain the title from the menu router (if available).
// If path is valid then try to obtain the title from the menu router
// (if available).
if ($valid_path) {
$router_item = menu_get_item($normal_path);
// If not using segment text as title then use the menu router title.
......@@ -487,10 +490,13 @@ function _easy_breadcrumb_obtain_segment_title($normal_path, $valid_path, $segme
}
/**
* Normalizes a text. E.g., transforms "about-us" to "About Us" or "About us", according to parameters.
* Normalizes a text.
*
* E.g., transforms "about-us" to "About Us" or "About us",
* according to parameters.
*
* @param string $raw_text
* text to be normalized.
* Text to be normalized.
*
* @return string
* normalized title.
......@@ -516,7 +522,7 @@ function _easy_breadcrumb_normalize_text($raw_text) {
$words_arr[$idx_1] = drupal_ucfirst($words_arr[$idx_1]);
}
}
$normalized_text = join(' ', $words_arr);
$normalized_text = implode(' ', $words_arr);
}
elseif ($capitalizator_mode === 'ucall') {
// Transforms the text 'once a time' to 'ONCE A TIME'.
......@@ -526,7 +532,8 @@ function _easy_breadcrumb_normalize_text($raw_text) {
// Transforms the text 'once a time' to 'once a TIME'.
// List of words to be forced by the capitalizator.
$forced_words = variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS, '');
// If case sensitivity is false make all the forced words uncapitalized by default.
// If case sensitivity is false make all the forced words
// uncapitalized by default.
if (!variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY, FALSE)) {
$forced_words = array_map('drupal_strtolower', $forced_words);
}
......@@ -536,7 +543,8 @@ function _easy_breadcrumb_normalize_text($raw_text) {
$words_arr[0] = drupal_ucfirst($words_arr[0]);
}
for ($idx_1 = 0, $words_quantity = count($words_arr); $idx_1 < $words_quantity; ++$idx_1) {
// If case sensitivity is false make the compared word uncapitalized in order to allow the comparison well.
// If case sensitivity is false make the compared word uncapitalized
// in order to allow the comparison well.
if (!variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY, FALSE)) {
$selected_word = drupal_strtolower($words_arr[$idx_1]);
}
......@@ -548,7 +556,7 @@ function _easy_breadcrumb_normalize_text($raw_text) {
$words_arr[$idx_1] = drupal_strtoupper($selected_word);
}
}
$normalized_text = join(' ', $words_arr);
$normalized_text = implode(' ', $words_arr);
}
else {
// Transforms the text 'once a time' to 'Once a time' (ucfirst).
......@@ -561,14 +569,15 @@ function _easy_breadcrumb_normalize_text($raw_text) {
/**
* Apply title replacements.
*
* @param String $title
* @param string $title
* Page title.
*
* @param Array $replacements.
* @param array $replacements
* Replacement rules map.
*/
function _easy_breadcrumb_apply_title_replacement(&$title, $replacements) {
if (!is_string($title)) return;
function _easy_breadcrumb_apply_title_replacement(&$title, array $replacements) {
if (!is_string($title)) {
return;
}
if (array_key_exists($title, $replacements)) {
$title = $replacements[$title];
......
......@@ -61,8 +61,9 @@ class EasyBreadcrumbConstants {
const DB_VAR_TITLE_SEGMENT_AS_LINK = 'easy_breadcrumb-title_segment_as_link';
/**
* Use the page's title when it is available instead of always trying to
* deduce it from the URL.
* Use the page's title when it is available.
*
* Instead of always trying to deduce it from the URL.
*/
const DB_VAR_TITLE_FROM_PAGE_WHEN_AVAILABLE = 'easy_breadcrumb-title_from_page_when_available';
......
<?php
/**
* @file
* Module's admin forms.
......@@ -33,13 +34,13 @@ function _easy_breadcrumb_general_settings_form() {
'#size' => 10,
'#title' => t('Breadcrumb separator:'),
'#default_value' => variable_get(EasyBreadcrumbConstants::DB_VAR_SEGMENTS_SEPARATOR, '»'),
);
);
$fieldset_general[EasyBreadcrumbConstants::DB_VAR_SEPERATOR_ENDING] = array(
'#type' => 'checkbox',
'#title' => t('Show breadcrumb separator after the final breadcrumb.'),
'#default_value' => variable_get(EasyBreadcrumbConstants::DB_VAR_SEPERATOR_ENDING, FALSE),
);
);
// Fieldset for grouping text settings.
$fieldset_general['first'] = array(
......@@ -106,7 +107,7 @@ function _easy_breadcrumb_general_settings_form() {
// before displaying them.
$excluded_paths_arr = variable_get(EasyBreadcrumbConstants::DB_VAR_EXCLUDED_PATHS,
EasyBreadcrumbConstants::defaultExcludedPaths());
$excluded_paths = @join("\r\n", $excluded_paths_arr);
$excluded_paths = @implode("\r\n", $excluded_paths_arr);
$fieldset_general['paths'][EasyBreadcrumbConstants::DB_VAR_EXCLUDED_PATHS] = array(
'#type' => 'textarea',
'#title' => t('Breadcrumb paths to be excluded:'),
......@@ -217,7 +218,7 @@ function _easy_breadcrumb_general_settings_form() {
// (word1 word2 wordN) before displaying them.
$capitalizator_ignored_words_arr = variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_IGNORED_WORDS,
EasyBreadcrumbConstants::defaultIgnoredWords());
$capitalizator_ignored_words = @join(' ', $capitalizator_ignored_words_arr);
$capitalizator_ignored_words = @implode(' ', $capitalizator_ignored_words_arr);
$form['caps'][EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_IGNORED_WORDS] = array(
'#type' => 'textfield',
......@@ -231,14 +232,14 @@ function _easy_breadcrumb_general_settings_form() {
),
'invisible' => array(
':input[name="' . EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_MODE . '"]' => array('!value' => 'ucwords'),
)
)
),
),
);
// Formats the forced-words array as space separated list of words
// (word1 word2 wordN) before displaying them.
$capitalizator_forced_words_arr = variable_get(EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS, '');
$capitalizator_forced_words = @join(' ', $capitalizator_forced_words_arr);
$capitalizator_forced_words = @implode(' ', $capitalizator_forced_words_arr);
$form['caps'][EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS] = array(
'#type' => 'textfield',
......@@ -253,8 +254,8 @@ function _easy_breadcrumb_general_settings_form() {
),
'invisible' => array(
':input[name="' . EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_MODE . '"]' => array('!value' => 'ucforce'),
)
)
),
),
);
$form['caps'][EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY] = array(
......@@ -267,7 +268,7 @@ function _easy_breadcrumb_general_settings_form() {
),
'invisible' => array(
':input[name="' . EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_MODE . '"]' => array('!value' => 'ucforce'),
)
),
),
'#description' => t('When unchecked, drupal will match both Drupal and drupaL.'),
);
......@@ -282,8 +283,8 @@ function _easy_breadcrumb_general_settings_form() {
),
'invisible' => array(
':input[name="' . EasyBreadcrumbConstants::DB_VAR_CAPITALIZATOR_MODE . '"]' => array('!value' => 'ucforce'),
)
)
),
),
);
// Adds buttons for processing the form.
......@@ -306,12 +307,12 @@ function _easy_breadcrumb_general_settings_form() {
/**
* Process the submitting of the administration form of this module.
*
* @param Assoc $form
* renderable form.
* @param Assoc $form_state
* form state.
* @param array $form
* Renderable form.
* @param array $form_state
* Form state.
*/
function _easy_breadcrumb_admin_submit($form, &$form_state) {
function _easy_breadcrumb_admin_submit(array $form, array &$form_state) {
// Pre-processes the list of ignored words for storing them as an array.
// Replaces line-endings by spaces and splits words by spaces.
......
<?php if ($segments_quantity > 0): ?>
<div itemscope class="easy-breadcrumb" itemtype="<?php print $list_type; ?>">
<?php foreach ($breadcrumb as $i => $item): ?>
<?php print $item; ?>
<?php if ($i < $segments_quantity - $separator_ending): ?>
<span class="easy-breadcrumb_segment-separator"><?php print $separator; ?></span>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
\ No newline at end of file
<?php
/**
* @file
* Easy breadcrumb template file.
*/
if ($segments_quantity > 0): ?>
<div itemscope class="easy-breadcrumb" itemtype="<?php print $list_type; ?>">
<?php foreach ($breadcrumb as $i => $item): ?>
<?php print $item; ?>
<?php if ($i < $segments_quantity - $separator_ending): ?>
<span class="easy-breadcrumb_segment-separator"><?php print $separator; ?></span>
<?php
endif; ?>
<?php
endforeach; ?>
</div>
<?php
endif; ?>
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