function calendar_granularity_path in Calendar 8
Same name and namespace in other branches
- 7.3 calendar.module \calendar_granularity_path()
Find the path for the calendar display that has a specific granularity.
Parameters
\Drupal\views\ViewExecutable $view: The current view.
string $granularity: The granularity to find.
Return value
string The path for the specific granularity, or an empty string if none was found.
Deprecated
use \Drupal\calendar\CalendarHelper::getURLForGranularity instead.
File
- ./
calendar.module, line 230
Code
function calendar_granularity_path(ViewExecutable &$view, $granularity) {
// @todo Find out what should happen here.
$paths =& drupal_static(__FUNCTION__, []);
$view_name = $view
->id();
if (!array_key_exists($view_name, $paths) || isset($paths[$view
->id()]) && !array_key_exists($granularity, $paths[$view
->id()])) {
$paths[$view_name][$granularity] = '';
foreach ($view->displayHandlers
->getConfiguration() as $id => $display) {
// Check for !empty() in case the view is not fully formed or has displays that are marked to be deleted.
// @todo handle deleted displays
// if (!empty($display->deleted) || empty($display->display_options['style_plugin']) || (isset($display->display_options['enabled']) && $display->display_options['enabled'] == FALSE)) {
// continue;
// }
if ($display['display_plugin'] != 'feed' && !empty($display['display_options']['path']) && !empty($display['display_options']['arguments'])) {
// Set to the default value, reset below if another value is found.
$type = 'month';
$argument = CalendarHelper::getDateArgumentHandler($view, $id);
if ($argument
->getGranularity() == $granularity) {
$part_path = $display['display_options']['path'];
$parts = explode('/', $part_path);
if (in_array('%', $parts)) {
$url = Url::fromRoute('<current>');
$current_path = $url
->toString();
$current_parts = explode('/', $current_path);
foreach ($parts as $key => $part) {
if ($part == '%' && !empty($current_parts[$key])) {
$parts[$key] = $current_parts[$key];
}
}
$part_path = implode('/', $parts);
}
$paths[$view
->id()][$granularity] = $part_path;
}
}
}
}
return $paths[$view
->id()][$granularity];
}