πŸ‡ΊπŸ‡ΈUnited States @RustedBucket

Account created on 1 July 2017, over 7 years ago
#

Recent comments

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

Currently battling this same issue. Trying to override a view template from a custom module.
Basically I want to override the themes views_view_unformatted.html.twig template

My custom template resides in modules/custom/custom_app/templates/views-view--on-campus-numbers.html.twig
In my custom_app.module file I have the following:

function custom_app_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if ($hook == 'views_view_unformatted') {
    $suggestions[] = 'views-view--on-campus-numbers';
  }
}


function custom_app_theme($existing, $type, $theme, $path) {
  return [
    'views_view__on_campus_numbers' => [
      'base_hook' => 'views_view_unformatted',
    ]
  ];
}

This throws 2 errors:

Warning: Undefined array key "render element" in Drupal\Core\Theme\ThemeManager->render() (line 199 of core/lib/Drupal/Core/Theme/ThemeManager.php).
Drupal\Core\Theme\ThemeManager->render('views_view__on_campus_numbers', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 187)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Warning: Undefined array key "render element" in Drupal\Core\Theme\ThemeManager->render() (line 201 of core/lib/Drupal/Core/Theme/ThemeManager.php).
Drupal\Core\Theme\ThemeManager->render('views_view__on_campus_numbers', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 187)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Adding 'render element' => 'elements' like this makes the error go away but no output from the view is rendered

    'views_view__on_campus_numbers' => [
      'render element' => 'elements',
      'base_hook' => 'views_view_unformatted',
    ]
πŸ‡ΊπŸ‡ΈUnited States RustedBucket

In response to #29, I've applied patch in #28 and added the config entries. When shutting down the Redis server I continue to get:
Error: Class "Redis" not found in Drupal\redis\Client\PhpRedis->getClient() (line 18 of /web/modules/contrib/redis/src/Client/PhpRedis.php) in the logs.

The instantiation of the Redis class fails.
In phpRedis.php
$client = new \Redis();

I think I have everything right.
Copied modules/redis/example.failover.services.yml to /sites/default/redis.failover.services.yml

settings.local.php

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/redis.failover.services.yml';
$settings['cache']['default'] = 'cache.backend.redis';
$settings['redis.failover'] = TRUE;
$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['host'] = '127.0.0.1';

Any thoughts?

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

I figured out how to do this by overriding the custom block template. This can be closed.

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

Any movement on this? It is a bit frustrating one can't have a module create a json field in a new table. I get the 'work-around' but that nullifies the core power of the field type. I might be wrong but it seems like something the schema api could support without impacting much of anything else.

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

Fyi: setting this $googleService->googleClient->setApiFormatV2(true); does not seem to have any effect. Still using the v3 api.

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

So using the Google_Service_Calendar_Calendar class does work. However, that set apis only exposes a very limited amount of Calendar data as compared the Google_Service_Calendar_CalendarListEntry. Not that it is a big deal but the fact one can't update via $service->calendarList->patch seems problematic. For instance, if one wanted to update the backgroundColor that isn't part of the Calendar_Calendar class so you have to use Calendar_CalendarListEntry.

Also, is there an easy way to capture the raw request and response objects by chance?

Thanks

πŸ‡ΊπŸ‡ΈUnited States RustedBucket

Yep, that seemed to do the trick. Thanks.

Below is my altered code. I just added the line $googleService->googleClient->setConfig('subject', $gmailAddress); Based on your find I also found an old issue from 2016 in the google clients issues that talks about it. https://github.com/googleapis/google-api-php-client/issues/891

Looks like it's an undocumented change to the apis or if it is documented it's buried somewhere. I don't know if it's worth trying to make a "fix" for this vs maybe adding it to the documentation somewhere. Hopefully this is the only gotcha, I started with gmail for what I'm doing because I already had examples that worked. One would think this only applies to the GMail apis but who knows.

And to answer your question about which email I used, it was the email address I'm trying to impersonate so NOT the one from the api credentials since this is intended to pull emails for a user logged into our Drupal.

Thanks for the quick response.

// Would normally be passed into this as a function parameter
$gmailAddress = 'some_user@valid_domain.com';

$google_api_service_client = \Drupal::entityTypeManager()->getStorage('google_api_service_client')->load('stored_client_id');

// Get the service.
$googleService = \Drupal::service('google_api_service_client.client');

// Set the account.
$googleService->setGoogleApiClient($google_api_service_client);

// Define subject for impersonation
$googleService->googleClient->setConfig('subject', $gmailAddress);

// Set optional parameters for the Gmail service
$optParams = array(
  'labelIds' => 'INBOX',
  'q' => '@uncc.edu',
  'maxResults' => 10,
);

try {
  $gmail = new \Google_Service_Gmail($googleService->googleClient);
  $threads = $gmail->users_messages->listUsersMessages($gmailAddress, $optParams);
  dpm($threads);
}
catch (Exception $e) {
  ksm($e);
}
Production build 0.71.5 2024