You are here

author.inc in Entity Construction Kit (ECK) 7.2

Same filename and directory in other branches
  1. 7.3 plugins/property_behavior/author.inc

File

plugins/property_behavior/author.inc
View 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',
);

/**
 * 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 && !isset($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;
}

Functions

Namesort descending Description
eck_author_property_entity_save When the entity is first saved, store the current user id as the author.
eck_author_property_property_info Let the system know that this property holds a user id.