You are here

function lightning_scheduler_entity_field_access in Lightning Workflow 8

Implements hook_entity_field_access().

File

modules/lightning_scheduler/lightning_scheduler.module, line 15

Code

function lightning_scheduler_entity_field_access($operation, FieldDefinitionInterface $field_definition, $account, FieldItemListInterface $items = NULL) {

  // We only have an opinion about the scheduled_publication field.
  if ($field_definition instanceof BaseFieldDefinition && $field_definition
    ->getName() == 'scheduled_publication') {
    $nope = AccessResult::forbidden();
    if (empty($items)) {
      return $nope;
    }

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $items
      ->getEntity();
    $workflow = \Drupal::service('content_moderation.moderation_information')
      ->getWorkflowForEntity($entity);
    if ($entity
      ->isNew() || empty($workflow)) {
      return $nope;
    }
  }
  return AccessResult::neutral();
}