1

I'm trying to style the title field from a view. So I create this template

views-view-field--frontpage--title.html.twig

And when I was trying to see what variables are avaiable in this template level. I decide to add

{{ kint() }}

And for some reason it showing me this huge error.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: CREATE TABLE {cache_render} ( `cid` VARCHAR(255) BINARY CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'Primary Key: Unique cache ID.', `data` LONGBLOB NULL DEFAULT NULL COMMENT 'A collection of data to cache.', `expire` INT NOT NULL DEFAULT 0 COMMENT 'A Unix timestamp indicating when the cache entry should expire, or -1 for never.', `created` DECIMAL(14, 3) NOT NULL DEFAULT 0 COMMENT 'A timestamp with millisecond precision indicating when the cache entry was created.', `serialized` SMALLINT NOT NULL DEFAULT 0 COMMENT 'A flag to indicate whether content is serialized (1) or not (0).', `tags` LONGTEXT NULL DEFAULT NULL COMMENT 'Space-separated list of cache tags for this entry.', `checksum` VARCHAR(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL COMMENT 'The tag invalidation checksum when this entry was saved.', PRIMARY KEY (`cid`), INDEX `expire` (`expire`) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COMMENT 'Storage for the cache API.'; Array ( ) in Drupal\Core\Render\RenderCache->set() (line 275 of core/lib/Drupal/Core/Render/RenderCache.php).The website encountered an unexpected error. Please try again later.

I think this might be a Drupal 8 bug, but I'm not sure.

So my question are..

  • How can I get the variables ? Or at least the field value so I can added wrapper around it.

  • In Drupal 8, do you think I went to deep on this template ? I notice that using the theme_debug functionality I could not see this template suggestion.

9
  • 1
    What is your MySQL MAX_ALLOWED_PACKET set at? It think it's more likely to be a config issue than a bug at first glance. e.g. you're inadvertently trying to force too much data into cache by invoking kint() with any arguments on a page that has some deeply nested/complicated vars in it
    – Clive
    Jan 8, 2016 at 13:44
  • @Clive, it was set to 16M. I change it to 160M for testing purpose and it fixed my issue. What you think it will be a decent amount for MAX_ALLOWED_PACKET ? Jan 8, 2016 at 13:47
  • What I think's irrelevant ;) Read through Rolando's answer here, that should help quite a bit
    – Clive
    Jan 8, 2016 at 13:49
  • 2
    Possible duplicate of Database general error: 2006 MySQL server has gone away
    – kenorb
    Jun 7, 2016 at 15:00
  • 1
    @darol100 not sure if you are aware of this by now, but you can manually change a config setting so you don't get WSOD when trying to {{ kint() }}, see this answer
    – No Sssweat
    Jan 9, 2017 at 12:51

1 Answer 1

4

If you do kint(), then it will try to output the raw data from the sql query and that is obviously to much for kint.

In this template there is not much going on and so there is not really much you can inspect with kint:

function template_preprocess_views_view_field(&$variables) {
  $variables['output'] = $variables['field']->advancedRender($variables['row']);
}

You can check the output with

{{ kint('output') }}

But this will only be the field content.

If you want to put a wrapper around the field, that is no problem, that is, what this twig is used for in most cases:

<div class="myfield">{{ output -}}<div>

If you want to debug the variables, see what variables are available in the view templates, look in core/modules/views/views.theme.inc and inspect them one by one with kint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.