Skip to content

Instantly share code, notes, and snippets.

View DiDebru's full-sized avatar
🏠
Working from home

DiDebru DiDebru

🏠
Working from home
View GitHub Profile
```
<?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;
@DiDebru
DiDebru / gist:c4037b26b04389e86cc9d08aed418260
Last active June 22, 2018 13:14
node access hook content moderation and workflow
/**
* 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();