This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
<?php | |
namespace Drupal\thunder_article\Form; | |
use Drupal\content_moderation\ModerationInformationInterface; | |
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
use Drupal\Core\Entity\EntityTypeManagerInterface; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Messenger\MessengerInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_node_access(). | |
*/ | |
function my_module_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Session\AccountInterface $account) { | |
$state = $node->moderation_state->value; | |
switch($op) { | |
case 'update': | |
if ($state !== 'draft') { | |
if ($account->hasPermission('view any unpublished content')) { | |
return AccessResult::allowed()->cachePerPermissions(); |