justclint β created an issue.
The issue here seemed to be that when we created the new types, we used the same id's as the previous variants. Just changing the type ids solved this issue. This can be closed.
justclint β created an issue.
I was able to get this done with a service decoration.
mymodule.service.yml
dismissible_message_bar.notification_service.decorate:
class: '\Drupal\mymodule\Service\DmbNotificationDecorateService'
decorates: dismissible_message_bar.notification_service
decoration_priority: 9
public: false
arguments: ['@dismissible_message_bar.notification_service.decorate.inner', '@domain.negotiator', '@path.current', '@entity_type.manager', '@request_stack', '@renderer', '@language_manager', '@path.matcher', '@path_alias.manager']
mymodule/src/Service/DmbNotificationDecorateService.php
namespace Drupal\mymodule\Service;
use Drupal\dismissible_message_bar\Service\DmbNotificationService;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Render\Renderer;
use Drupal\domain\DomainNegotiator;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Modifies the Dmb Notifications service.
*/
class DmbNotificationDecorateService extends DmbNotificationService {
/**
* Original service object.
*
* @var \Drupal\dismissible_message_bar\Service\DmbNotificationService
*/
protected $originalService;
/**
* Domain negotiator.
*
* @var \Drupal\domain\DomainNegotiator
*/
protected $domainNegotiator;
/**
* DmbNotificationDecorateService constructor.
*
* @param \Drupal\dismissible_message_bar\Service\DmbNotificationService $original_service
* Service to decorate.
* @param \Drupal\domain\DomainNegotiator $domain_negotiator
* Domain access.
* @param \Drupal\Core\Path\CurrentPathStack $current_path_stack
* Current path stack.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* Request Stack.
* @param \Drupal\Core\Render\Renderer $renderer
* Renderer service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager service.
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
* Path matcher service.
* @param \Drupal\path_alias\AliasManagerInterface $alias_manager
* Alias manager service.
*/
public function __construct(
DmbNotificationService $original_service,
DomainNegotiator $domain_negotiator,
CurrentPathStack $current_path_stack,
EntityTypeManagerInterface $entity_type_manager,
RequestStack $request_stack,
Renderer $renderer,
LanguageManagerInterface $language_manager,
PathMatcherInterface $path_matcher,
AliasManagerInterface $alias_manager ) {
$this->originalService = $original_service;
$this->domainNegotiator = $domain_negotiator;
parent::__construct(
$current_path_stack,
$entity_type_manager,
$request_stack,
$renderer,
$language_manager,
$path_matcher,
$alias_manager
);
}
/**
* Returns array of all notifications.
*
* @return array
* Notification values to insert into drupal settings.
*/
public function returnAllNotifications():array {
$parentNotifications = parent::returnAllNotifications();
$result = [];
if (!empty($parentNotifications)) {
foreach ($parentNotifications as $parentNotification) {
$display = TRUE;
$notification = $this->entityTypeManager->getStorage('dmb_notifications_entity')->load($parentNotification['id']);
// Handle domains.
if ($notification->hasField('field_domain_access') && !$notification->get('field_domain_access')->isEmpty()) {
$field_domain_access = $notification->field_domain_access->getValue();
$enabled_domains = [];
foreach ($field_domain_access as $domain_array) {
$enabled_domains[] = $domain_array['target_id'];
}
$getActiveDomain = $this->domainNegotiator->getActiveDomain();
$currentDomainId = $getActiveDomain->id();
if (!in_array($currentDomainId, $enabled_domains)) {
$display = FALSE;
}
}
if ($display) {
$result[$parentNotification['id']] = $parentNotification;
}
}
}
return $result;
}
}
@gausarts, apologies for delayed reply. Its just taken a while to monitor and diagnose. Your recommendation about reattaching the behaviors did seem to reduce the issue by about 80-90%. Although it was still occurring, it did point us in the right direction and was able to track this back to this issue:
https://www.drupal.org/project/drupal/issues/3105024 π Drupal main javascript file can't be loaded with "defer" attribute after upgrade to 8.8.1 Fixed
So just want to mention in case anyone comes across this. The is not a blazy issue. Ultimately applying this solved the problem:
https://www.drupal.org/project/advagg/issues/3046173#comment-14078683 β
We are also using domain access https://www.drupal.org/project/domain β and trying to restrict specific bundle types to domains.
We've been able to add new notification bundles with custom domain data field but seems like all the conditional logic is in DmbNotificationService.php.
Is there a recommended approach to adding custom viewing conditions per bundle type?
Thanks!
Thanks @SomebodySysop. Your suggestion worked. We were seeing this error in our logs which didnt have any links so for anyone else in the same situation, these are the 2 pages to save:
/admin/config/search/search-api/index/content/fields/edit/rendered
/admin/config/search/search-api/index/content/fields
Thanks Mojiferous! That worked.
justclint β created an issue.
Thanks @gausarts!
Im adding the blazy/load dependency higher up in our theme to see if that remedies the problem. If I see this issue again Ill try the dBlazy.ready method.
justclint β created an issue.
Thanks for the suggestion. Attaching library to the block in preprocess does the job for now.
justclint β created an issue.
Thanks @Mojiferous, I finally found issue being permissions. After allowing "anonymous" users to "View published DMB Notifications entities" I can see the notification content now.
So per my original question, I think we can close this as its solved.
However, not sure what I just experienced is a bug in the sense that, when a role (anonymous in my case) is not given the permission "View published DMB Notifications entities", they can still view the notification, it just happens to be hiding the content within. Im guessing if role does not have that permission, then expectation would be they should not see the notification at all.
justclint β created an issue.
Thanks for the detailed explanation. This is very helpful.
I tried listening to blazy.done
and it works but I must be missing or misunderstanding something in regards to timing.
When I use it like this I guess I was expecting that after blazy was done, we'd see the data-src value moved to src but this doesnt seem to be the case in my test:
(function ($, Drupal, once, dBlazy) {
Drupal.behaviors.cardGrid = {
attach: function (context, settings) {
once('cardGrid', '.card-grid', context).forEach(function (element) {
$(".card").each(function () {
const cardImage = $(".b-lazy", this);
const showImage = function () {
console.log(image.data('src')); // STILL POPULATED
console.log(image.attr('src')); // STILL EMPTY
// Hide skeleton overlay...
}
dBlazy.on(cardImage, 'blazy.done', showImage, false);
});
});
}
};
})(jQuery, Drupal, once, dBlazy);
For sake of this issue, I think we can close. What you provided above puts me in the right direction and if I can come up with meaningful patches I will.
Thanks again!
Thanks @gausarts!
I see we have Drupal.blazy.init.load(), Drupal.blazy.init.revalidate(), etc.. and options.success and options.error.
Im able to execute on options.success and options.error but I get unexpected results where params are always undefined. Im guessing my syntax might be off here:
Drupal.blazy.init.options.success(function (element, msg) {
console.log("success");
console.log(element);
console.log(msg);
});
Drupal.blazy.init.options.error(function (element, msg) {
console.log("error");
console.log(element);
console.log(msg);
});
What would be the correct way to replicate this https://dinbror.dk/blog/blazy/#Callback in new IO? I need to execute on each image after successful lazyload and log any errors if they come up.
justclint β created an issue.