[views] Knowing the display type of a view
Hi all, I'm implementing a hook of hook_views_pre_render and I need to know if the current display being rendered is a page. Is there any api in views for this? I'm right now using substr($view->current_display, 0, 4) == 'page' but I wonder if there is any way more elegant. Thanks in advance! -- Christian López Espínola Área de Proyectos Emergya Consultoría Tfno: +34 954 51 75 77 Fax: +34 954 51 64 73 www.emergya.es
On Thu, 2010-12-30 at 14:09 +0100, Christian López Espínola wrote:
I'm right now using substr($view->current_display, 0, 4) == 'page' but I wonder if there is any way more elegant.
That's how I use it, too. And it seems quite elegant to me :)
On 12/30/2010 5:09 AM, Christian López Espínola wrote:
Hi all,
I'm implementing a hook of hook_views_pre_render and I need to know if the current display being rendered is a page.
Is there any api in views for this? I'm right now using substr($view->current_display, 0, 4) == 'page' but I wonder if there is any way more elegant.
This is probably more correct. get_class($view->display_handler) == 'views_plugin_display_page' More generically, there's also: $view->display_handler->has_path() -- that gets more than just 'page' displays, it gets 'feed' displays as well. But this could be valuable if using something like calendar's custom page displays which aren't specifically page displays, but act like them nonetheless.
Hi, We tend to use the 'is_a' function, like so: if (is_a($view->display_handler, 'views_plugin_display_page')) { ... } that way if you use a display handler that subclasses the page one, you still get your code executed. http://php.net/manual/en/function.is-a.php Regards Steven Jones ComputerMinds ltd - Perfect Drupal Websites Phone : 024 7666 7277 Mobile : 07702 131 576 Twitter : darthsteven http://www.computerminds.co.uk On 30 Dec 2010, at 15:43, Earl Miles <merlin@logrus.com> wrote:
On 12/30/2010 5:09 AM, Christian López Espínola wrote:
Hi all,
I'm implementing a hook of hook_views_pre_render and I need to know if the current display being rendered is a page.
Is there any api in views for this? I'm right now using substr($view->current_display, 0, 4) == 'page' but I wonder if there is any way more elegant.
This is probably more correct.
get_class($view->display_handler) == 'views_plugin_display_page'
More generically, there's also: $view->display_handler->has_path() -- that gets more than just 'page' displays, it gets 'feed' displays as well. But this could be valuable if using something like calendar's custom page displays which aren't specifically page displays, but act like them nonetheless.
On Fri, 2010-12-31 at 00:04 +0000, Steven Jones wrote:
Hi,
We tend to use the 'is_a' function, like so:
if (is_a($view->display_handler, 'views_plugin_display_page')) { ... }
that way if you use a display handler that subclasses the page one, you still get your code executed.
Then why don't use use instanceof ? if ($view->display_handler instanceof views_plugin_display_page) { } <cite> 5.0.0 This function became deprecated in favour of the instanceof operator. Calling this function will result in an E_STRICT warning. </cite> Pierre.
participants (5)
-
Christian López Espínola -
Earl Miles -
Nikola Kotur -
Pierre Rineau -
Steven Jones