Does theme_suggestions_views_view_alter work with views in Drupal 8.x.3? I have cleared the cache(drush cr) multiple times to try and get it to work. After a search on the web, I can't seem to find any information on this subject and wondering is this a bug or it can't be done.

  1. Image Selection_004.jpg shows that suggestions exist in debugging.
  2. Image Selection_008.jpg is the twig file that I have created in my theme.

This is the function I have been trying to get to work.

/**
 * Implements hook_theme_suggestions_HOOK_alter() for form templates.
 *
 * @param array $suggestions
 * @param array $variables
 */
function purencool_vision_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {

  if (isset($variables['view'])) {
    $view_id = $variables['view']->id();
    $view_block = $variables['view']->getDisplay()->display['id'];
    array_splice($suggestions, 1, 0, 'view__' . $view_id . '__' . $view_block);
  }
}
Files: 
CommentFileSizeAuthor
Selection_008.jpg144.84 KBPurencool
Selection_004.jpg23.36 KBPurencool

Comments

Purencool created an issue. See original summary.

Purencool’s picture

Issue summary: View changes
Lendude’s picture

Project: Views » Drupal core
Version: 8.x-3.x-dev » 8.3.x-dev
Component: Miscellaneous » views.module

Views is in Drupal Core now, so moving to the right queue.

tetranz’s picture

I think the problem here is that your suggestion needs to start with views__view__ and template start with views--view--.

I'm not sure of all the rules but it seems like you need to start with the base name as the template you're overriding.

Having said that, I don't think you need this code at all. Core already implements the pattern that I think you're trying to achieve.

http://redcrackle.com/blog/drupal-8/theme-views-templates

I created a view called test with a display called page_1.
That uses my template views-view--test--page-1.html.twig with no additional suggestions needed.

Unfortunately the theme debugging comments doesn't show view's default suggestions.

Just as side note. I don't really follow your use of array_splice. Isn't that the same as this?
$suggestions[] = 'view__' . $view_id . '__' . $view_block;