ECK entity getOwnerID() returns null value

Created on 13 August 2020, almost 5 years ago
Updated 26 December 2024, 5 months ago

Problem/Motivation

I am trying to implement 'own permissions' for Drupal 8 version of ECK. I want to access the 'owner' uid for ECK entity to allow content creators to make changes and disallow everyone else.

Steps to reproduce

  • Create an ECK bundle with multiple fields
  • Reference the ECK bundle from a content type
  • Allow users to create content type nodes
  • ECK permission system does not allow 'own' content edit/delete access which can be a security vulnerability
  • Disallow 'edit all' and 'delete all' permissions
  • Write custom code so content type node creators can edit and delete the nodes they created

Proposed resolution

function MODULE_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
  $user = \Drupal::currentUser()->id();
  drupal_set_message(\Drupal::currentUser()->id(), 'error');
  if ($entity->getEntityTypeId() == 'ECK_ENTITYTYPE'){
    switch ($operation) {
      case 'update':
      case 'delete':
        if ($entity->uid() == $user) {
          AccessResult::allowed();
      }
      break;
    }
  }
}

$entity->uid() returns null. $entity->getOwnerID() returns null.

What am I missing?

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: outdated

Component

Miscellaneous

Created by

🇮🇳India arun_kv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium dieterholvoet Brussels

    ECK permission system does not allow 'own' content edit/delete access which can be a security vulnerability

    Nowadays it does. Not sure why no user was returned in your case, maybe because access was being checked for an empty/new entity?

Production build 0.71.5 2024