author.inc in Entity Construction Kit (ECK) 7.3
Same filename and directory in other branches
File
plugins/property_behavior/author.incView source
<?php
/**
 * @file
 * Author Behavior.
 *
 * Save the user id of the user when the entity is created.
 */
$plugin = array(
  'label' => "Author",
  'entity_save' => 'eck_author_property_entity_save',
  'property_info' => 'eck_author_property_property_info',
  'permissions' => 'eck_author_property_permissions',
);
/**
 * When the entity is first saved, store the current user id as the author.
 */
function eck_author_property_entity_save($property, $vars) {
  $entity = $vars['entity'];
  if (isset($entity->is_new) && $entity->is_new && empty($entity->{$property})) {
    global $user;
    $entity->{$property} = $user->uid;
  }
}
/**
 * Let the system know that this property holds a user id.
 */
function eck_author_property_property_info($property, $vars) {
  $vars['properties'][$property]['type'] = 'user';
  return $vars;
}
/**
 * Augmenting the permission system with own permissions.
 */
function eck_author_property_permissions($property, $vars) {
  $op = $vars['op'];
  $perms = $vars['permissions'];
  $account = $vars['account'];
  $entity = $vars['entity'];
  $allow = FALSE;
  foreach ($perms as $perm) {
    $p = $perm->permission;
    $property = $entity->{$property};
    $uid = $account->uid;
    if (strcmp($p, "{$op} own entity") == 0 && $property == $uid) {
      $allow = TRUE;
    }
  }
  return $allow;
}Functions
| Name   | Description | 
|---|---|
| eck_author_property_entity_save | When the entity is first saved, store the current user id as the author. | 
| eck_author_property_permissions | Augmenting the permission system with own permissions. | 
| eck_author_property_property_info | Let the system know that this property holds a user id. | 
