I have a custom action to update some table values base on node content selection. My custom actions are listed correctly on bulk update select box. But I can perform operation some random node content only. Any thoughts!! why It's allow actions to perform on some contents only.
View Bulk Operation: https://www.drupal.org/project/views_bulk_operations
Tried Version: 8.x-3.13 , 4.0.0-rc1
<?php
namespace Drupal\custom_user\Plugin\Action;
use Drupal\node\Entity\Node;
use Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Content moderation publish node.
*
* @Action(
* id = "notification_read",
* label = @Translation("Update Notification As Read"),
* type = "node",
* confirm = TRUE
* )
*/
class NotificationRead extends ViewsBulkOperationsActionBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function execute(ContentEntityInterface $entity = NULL) {
$nid = $entity->id();
$uid = \Drupal::currentUser()->id();
if ($nid) {
$connection = \Drupal::database();
$connection->delete('notifications')
->condition('entity_id', $nid)
->condition('entity_uid', $uid)
->execute();
}
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
\Drupal::logger('test')->warning(print_r("test", TRUE));
if ($object instanceof Node) {
return True;
}
return FALSE;
}
}[![enter image description here][1]][1]