0

I have come quite far in my Drupal 8 development without needing to write much custom php code. However, I am using paragraphs and eck entities as referenced entities in content types. For users to be able to edit their own content, I need edit and delete permissions in paragraph and eck to apply to only own content. I looked up some hooks and wrote the below code in my theme file. It doesn't work. Will appreciate any help in taking this to finish line.

  function THEME_entity_info_alter(&$entity_info) {
    $entity_info['contact_information_fields']['access callback'] = 'THEME_ENTITYNAME_access';
  }
    
  function THEME_ENTITYNAME_access(\Drupal\Core\Entity\EntityInterface $entity, $op, \Drupal\Core\Session\AccountInterface $account) {
    $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
    switch ($op) {
      case 'update':
      case 'delete':
        if ($entity->uid == $user->get('uid')) {
          return TRUE;
        }
        break;
    }
    
    return eck__entity_access($entity, $op, $account);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.