FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
23
sites/all/modules/contrib/dev/entity/modules/book.info.inc
Normal file
23
sites/all/modules/contrib/dev/entity/modules/book.info.inc
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about book nodes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of book module.
|
||||
*
|
||||
* @see entity_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_book_entity_property_info_alter(&$info) {
|
||||
// Add meta-data about the added node properties.
|
||||
$properties = &$info['node']['properties'];
|
||||
|
||||
$properties['book'] = array(
|
||||
'label' => t("Book"),
|
||||
'type' => 'node',
|
||||
'description' => t("If part of a book, the book to which this book page belongs."),
|
||||
'getter callback' => 'entity_metadata_book_get_properties',
|
||||
);
|
||||
}
|
974
sites/all/modules/contrib/dev/entity/modules/callbacks.inc
Normal file
974
sites/all/modules/contrib/dev/entity/modules/callbacks.inc
Normal file
@@ -0,0 +1,974 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides various callbacks for the whole core module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback for getting properties of an entity.
|
||||
*/
|
||||
function entity_metadata_entity_get_properties($entity, array $options, $name, $entity_type) {
|
||||
if ($name == 'url') {
|
||||
$return = entity_uri($entity_type, $entity);
|
||||
return url($return['path'], $return['options'] + $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting book node properties.
|
||||
* @see entity_metadata_book_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_book_get_properties($node, array $options, $name, $entity_type) {
|
||||
if (!isset($node->book['bid'])) {
|
||||
throw new EntityMetadataWrapperException('This node is no book page.');
|
||||
}
|
||||
return $node->book['bid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting comment properties.
|
||||
* @see entity_metadata_comment_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_comment_get_properties($comment, array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'name':
|
||||
return $comment->name;
|
||||
|
||||
case 'mail':
|
||||
if ($comment->uid != 0) {
|
||||
$account = user_load($comment->uid);
|
||||
return $account->mail;
|
||||
}
|
||||
return $comment->mail;
|
||||
|
||||
case 'edit_url':
|
||||
return url('comment/edit/' . $comment->cid, $options);
|
||||
|
||||
case 'parent':
|
||||
if (!empty($comment->pid)) {
|
||||
return $comment->pid;
|
||||
}
|
||||
// There is no parent comment.
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for setting comment properties.
|
||||
* @see entity_metadata_comment_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_comment_setter($comment, $name, $value) {
|
||||
switch ($name) {
|
||||
case 'node':
|
||||
$comment->nid = $value;
|
||||
// Also set the bundle name.
|
||||
$node = node_load($value);
|
||||
$comment->node_type = 'comment_node_' . $node->type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting comment related node properties.
|
||||
* @see entity_metadata_comment_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_comment_get_node_properties($node, array $options, $name, $entity_type) {
|
||||
switch ($name) {
|
||||
case 'comment_count':
|
||||
return isset($node->comment_count) ? $node->comment_count : 0;
|
||||
|
||||
case 'comment_count_new':
|
||||
return comment_num_new($node->nid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter callback for getting global languages.
|
||||
*/
|
||||
function entity_metadata_locale_get_languages($data, array $options, $name) {
|
||||
return isset($GLOBALS[$name]) ? $GLOBALS[$name]->language : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter callback for getting the preferred user language.
|
||||
*/
|
||||
function entity_metadata_locale_get_user_language($account, array $options, $name) {
|
||||
return user_preferred_language($account)->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the options lists for the node and comment status property.
|
||||
*/
|
||||
function entity_metadata_status_options_list() {
|
||||
return array(
|
||||
NODE_PUBLISHED => t('Published'),
|
||||
NODE_NOT_PUBLISHED => t('Unpublished'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting node properties.
|
||||
*
|
||||
* @see entity_metadata_node_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_node_get_properties($node, array $options, $name, $entity_type) {
|
||||
switch ($name) {
|
||||
case 'is_new':
|
||||
return empty($node->nid) || !empty($node->is_new);
|
||||
|
||||
case 'source':
|
||||
if (!empty($node->tnid) && $source = node_load($node->tnid)) {
|
||||
return $source;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case 'edit_url':
|
||||
return url('node/' . $node->nid . '/edit', $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for determing access for node revision related properties.
|
||||
*/
|
||||
function entity_metadata_node_revision_access($op, $name, $entity = NULL, $account = NULL) {
|
||||
return $op == 'view' ? user_access('view revisions', $account) : user_access('administer nodes', $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting poll properties.
|
||||
* @see entity_metadata_poll_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_poll_node_get_properties($node, array $options, $name) {
|
||||
$total_votes = $highest_votes = 0;
|
||||
foreach ($node->choice as $choice) {
|
||||
if ($choice['chvotes'] > $highest_votes) {
|
||||
$winner = $choice;
|
||||
$highest_votes = $choice['chvotes'];
|
||||
}
|
||||
$total_votes = $total_votes + $choice['chvotes'];
|
||||
}
|
||||
|
||||
if ($name == 'poll_duration') {
|
||||
return $node->runtime;
|
||||
}
|
||||
elseif ($name == 'poll_votes') {
|
||||
return $total_votes;
|
||||
}
|
||||
elseif (!isset($winner)) {
|
||||
// There is no poll winner yet.
|
||||
return NULL;
|
||||
}
|
||||
switch ($name) {
|
||||
case 'poll_winner_votes':
|
||||
return $winner['chvotes'];
|
||||
|
||||
case 'poll_winner':
|
||||
return $winner['chtext'];
|
||||
|
||||
case 'poll_winner_percent':
|
||||
return ($winner['chvotes'] / $total_votes) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting statistics properties.
|
||||
* @see entity_metadata_statistics_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_statistics_node_get_properties($node, array $options, $name) {
|
||||
$statistics = (array) statistics_get($node->nid);
|
||||
$statistics += array('totalcount' => 0, 'daycount' => 0, 'timestamp' => NULL);
|
||||
|
||||
switch ($name) {
|
||||
case 'views':
|
||||
return $statistics['totalcount'];
|
||||
|
||||
case 'day_views':
|
||||
return $statistics['daycount'];
|
||||
|
||||
case 'last_view':
|
||||
return $statistics['timestamp'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting site-wide properties.
|
||||
* @see entity_metadata_system_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_system_get_properties($data = FALSE, array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'name':
|
||||
return variable_get('site_name', 'Drupal');
|
||||
|
||||
case 'url':
|
||||
return url('<front>', $options);
|
||||
|
||||
case 'login_url':
|
||||
return url('user', $options);
|
||||
|
||||
case 'current_user':
|
||||
return $GLOBALS['user']->uid ? $GLOBALS['user']->uid : drupal_anonymous_user();
|
||||
|
||||
case 'current_date':
|
||||
return REQUEST_TIME;
|
||||
|
||||
case 'current_page':
|
||||
// Subsequent getters of the struct retrieve the actual values.
|
||||
return array();
|
||||
|
||||
default:
|
||||
return variable_get('site_' . $name, '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting properties for the current page request.
|
||||
* @see entity_metadata_system_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_system_get_page_properties($data = array(), array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'url':
|
||||
return $GLOBALS['base_root'] . request_uri();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting file properties.
|
||||
* @see entity_metadata_system_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_system_get_file_properties($file, array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'name':
|
||||
return $file->filename;
|
||||
|
||||
case 'mime':
|
||||
return $file->filemime;
|
||||
|
||||
case 'size':
|
||||
return $file->filesize;
|
||||
|
||||
case 'url':
|
||||
return url(file_create_url($file->uri), $options);
|
||||
|
||||
case 'owner':
|
||||
return $file->uid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting term properties.
|
||||
*
|
||||
* @see entity_metadata_taxonomy_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_taxonomy_term_get_properties($term, array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'node_count':
|
||||
return count(taxonomy_select_nodes($term->tid));
|
||||
|
||||
case 'description':
|
||||
return check_markup($term->description, isset($term->format) ? $term->format : NULL, '', TRUE);
|
||||
|
||||
case 'parent':
|
||||
if (isset($term->parent[0]) && !is_array(isset($term->parent[0]))) {
|
||||
return $term->parent;
|
||||
}
|
||||
return array_keys(taxonomy_get_parents($term->tid));
|
||||
|
||||
case 'parents_all':
|
||||
// We have to return an array of ids.
|
||||
$tids = array();
|
||||
foreach (taxonomy_get_parents_all($term->tid) as $parent) {
|
||||
$tids[] = $parent->tid;
|
||||
}
|
||||
return $tids;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for setting term properties.
|
||||
*
|
||||
* @see entity_metadata_taxonomy_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_taxonomy_term_setter($term, $name, $value) {
|
||||
switch ($name) {
|
||||
case 'vocabulary':
|
||||
// Make sure to update the taxonomy bundle key, so load the vocabulary.
|
||||
// Support both, loading by name or ID.
|
||||
$vocabulary = is_numeric($value) ? taxonomy_vocabulary_load($value) : taxonomy_vocabulary_machine_name_load($value);
|
||||
$term->vocabulary_machine_name = $vocabulary->machine_name;
|
||||
return $term->vid = $vocabulary->vid;
|
||||
case 'parent':
|
||||
return $term->parent = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting vocabulary properties.
|
||||
* @see entity_metadata_taxonomy_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_taxonomy_vocabulary_get_properties($vocabulary, array $options, $name) {
|
||||
switch ($name) {
|
||||
case 'term_count':
|
||||
$sql = "SELECT COUNT (1) FROM {taxonomy_term_data} td WHERE td.vid = :vid";
|
||||
return db_query($sql, array(':vid' => $vocabulary->vid))->fetchField();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting user properties.
|
||||
* @see entity_metadata_user_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_user_get_properties($account, array $options, $name, $entity_type) {
|
||||
switch ($name) {
|
||||
case 'last_access':
|
||||
// In case there was no access the value is 0, but we have to return NULL.
|
||||
return empty($account->access) ? NULL : $account->access;
|
||||
|
||||
case 'last_login':
|
||||
return empty($account->login) ? NULL : $account->login;
|
||||
|
||||
case 'name':
|
||||
return empty($account->uid) ? variable_get('anonymous', t('Anonymous')) : $account->name;
|
||||
|
||||
case 'url':
|
||||
if (empty($account->uid)) {
|
||||
return NULL;
|
||||
}
|
||||
$return = entity_uri('user', $account);
|
||||
return $return ? url($return['path'], $return['options'] + $options) : '';
|
||||
|
||||
case 'edit_url':
|
||||
return empty($account->uid) ? NULL : url("user/$account->uid/edit", $options);
|
||||
|
||||
case 'roles':
|
||||
return isset($account->roles) ? array_keys($account->roles) : array();
|
||||
|
||||
case 'theme':
|
||||
return empty($account->theme) ? variable_get('theme_default', 'bartik') : $account->theme;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for setting user properties.
|
||||
* @see entity_metadata_user_entity_info_alter()
|
||||
*/
|
||||
function entity_metadata_user_set_properties($account, $name, $value) {
|
||||
switch ($name) {
|
||||
case 'roles':
|
||||
$account->roles = array_intersect_key(user_roles(), array_flip($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options list callback returning all user roles.
|
||||
*/
|
||||
function entity_metadata_user_roles($property_name = 'roles', $info = array(), $op = 'edit') {
|
||||
$roles = user_roles();
|
||||
if ($op == 'edit') {
|
||||
unset($roles[DRUPAL_AUTHENTICATED_RID], $roles[DRUPAL_ANONYMOUS_RID]);
|
||||
}
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the options lists for user status property.
|
||||
*/
|
||||
function entity_metadata_user_status_options_list() {
|
||||
return array(
|
||||
0 => t('Blocked'),
|
||||
1 => t('Active'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback defining an options list for language properties.
|
||||
*/
|
||||
function entity_metadata_language_list() {
|
||||
$list = array();
|
||||
$list[LANGUAGE_NONE] = t('Language neutral');
|
||||
foreach (language_list() as $language) {
|
||||
$list[$language->language] = $language->name;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting field property values.
|
||||
*/
|
||||
function entity_metadata_field_property_get($entity, array $options, $name, $entity_type, $info) {
|
||||
$field = field_info_field($name);
|
||||
$columns = array_keys($field['columns']);
|
||||
$langcode = isset($options['language']) ? $options['language']->language : LANGUAGE_NONE;
|
||||
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode, TRUE);
|
||||
$values = array();
|
||||
if (isset($entity->{$name}[$langcode])) {
|
||||
foreach ($entity->{$name}[$langcode] as $delta => $data) {
|
||||
$values[$delta] = $data[$columns[0]];
|
||||
if ($info['type'] == 'boolean' || $info['type'] == 'list<boolean>') {
|
||||
// Ensure that we have a clean boolean data type.
|
||||
$values[$delta] = (boolean) $values[$delta];
|
||||
}
|
||||
}
|
||||
}
|
||||
// For an empty single-valued field, we have to return NULL.
|
||||
return $field['cardinality'] == 1 ? ($values ? reset($values) : NULL) : $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for setting field property values.
|
||||
*/
|
||||
function entity_metadata_field_property_set($entity, $name, $value, $langcode, $entity_type, $info) {
|
||||
$field = field_info_field($name);
|
||||
$columns = array_keys($field['columns']);
|
||||
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode);
|
||||
$values = $field['cardinality'] == 1 ? array($value) : (array) $value;
|
||||
|
||||
$items = array();
|
||||
foreach ($values as $delta => $value) {
|
||||
if (isset($value)) {
|
||||
$items[$delta][$columns[0]] = $value;
|
||||
if ($info['type'] == 'boolean' || $info['type'] == 'list<boolean>') {
|
||||
// Convert boolean values back to an integer for writing.
|
||||
$items[$delta][$columns[0]] = (integer) $items[$delta][$columns[0]] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$entity->{$name}[$langcode] = $items;
|
||||
// Empty the static field language cache, so the field system picks up any
|
||||
// possible new languages.
|
||||
drupal_static_reset('field_language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback returning the options list of a field.
|
||||
*/
|
||||
function entity_metadata_field_options_list($name, $info) {
|
||||
$field_property_info = $info;
|
||||
if (is_numeric($name) && isset($info['parent'])) {
|
||||
// The options list is to be returned for a single item of a multiple field.
|
||||
$field_property_info = $info['parent']->info();
|
||||
$name = $field_property_info['name'];
|
||||
}
|
||||
if (($field = field_info_field($name)) && isset($field_property_info['parent'])) {
|
||||
// Retrieve the wrapped entity holding the field.
|
||||
$wrapper = $field_property_info['parent'];
|
||||
try {
|
||||
$entity = $wrapper->value();
|
||||
}
|
||||
catch (EntityMetadataWrapperException $e) {
|
||||
// No data available.
|
||||
$entity = NULL;
|
||||
}
|
||||
$instance = $wrapper->getBundle() ? field_info_instance($wrapper->type(), $name, $wrapper->getBundle()) : NULL;
|
||||
return (array) module_invoke($field['module'], 'options_list', $field, $instance, $wrapper->type(), $entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to verbatim get the data structure of a field. Useful for fields
|
||||
* that add metadata for their own data structure.
|
||||
*/
|
||||
function entity_metadata_field_verbatim_get($entity, array $options, $name, $entity_type, &$context) {
|
||||
// Set contextual info useful for getters of any child properties.
|
||||
$context['instance'] = field_info_instance($context['parent']->type(), $name, $context['parent']->getBundle());
|
||||
$context['field'] = field_info_field($name);
|
||||
$langcode = isset($options['language']) ? $options['language']->language : LANGUAGE_NONE;
|
||||
$langcode = entity_metadata_field_get_language($entity_type, $entity, $context['field'], $langcode, TRUE);
|
||||
|
||||
if ($context['field']['cardinality'] == 1) {
|
||||
return isset($entity->{$name}[$langcode][0]) ? $entity->{$name}[$langcode][0] : NULL;
|
||||
}
|
||||
return isset($entity->{$name}[$langcode]) ? $entity->{$name}[$langcode] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the passed field items in the object. Useful as field level setter
|
||||
* to set the whole data structure at once.
|
||||
*/
|
||||
function entity_metadata_field_verbatim_set($entity, $name, $items, $langcode, $entity_type) {
|
||||
$field = field_info_field($name);
|
||||
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode);
|
||||
$value = $field['cardinality'] == 1 ? array($items) : (array) $items;
|
||||
// Filter out any items set to NULL.
|
||||
$entity->{$name}[$langcode] = array_filter($value);
|
||||
|
||||
// Empty the static field language cache, so the field system picks up any
|
||||
// possible new languages.
|
||||
drupal_static_reset('field_language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for determining the field language to be used.
|
||||
*
|
||||
* Note that we cannot use field_language() as we are not about to display
|
||||
* values, but generally read/write values.
|
||||
*
|
||||
* @param $fallback
|
||||
* (optional) Whether to fall back to the entity default language, if no
|
||||
* value is available for the given language code yet.
|
||||
*
|
||||
* @return
|
||||
* The language code to use.
|
||||
*/
|
||||
function entity_metadata_field_get_language($entity_type, $entity, $field, $langcode = LANGUAGE_NONE, $fallback = FALSE) {
|
||||
// Try to figure out the default language used by the entity.
|
||||
// With Drupal >= 7.15 we can use entity_language().
|
||||
if (function_exists('entity_language')) {
|
||||
$default_langcode = entity_language($entity_type, $entity);
|
||||
}
|
||||
else {
|
||||
$default_langcode = !empty($entity->language) ? $entity->language : LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
// Determine the right language to use.
|
||||
if ($default_langcode != LANGUAGE_NONE && field_is_translatable($entity_type, $field)) {
|
||||
$langcode = ($langcode != LANGUAGE_NONE) ? field_valid_language($langcode, $default_langcode) : $default_langcode;
|
||||
if (!isset($entity->{$field['field_name']}[$langcode]) && $fallback) {
|
||||
$langcode = $default_langcode;
|
||||
}
|
||||
return $langcode;
|
||||
}
|
||||
else {
|
||||
return LANGUAGE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting the sanitized text of 'text_formatted' properties.
|
||||
* This callback is used for both the 'value' and the 'summary'.
|
||||
*/
|
||||
function entity_metadata_field_text_get($item, array $options, $name, $type, $context) {
|
||||
// $name is either 'value' or 'summary'.
|
||||
if (!isset($item['safe_' . $name])) {
|
||||
// Apply input formats.
|
||||
$langcode = isset($options['language']) ? $options['language']->language : '';
|
||||
$format = isset($item['format']) ? $item['format'] : filter_default_format();
|
||||
$item['safe_' . $name] = check_markup($item[$name], $format, $langcode);
|
||||
// To speed up subsequent calls, update $item with the 'safe_value'.
|
||||
$context['parent']->set($item);
|
||||
}
|
||||
return $item['safe_' . $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the list of all available text formats.
|
||||
*/
|
||||
function entity_metadata_field_text_formats() {
|
||||
foreach (filter_formats() as $key => $format) {
|
||||
$formats[$key] = $format->name;
|
||||
}
|
||||
return $formats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for getting the file entity of file fields.
|
||||
*/
|
||||
function entity_metadata_field_file_get($item) {
|
||||
return $item['fid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for setting the file entity of file fields.
|
||||
*/
|
||||
function entity_metadata_field_file_set(&$item, $property_name, $value) {
|
||||
$item['fid'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for auto-creating file field $items.
|
||||
*/
|
||||
function entity_metadata_field_file_create_item($property_name, $context) {
|
||||
// 'fid' is required, so 'file' has to be set as initial property.
|
||||
return array('display' => isset($context['field']['settings']['display_default']) ? $context['field']['settings']['display_default'] : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for validating file field $items.
|
||||
*/
|
||||
function entity_metadata_field_file_validate_item($items, $context) {
|
||||
// Allow NULL values.
|
||||
if (!isset($items)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Stream-line $items for multiple vs non-multiple fields.
|
||||
$items = !entity_property_list_extract_type($context['type']) ? array($items) : (array) $items;
|
||||
|
||||
foreach ($items as $item) {
|
||||
// File-field items require a valid file.
|
||||
if (!isset($item['fid']) || !file_load($item['fid'])) {
|
||||
return FALSE;
|
||||
}
|
||||
if (isset($context['property info']['display']) && !isset($item['display'])) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for the node entity.
|
||||
*
|
||||
* This function does not implement hook_node_access(), thus it may not be
|
||||
* called entity_metadata_node_access().
|
||||
*/
|
||||
function entity_metadata_no_hook_node_access($op, $node = NULL, $account = NULL) {
|
||||
if (isset($node)) {
|
||||
// If a non-default revision is given, incorporate revision access.
|
||||
$default_revision = node_load($node->nid);
|
||||
if ($node->vid != $default_revision->vid) {
|
||||
return _node_revision_access($node, $op);
|
||||
}
|
||||
else {
|
||||
return node_access($op, $node, $account);
|
||||
}
|
||||
}
|
||||
// Is access to all nodes allowed?
|
||||
if (!user_access('access content', $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (user_access('bypass node access', $account) || (!isset($account) && $op == 'view' && node_access_view_all_nodes())) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for the user entity.
|
||||
*/
|
||||
function entity_metadata_user_access($op, $entity = NULL, $account = NULL, $entity_type) {
|
||||
$account = isset($account) ? $account : $GLOBALS['user'];
|
||||
// Grant access to the users own user account and to the anonymous one.
|
||||
if (isset($entity) && $op != 'delete' && (($entity->uid == $account->uid && $entity->uid) || (!$entity->uid && $op == 'view'))) {
|
||||
return TRUE;
|
||||
}
|
||||
if (user_access('administer users', $account) || user_access('access user profiles', $account) && $op == 'view' && $entity->status) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for restricted user properties.
|
||||
*/
|
||||
function entity_metadata_user_properties_access($op, $property, $entity = NULL, $account = NULL) {
|
||||
if (user_access('administer users', $account)) {
|
||||
return TRUE;
|
||||
}
|
||||
$account = isset($account) ? $account : $GLOBALS['user'];
|
||||
// Flag to indicate if this user entity is the own user account.
|
||||
$is_own_account = isset($entity) && $account->uid == $entity->uid;
|
||||
switch ($property) {
|
||||
case 'name':
|
||||
// Allow view access to anyone with access to the entity.
|
||||
if ($op == 'view') {
|
||||
return TRUE;
|
||||
}
|
||||
// Allow edit access for own user name if the permission is satisfied.
|
||||
return $is_own_account && user_access('change own username', $account);
|
||||
case 'mail':
|
||||
// Allow access to own mail address.
|
||||
return $is_own_account;
|
||||
case 'roles':
|
||||
// Allow view access for own roles.
|
||||
return ($op == 'view' && $is_own_account);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for the comment entity.
|
||||
*/
|
||||
function entity_metadata_comment_access($op, $entity = NULL, $account = NULL) {
|
||||
// When determining access to a comment, 'comment_access' does not take any
|
||||
// access restrictions to the comment's associated node into account. If a
|
||||
// comment has an associated node, the user must be able to view it in order
|
||||
// to access the comment.
|
||||
if (isset($entity->nid)) {
|
||||
if (!entity_access('view', 'node', node_load($entity->nid), $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (isset($entity) && $op == 'update') {
|
||||
// Because 'comment_access' only checks the current user, we need to do our
|
||||
// own access checking if an account was specified.
|
||||
if (!isset($account)) {
|
||||
return comment_access('edit', $entity);
|
||||
}
|
||||
else {
|
||||
return ($account->uid && $account->uid == $entity->uid && $entity->status == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account);
|
||||
}
|
||||
}
|
||||
if (user_access('administer comments', $account) || user_access('access comments', $account) && $op == 'view') {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for the taxonomy entities.
|
||||
*/
|
||||
function entity_metadata_taxonomy_access($op, $entity = NULL, $account = NULL, $entity_type) {
|
||||
if ($entity_type == 'taxonomy_vocabulary') {
|
||||
return user_access('administer taxonomy', $account);
|
||||
}
|
||||
if (isset($entity) && $op == 'update' && !isset($account) && taxonomy_term_edit_access($entity)) {
|
||||
return TRUE;
|
||||
}
|
||||
if (user_access('administer taxonomy', $account) || user_access('access content', $account) && $op == 'view') {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access callback for file entities.
|
||||
*/
|
||||
function entity_metadata_file_access($op, $file = NULL, $account = NULL, $entity_type) {
|
||||
// We can only check access for the current user, so return FALSE on other accounts.
|
||||
global $user;
|
||||
if ($op == 'view' && isset($file) && (!isset($account) || $user->uid == $account->uid)) {
|
||||
// Invoke hook_file_download() to obtain access information.
|
||||
foreach (module_implements('file_download') as $module) {
|
||||
$result = module_invoke($module, 'file_download', $file->uri);
|
||||
if ($result == -1) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback to determine access for properties which are fields.
|
||||
*/
|
||||
function entity_metadata_field_access_callback($op, $name, $entity = NULL, $account = NULL, $entity_type) {
|
||||
$field = field_info_field($name);
|
||||
return field_access($op, $field, $entity_type, $entity, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to create entity objects.
|
||||
*/
|
||||
function entity_metadata_create_object($values = array(), $entity_type) {
|
||||
$info = entity_get_info($entity_type);
|
||||
// Make sure at least the bundle and label properties are set.
|
||||
if (isset($info['entity keys']['bundle']) && $key = $info['entity keys']['bundle']) {
|
||||
$values += array($key => NULL);
|
||||
}
|
||||
if (isset($info['entity keys']['label']) && $key = $info['entity keys']['label']) {
|
||||
$values += array($key => NULL);
|
||||
}
|
||||
$entity = (object) $values;
|
||||
$entity->is_new = TRUE;
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to create a new comment.
|
||||
*/
|
||||
function entity_metadata_create_comment($values = array()) {
|
||||
$comment = (object) ($values + array(
|
||||
'status' => COMMENT_PUBLISHED,
|
||||
'pid' => 0,
|
||||
'subject' => '',
|
||||
'uid' => 0,
|
||||
'language' => LANGUAGE_NONE,
|
||||
'node_type' => NULL,
|
||||
'is_new' => TRUE,
|
||||
));
|
||||
$comment->cid = FALSE;
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to create a new node.
|
||||
*/
|
||||
function entity_metadata_create_node($values = array()) {
|
||||
$node = (object) array(
|
||||
'type' => $values['type'],
|
||||
'language' => LANGUAGE_NONE,
|
||||
'is_new' => TRUE,
|
||||
);
|
||||
// Set some defaults.
|
||||
$node_options = variable_get('node_options_' . $node->type, array('status', 'promote'));
|
||||
foreach (array('status', 'promote', 'sticky') as $key) {
|
||||
$node->$key = (int) in_array($key, $node_options);
|
||||
}
|
||||
if (module_exists('comment') && !isset($node->comment)) {
|
||||
$node->comment = variable_get("comment_$node->type", COMMENT_NODE_OPEN);
|
||||
}
|
||||
// Apply the given values.
|
||||
foreach ($values as $key => $value) {
|
||||
$node->$key = $value;
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to save a user account.
|
||||
*/
|
||||
function entity_metadata_user_save($account) {
|
||||
$edit = (array) $account;
|
||||
// Don't save the hashed password as password.
|
||||
unset($edit['pass']);
|
||||
user_save($account, $edit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to delete a file.
|
||||
* Watch out to not accidentilly implement hook_file_delete().
|
||||
*/
|
||||
function entity_metadata_delete_file($fid) {
|
||||
file_delete(file_load($fid), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to view nodes.
|
||||
*/
|
||||
function entity_metadata_view_node($entities, $view_mode = 'full', $langcode = NULL) {
|
||||
$result = node_view_multiple($entities, $view_mode, 0, $langcode);
|
||||
// Make sure to key the result with 'node' instead of 'nodes'.
|
||||
return array('node' => reset($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to view comments.
|
||||
*/
|
||||
function entity_metadata_view_comment($entities, $view_mode = 'full', $langcode = NULL) {
|
||||
$build = array();
|
||||
$nodes = array();
|
||||
// The comments, indexed by nid and then by cid.
|
||||
$nid_comments = array();
|
||||
foreach ($entities as $cid => $comment) {
|
||||
$nid = $comment->nid;
|
||||
$nodes[$nid] = $nid;
|
||||
$nid_comments[$nid][$cid] = $comment;
|
||||
}
|
||||
$nodes = node_load_multiple(array_keys($nodes));
|
||||
foreach ($nid_comments as $nid => $comments) {
|
||||
$node = isset($nodes[$nid]) ? $nodes[$nid] : NULL;
|
||||
$build += comment_view_multiple($comments, $node, $view_mode, 0, $langcode);
|
||||
}
|
||||
return array('comment' => $build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to view an entity, for which just ENTITYTYPE_view() is available.
|
||||
*/
|
||||
function entity_metadata_view_single($entities, $view_mode = 'full', $langcode = NULL, $entity_type) {
|
||||
$function = $entity_type . '_view';
|
||||
$build = array();
|
||||
foreach ($entities as $key => $entity) {
|
||||
$build[$entity_type][$key] = $function($entity, $view_mode, $langcode);
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form of a node.
|
||||
*/
|
||||
function entity_metadata_form_node($node) {
|
||||
// Pre-populate the form-state with the right form include.
|
||||
$form_state['build_info']['args'] = array($node);
|
||||
form_load_include($form_state, 'inc', 'node', 'node.pages');
|
||||
return drupal_build_form($node->type . '_node_form', $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form of a comment.
|
||||
*/
|
||||
function entity_metadata_form_comment($comment) {
|
||||
if (!isset($comment->node_type)) {
|
||||
$node = node_load($comment->nid);
|
||||
$comment->node_type = 'comment_node_' . $node->type;
|
||||
}
|
||||
return drupal_get_form($comment->node_type . '_form', $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form of a user account.
|
||||
*/
|
||||
function entity_metadata_form_user($account) {
|
||||
// Pre-populate the form-state with the right form include.
|
||||
$form_state['build_info']['args'] = array($account);
|
||||
form_load_include($form_state, 'inc', 'user', 'user.pages');
|
||||
return drupal_build_form('user_profile_form', $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form of a term.
|
||||
*/
|
||||
function entity_metadata_form_taxonomy_term($term) {
|
||||
// Pre-populate the form-state with the right form include.
|
||||
$form_state['build_info']['args'] = array($term);
|
||||
form_load_include($form_state, 'inc', 'taxonomy', 'taxonomy.admin');
|
||||
return drupal_build_form('taxonomy_form_term', $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form of a vocabulary.
|
||||
*/
|
||||
function entity_metadata_form_taxonomy_vocabulary($term) {
|
||||
// Pre-populate the form-state with the right form include.
|
||||
$form_state['build_info']['args'] = array($term);
|
||||
form_load_include($form_state, 'inc', 'taxonomy', 'taxonomy.admin');
|
||||
return drupal_build_form('taxonomy_form_term', $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to get the form for entities using the entity API admin ui.
|
||||
*/
|
||||
function entity_metadata_form_entity_ui($entity, $entity_type) {
|
||||
$info = entity_get_info($entity_type);
|
||||
$form_state = form_state_defaults();
|
||||
// Add in the include file as the form API does else with the include file
|
||||
// specified for the active menu item.
|
||||
if (!empty($info['admin ui']['file'])) {
|
||||
$path = isset($info['admin ui']['file path']) ? $info['admin ui']['file path'] : drupal_get_path('module', $info['module']);
|
||||
$form_state['build_info']['files']['entity_ui'] = $path . '/' . $info['admin ui']['file'];
|
||||
// Also load the include file.
|
||||
if (file_exists($form_state['build_info']['files']['entity_ui'])) {
|
||||
require_once DRUPAL_ROOT . '/' . $form_state['build_info']['files']['entity_ui'];
|
||||
}
|
||||
}
|
||||
return entity_ui_get_form($entity_type, $entity, $op = 'edit', $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for querying entity properties having their values stored in the
|
||||
* entities main db table.
|
||||
*/
|
||||
function entity_metadata_table_query($entity_type, $property, $value, $limit) {
|
||||
$properties = entity_get_all_property_info($entity_type);
|
||||
$info = $properties[$property] + array('schema field' => $property);
|
||||
|
||||
$query = new EntityFieldQuery();
|
||||
$query->entityCondition('entity_type', $entity_type, '=')
|
||||
->propertyCondition($info['schema field'], $value, is_array($value) ? 'IN' : '=')
|
||||
->range(0, $limit);
|
||||
|
||||
$result = $query->execute();
|
||||
return !empty($result[$entity_type]) ? array_keys($result[$entity_type]) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for querying entities by field values. This function just queries
|
||||
* for the value of the first specified column. Also it is only suitable for
|
||||
* fields that don't process the data, so it's stored the same way as returned.
|
||||
*/
|
||||
function entity_metadata_field_query($entity_type, $property, $value, $limit) {
|
||||
$query = new EntityFieldQuery();
|
||||
$field = field_info_field($property);
|
||||
$columns = array_keys($field['columns']);
|
||||
|
||||
$query->entityCondition('entity_type', $entity_type, '=')
|
||||
->fieldCondition($field, $columns[0], $value, is_array($value) ? 'IN' : '=')
|
||||
->range(0, $limit);
|
||||
|
||||
$result = $query->execute();
|
||||
return !empty($result[$entity_type]) ? array_keys($result[$entity_type]) : array();
|
||||
}
|
164
sites/all/modules/contrib/dev/entity/modules/comment.info.inc
Normal file
164
sites/all/modules/contrib/dev/entity/modules/comment.info.inc
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about the comment entity.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of comment module.
|
||||
*
|
||||
* @see entity_entity_property_info()
|
||||
*/
|
||||
function entity_metadata_comment_entity_property_info() {
|
||||
$info = array();
|
||||
// Add meta-data about the basic comment properties.
|
||||
$properties = &$info['comment']['properties'];
|
||||
|
||||
$properties['cid'] = array(
|
||||
'label' => t("Comment ID"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The unique ID of the comment."),
|
||||
'schema field' => 'cid',
|
||||
);
|
||||
$properties['hostname'] = array(
|
||||
'label' => t("IP Address"),
|
||||
'description' => t("The IP address of the computer the comment was posted from."),
|
||||
'schema field' => 'hostname',
|
||||
);
|
||||
$properties['name'] = array(
|
||||
'label' => t("Name"),
|
||||
'description' => t("The name left by the comment author."),
|
||||
'getter callback' => 'entity_metadata_comment_get_properties',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'sanitize' => 'filter_xss',
|
||||
'schema field' => 'name',
|
||||
);
|
||||
$properties['mail'] = array(
|
||||
'label' => t("Email address"),
|
||||
'description' => t("The email address left by the comment author."),
|
||||
'getter callback' => 'entity_metadata_comment_get_properties',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'validation callback' => 'valid_email_address',
|
||||
'schema field' => 'mail',
|
||||
);
|
||||
$properties['homepage'] = array(
|
||||
'label' => t("Home page"),
|
||||
'description' => t("The home page URL left by the comment author."),
|
||||
'sanitize' => 'filter_xss_bad_protocol',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'schema field' => 'homepage',
|
||||
);
|
||||
$properties['subject'] = array(
|
||||
'label' => t("Subject"),
|
||||
'description' => t("The subject of the comment."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'sanitize' => 'filter_xss',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'subject',
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The URL of the comment."),
|
||||
'getter callback' => 'entity_metadata_entity_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['edit_url'] = array(
|
||||
'label' => t("Edit URL"),
|
||||
'description' => t("The URL of the comment's edit page."),
|
||||
'getter callback' => 'entity_metadata_comment_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['created'] = array(
|
||||
'label' => t("Date created"),
|
||||
'description' => t("The date the comment was posted."),
|
||||
'type' => 'date',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'schema field' => 'created',
|
||||
);
|
||||
$properties['parent'] = array(
|
||||
'label' => t("Parent"),
|
||||
'description' => t("The comment's parent, if comment threading is active."),
|
||||
'type' => 'comment',
|
||||
'getter callback' => 'entity_metadata_comment_get_properties',
|
||||
'schema field' => 'pid',
|
||||
);
|
||||
$properties['node'] = array(
|
||||
'label' => t("Node"),
|
||||
'description' => t("The node the comment was posted to."),
|
||||
'type' => 'node',
|
||||
'setter callback' => 'entity_metadata_comment_setter',
|
||||
'setter permission' => 'administer comments',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'nid',
|
||||
);
|
||||
$properties['author'] = array(
|
||||
'label' => t("Author"),
|
||||
'description' => t("The author of the comment."),
|
||||
'type' => 'user',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'uid',
|
||||
);
|
||||
$properties['status'] = array(
|
||||
'label' => t("Status"),
|
||||
'description' => t("Whether the comment is published or unpublished."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
// Although the status is expected to be boolean, its schema suggests
|
||||
// it is an integer, so we follow the schema definition.
|
||||
'type' => 'integer',
|
||||
'options list' => 'entity_metadata_status_options_list',
|
||||
'setter permission' => 'administer comments',
|
||||
'schema field' => 'status',
|
||||
);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of comment module.
|
||||
* @see entity_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_comment_entity_property_info_alter(&$info) {
|
||||
// Add info about comment module related properties to the node entity.
|
||||
$properties = &$info['node']['properties'];
|
||||
$properties['comment'] = array(
|
||||
'label' => t("Comments allowed"),
|
||||
'description' => t("Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write)."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer comments',
|
||||
'type' => 'integer',
|
||||
);
|
||||
$properties['comment_count'] = array(
|
||||
'label' => t("Comment count"),
|
||||
'description' => t("The number of comments posted on a node."),
|
||||
'getter callback' => 'entity_metadata_comment_get_node_properties',
|
||||
'type' => 'integer',
|
||||
);
|
||||
$properties['comment_count_new'] = array(
|
||||
'label' => t("New comment count"),
|
||||
'description' => t("The number of comments posted on a node since the reader last viewed it."),
|
||||
'getter callback' => 'entity_metadata_comment_get_node_properties',
|
||||
'type' => 'integer',
|
||||
);
|
||||
|
||||
// The comment body field is usually available for all bundles, so add it
|
||||
// directly to the comment entity.
|
||||
$info['comment']['properties']['comment_body'] = array(
|
||||
'type' => 'text_formatted',
|
||||
'label' => t('The main body text'),
|
||||
'getter callback' => 'entity_metadata_field_verbatim_get',
|
||||
'setter callback' => 'entity_metadata_field_verbatim_set',
|
||||
'property info' => entity_property_text_formatted_info(),
|
||||
'field' => TRUE,
|
||||
'required' => TRUE,
|
||||
);
|
||||
unset($info['comment']['properties']['comment_body']['property info']['summary']);
|
||||
}
|
170
sites/all/modules/contrib/dev/entity/modules/field.info.inc
Normal file
170
sites/all/modules/contrib/dev/entity/modules/field.info.inc
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info for fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of field module.
|
||||
*
|
||||
* @see entity_field_info_alter()
|
||||
* @see entity_entity_property_info()
|
||||
*/
|
||||
function entity_metadata_field_entity_property_info() {
|
||||
$info = array();
|
||||
// Loop over all field instances and add them as property.
|
||||
foreach (field_info_fields() as $field_name => $field) {
|
||||
$field += array('bundles' => array());
|
||||
if ($field_type = field_info_field_types($field['type'])) {
|
||||
// Add in our default callback as the first one.
|
||||
$field_type += array('property_callbacks' => array());
|
||||
array_unshift($field_type['property_callbacks'], 'entity_metadata_field_default_property_callback');
|
||||
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle) {
|
||||
$instance = field_info_instance($entity_type, $field_name, $bundle);
|
||||
|
||||
if ($instance && empty($instance['deleted'])) {
|
||||
foreach ($field_type['property_callbacks'] as $callback) {
|
||||
$callback($info, $entity_type, $field, $instance, $field_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to add in property info defaults per field instance.
|
||||
* @see entity_metadata_field_entity_property_info().
|
||||
*/
|
||||
function entity_metadata_field_default_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
if (!empty($field_type['property_type'])) {
|
||||
if ($field['cardinality'] != 1) {
|
||||
$field_type['property_type'] = 'list<' . $field_type['property_type'] . '>';
|
||||
}
|
||||
// Add in instance specific property info, if given and apply defaults.
|
||||
$name = $field['field_name'];
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
|
||||
$instance += array('property info' => array());
|
||||
$property = $instance['property info'] + array(
|
||||
'label' => $instance['label'],
|
||||
'type' => $field_type['property_type'],
|
||||
'description' => t('Field "@name".', array('@name' => $name)),
|
||||
'getter callback' => 'entity_metadata_field_property_get',
|
||||
'setter callback' => 'entity_metadata_field_property_set',
|
||||
'access callback' => 'entity_metadata_field_access_callback',
|
||||
'query callback' => 'entity_metadata_field_query',
|
||||
'translatable' => !empty($field['translatable']),
|
||||
// Specify that this property stems from a field.
|
||||
'field' => TRUE,
|
||||
'required' => !empty($instance['required']),
|
||||
);
|
||||
// For field types of the list module add in the options list callback.
|
||||
if (strpos($field['type'], 'list') === 0) {
|
||||
$property['options list'] = 'entity_metadata_field_options_list';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callback to adapt the property info for text fields. If a text
|
||||
* field is processed we make use of a separate data structure so that format
|
||||
* filters are available too. For the text value the sanitized, thus processed
|
||||
* value is returned by default.
|
||||
*
|
||||
* @see entity_metadata_field_entity_property_info()
|
||||
* @see entity_field_info_alter()
|
||||
* @see entity_property_text_formatted_info()
|
||||
*/
|
||||
function entity_metadata_field_text_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
if (!empty($instance['settings']['text_processing']) || $field['type'] == 'text_with_summary') {
|
||||
// Define a data structure for dealing with text that is formatted or has
|
||||
// a summary.
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
|
||||
|
||||
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
|
||||
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
|
||||
unset($property['query callback']);
|
||||
|
||||
if (empty($instance['settings']['text_processing'])) {
|
||||
$property['property info'] = entity_property_field_item_textsummary_info();
|
||||
}
|
||||
else {
|
||||
// For formatted text we use the type name 'text_formatted'.
|
||||
$property['type'] = ($field['cardinality'] != 1) ? 'list<text_formatted>' : 'text_formatted';
|
||||
$property['property info'] = entity_property_text_formatted_info();
|
||||
}
|
||||
// Enable auto-creation of the item, so that it is possible to just set
|
||||
// the textual or summary value.
|
||||
$property['auto creation'] = 'entity_property_create_array';
|
||||
|
||||
if ($field['type'] != 'text_with_summary') {
|
||||
unset($property['property info']['summary']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callback to adapt the property info for term reference fields.
|
||||
* @see entity_metadata_field_entity_property_info().
|
||||
*/
|
||||
function entity_metadata_field_term_reference_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
|
||||
if (count($field['settings']['allowed_values']) == 1) {
|
||||
$settings = reset($field['settings']['allowed_values']);
|
||||
$property['bundle'] = $settings['vocabulary'];
|
||||
}
|
||||
// Only add the options list callback for controlled vocabularies, thus
|
||||
// vocabularies not using the autocomplete widget.
|
||||
if ($instance['widget']['type'] != 'taxonomy_autocomplete') {
|
||||
$property['options list'] = 'entity_metadata_field_options_list';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callback to adapt the property info for file fields.
|
||||
* @see entity_metadata_field_entity_property_info().
|
||||
*/
|
||||
function entity_metadata_field_file_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
|
||||
// Define a data structure so it's possible to deal with files and their
|
||||
// descriptions.
|
||||
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
|
||||
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
|
||||
|
||||
// Auto-create the field $items as soon as a property is set.
|
||||
$property['auto creation'] = 'entity_metadata_field_file_create_item';
|
||||
$property['validation callback'] = 'entity_metadata_field_file_validate_item';
|
||||
|
||||
$property['property info'] = entity_property_field_item_file_info();
|
||||
|
||||
if (empty($instance['settings']['description_field'])) {
|
||||
unset($property['property info']['description']);
|
||||
}
|
||||
if (empty($field['settings']['display_field'])) {
|
||||
unset($property['property info']['display']);
|
||||
}
|
||||
unset($property['query callback']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callback to adapt the property info for image fields.
|
||||
* This callback gets invoked after entity_metadata_field_file_callback().
|
||||
* @see entity_metadata_field_entity_property_info().
|
||||
*/
|
||||
function entity_metadata_field_image_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
|
||||
// Update the property info with the info for image fields.
|
||||
$property['property info'] = entity_property_field_item_image_info();
|
||||
|
||||
if (empty($instance['settings']['alt_field'])) {
|
||||
unset($property['property info']['alt']);
|
||||
}
|
||||
if (empty($field['settings']['title_field'])) {
|
||||
unset($property['property info']['title']);
|
||||
}
|
||||
}
|
40
sites/all/modules/contrib/dev/entity/modules/locale.info.inc
Normal file
40
sites/all/modules/contrib/dev/entity/modules/locale.info.inc
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides locale-related properties.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of locale module.
|
||||
*
|
||||
* @see entity_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_locale_entity_property_info_alter(&$info) {
|
||||
|
||||
$info['user']['properties']['language'] = array(
|
||||
'label' => t("Language"),
|
||||
'description' => t("This account's default language for e-mails, and preferred language for site presentation."),
|
||||
'type' => 'token',
|
||||
'getter callback' => 'entity_metadata_locale_get_user_language',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'options list' => 'entity_metadata_language_list',
|
||||
'schema field' => 'language',
|
||||
'setter permission' => 'administer users',
|
||||
);
|
||||
|
||||
$info['site']['properties']['current_page']['property info']['language'] = array(
|
||||
'label' => t("Interface language"),
|
||||
'description' => t("The language code of the current user interface language."),
|
||||
'type' => 'token',
|
||||
'getter callback' => 'entity_metadata_locale_get_languages',
|
||||
'options list' => 'entity_metadata_language_list',
|
||||
);
|
||||
$info['site']['properties']['current_page']['property info']['language_content'] = array(
|
||||
'label' => t("Content language"),
|
||||
'description' => t("The language code of the current content language."),
|
||||
'type' => 'token',
|
||||
'getter callback' => 'entity_metadata_locale_get_languages',
|
||||
'options list' => 'entity_metadata_language_list',
|
||||
);
|
||||
}
|
165
sites/all/modules/contrib/dev/entity/modules/node.info.inc
Normal file
165
sites/all/modules/contrib/dev/entity/modules/node.info.inc
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about the node entity.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of node module.
|
||||
*
|
||||
* @see entity_entity_property_info()
|
||||
*/
|
||||
function entity_metadata_node_entity_property_info() {
|
||||
$info = array();
|
||||
// Add meta-data about the basic node properties.
|
||||
$properties = &$info['node']['properties'];
|
||||
|
||||
$properties['nid'] = array(
|
||||
'label' => t("Node ID"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The unique ID of the node."),
|
||||
'schema field' => 'nid',
|
||||
);
|
||||
$properties['vid'] = array(
|
||||
'label' => t("Revision ID"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The unique ID of the node's revision."),
|
||||
'schema field' => 'vid',
|
||||
);
|
||||
$properties['is_new'] = array(
|
||||
'label' => t("Is new"),
|
||||
'type' => 'boolean',
|
||||
'description' => t("Whether the node is new and not saved to the database yet."),
|
||||
'getter callback' => 'entity_metadata_node_get_properties',
|
||||
);
|
||||
$properties['type'] = array(
|
||||
'label' => t("Content type"),
|
||||
'type' => 'token',
|
||||
'description' => t("The type of the node."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'options list' => 'node_type_get_names',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'type',
|
||||
);
|
||||
$properties['title'] = array(
|
||||
'label' => t("Title"),
|
||||
'description' => t("The title of the node."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'schema field' => 'title',
|
||||
'required' => TRUE,
|
||||
);
|
||||
$properties['language'] = array(
|
||||
'label' => t("Language"),
|
||||
'type' => 'token',
|
||||
'description' => t("The language the node is written in."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'options list' => 'entity_metadata_language_list',
|
||||
'schema field' => 'language',
|
||||
'setter permission' => 'administer nodes',
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The URL of the node."),
|
||||
'getter callback' => 'entity_metadata_entity_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['edit_url'] = array(
|
||||
'label' => t("Edit URL"),
|
||||
'description' => t("The URL of the node's edit page."),
|
||||
'getter callback' => 'entity_metadata_node_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['status'] = array(
|
||||
'label' => t("Status"),
|
||||
'description' => t("Whether the node is published or unpublished."),
|
||||
// Although the status is expected to be boolean, its schema suggests
|
||||
// it is an integer, so we follow the schema definition.
|
||||
'type' => 'integer',
|
||||
'options list' => 'entity_metadata_status_options_list',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'schema field' => 'status',
|
||||
);
|
||||
$properties['promote'] = array(
|
||||
'label' => t("Promoted to frontpage"),
|
||||
'description' => t("Whether the node is promoted to the frontpage."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'schema field' => 'promote',
|
||||
'type' => 'boolean',
|
||||
);
|
||||
$properties['sticky'] = array(
|
||||
'label' => t("Sticky in lists"),
|
||||
'description' => t("Whether the node is displayed at the top of lists in which it appears."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'schema field' => 'sticky',
|
||||
'type' => 'boolean',
|
||||
);
|
||||
$properties['created'] = array(
|
||||
'label' => t("Date created"),
|
||||
'type' => 'date',
|
||||
'description' => t("The date the node was posted."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'schema field' => 'created',
|
||||
);
|
||||
$properties['changed'] = array(
|
||||
'label' => t("Date changed"),
|
||||
'type' => 'date',
|
||||
'schema field' => 'changed',
|
||||
'description' => t("The date the node was most recently updated."),
|
||||
);
|
||||
$properties['author'] = array(
|
||||
'label' => t("Author"),
|
||||
'type' => 'user',
|
||||
'description' => t("The author of the node."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'setter permission' => 'administer nodes',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'uid',
|
||||
);
|
||||
$properties['source'] = array(
|
||||
'label' => t("Translation source node"),
|
||||
'type' => 'node',
|
||||
'description' => t("The original-language version of this node, if one exists."),
|
||||
'getter callback' => 'entity_metadata_node_get_properties',
|
||||
);
|
||||
$properties['log'] = array(
|
||||
'label' => t("Revision log message"),
|
||||
'type' => 'text',
|
||||
'description' => t("In case a new revision is to be saved, the log entry explaining the changes for this version."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'access callback' => 'entity_metadata_node_revision_access',
|
||||
);
|
||||
$properties['revision'] = array(
|
||||
'label' => t("Creates revision"),
|
||||
'type' => 'boolean',
|
||||
'description' => t("Whether saving this node creates a new revision."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'access callback' => 'entity_metadata_node_revision_access',
|
||||
);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of node module.
|
||||
* @see entity_metadata_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_node_entity_property_info_alter(&$info) {
|
||||
// Move the body property to the node by default, as its usually there this
|
||||
// makes dealing with it more convenient.
|
||||
$info['node']['properties']['body'] = array(
|
||||
'type' => 'text_formatted',
|
||||
'label' => t('The main body text'),
|
||||
'getter callback' => 'entity_metadata_field_verbatim_get',
|
||||
'setter callback' => 'entity_metadata_field_verbatim_set',
|
||||
'property info' => entity_property_text_formatted_info(),
|
||||
'auto creation' => 'entity_property_create_array',
|
||||
'field' => TRUE,
|
||||
);
|
||||
}
|
50
sites/all/modules/contrib/dev/entity/modules/poll.info.inc
Normal file
50
sites/all/modules/contrib/dev/entity/modules/poll.info.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about poll nodes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of poll module.
|
||||
*
|
||||
* @see entity_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_poll_entity_property_info_alter(&$info) {
|
||||
$properties = &$info['node']['bundles']['poll']['properties'];
|
||||
|
||||
$properties['poll_votes'] = array(
|
||||
'label' => t("Poll votes"),
|
||||
'description' => t("The number of votes that have been cast on a poll node."),
|
||||
'type' => 'integer',
|
||||
'getter callback' => 'entity_metadata_poll_node_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['poll_winner'] = array(
|
||||
'label' => t("Poll winner"),
|
||||
'description' => t("The winning poll answer."),
|
||||
'getter callback' => 'entity_metadata_poll_node_get_properties',
|
||||
'sanitize' => 'filter_xss',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['poll_winner_votes'] = array(
|
||||
'label' => t("Poll winner votes"),
|
||||
'description' => t("The number of votes received by the winning poll answer."),
|
||||
'type' => 'integer',
|
||||
'getter callback' => 'entity_metadata_poll_node_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['poll_winner_percent'] = array(
|
||||
'label' => t("Poll winner percent"),
|
||||
'description' => t("The percentage of votes received by the winning poll answer."),
|
||||
'getter callback' => 'entity_metadata_poll_node_get_properties',
|
||||
'type' => 'decimal',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['poll_duration'] = array(
|
||||
'label' => t("Poll duration"),
|
||||
'description' => t("The length of time the poll node is set to run."),
|
||||
'getter callback' => 'entity_metadata_poll_node_get_properties',
|
||||
'type' => 'duration',
|
||||
);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about statistics.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info_alter() on top of statistics module.
|
||||
*
|
||||
* @see entity_entity_property_info_alter()
|
||||
*/
|
||||
function entity_metadata_statistics_entity_property_info_alter(&$info) {
|
||||
$properties = &$info['node']['properties'];
|
||||
|
||||
$properties['views'] = array(
|
||||
'label' => t("Number of views"),
|
||||
'description' => t("The number of visitors who have read the node."),
|
||||
'type' => 'integer',
|
||||
'getter callback' => 'entity_metadata_statistics_node_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['day_views'] = array(
|
||||
'label' => t("Views today"),
|
||||
'description' => t("The number of visitors who have read the node today."),
|
||||
'type' => 'integer',
|
||||
'getter callback' => 'entity_metadata_statistics_node_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['last_view'] = array(
|
||||
'label' => t("Last view"),
|
||||
'description' => t("The date on which a visitor last read the node."),
|
||||
'type' => 'date',
|
||||
'getter callback' => 'entity_metadata_statistics_node_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
}
|
132
sites/all/modules/contrib/dev/entity/modules/system.info.inc
Normal file
132
sites/all/modules/contrib/dev/entity/modules/system.info.inc
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about system-wide entities.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of system module.
|
||||
*
|
||||
* @see entity_entity_property_info()
|
||||
* @see entity_metadata_site_wrapper()
|
||||
*/
|
||||
function entity_metadata_system_entity_property_info() {
|
||||
$info = array();
|
||||
|
||||
// There is no site entity, but still add metadata for global site properties
|
||||
// here. That way modules can alter and add further properties at this place.
|
||||
// In order to make use of this metadata modules may use the wrapper returned
|
||||
// by entity_metadata_site_wrapper().
|
||||
$properties = &$info['site']['properties'];
|
||||
$properties['name'] = array(
|
||||
'label' => t("Name"),
|
||||
'description' => t("The name of the site."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'sanitize' => 'check_plain',
|
||||
);
|
||||
$properties['slogan'] = array(
|
||||
'label' => t("Slogan"),
|
||||
'description' => t("The slogan of the site."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'sanitize' => 'check_plain',
|
||||
);
|
||||
$properties['mail'] = array(
|
||||
'label' => t("Email"),
|
||||
'description' => t("The administrative email address for the site."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The URL of the site's front page."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'type' => 'uri',
|
||||
);
|
||||
$properties['login_url'] = array(
|
||||
'label' => t("Login page"),
|
||||
'description' => t("The URL of the site's login page."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'type' => 'uri',
|
||||
);
|
||||
$properties['current_user'] = array(
|
||||
'label' => t("Logged in user"),
|
||||
'description' => t("The currently logged in user."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'type' => 'user',
|
||||
);
|
||||
$properties['current_date'] = array(
|
||||
'label' => t("Current date"),
|
||||
'description' => t("The current date and time."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'type' => 'date',
|
||||
);
|
||||
$properties['current_page'] = array(
|
||||
'label' => t("Current page"),
|
||||
'description' => t("Information related to the current page request."),
|
||||
'getter callback' => 'entity_metadata_system_get_properties',
|
||||
'type' => 'struct',
|
||||
'property info' => array(
|
||||
'path' => array(
|
||||
'label' => t("Path"),
|
||||
'description' => t("The internal Drupal path of the current page request."),
|
||||
'getter callback' => 'current_path',
|
||||
'type' => 'text',
|
||||
),
|
||||
'url' => array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The full URL of the current page request."),
|
||||
'getter callback' => 'entity_metadata_system_get_page_properties',
|
||||
'type' => 'uri',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Files.
|
||||
$properties = &$info['file']['properties'];
|
||||
$properties['fid'] = array(
|
||||
'label' => t("File ID"),
|
||||
'description' => t("The unique ID of the uploaded file."),
|
||||
'type' => 'integer',
|
||||
'validation callback' => 'entity_metadata_validate_integer_positive',
|
||||
'schema field' => 'fid',
|
||||
);
|
||||
$properties['name'] = array(
|
||||
'label' => t("File name"),
|
||||
'description' => t("The name of the file on disk."),
|
||||
'getter callback' => 'entity_metadata_system_get_file_properties',
|
||||
'schema field' => 'filename',
|
||||
);
|
||||
$properties['mime'] = array(
|
||||
'label' => t("MIME type"),
|
||||
'description' => t("The MIME type of the file."),
|
||||
'getter callback' => 'entity_metadata_system_get_file_properties',
|
||||
'sanitize' => 'filter_xss',
|
||||
'schema field' => 'filemime',
|
||||
);
|
||||
$properties['size'] = array(
|
||||
'label' => t("File size"),
|
||||
'description' => t("The size of the file, in kilobytes."),
|
||||
'getter callback' => 'entity_metadata_system_get_file_properties',
|
||||
'type' => 'integer',
|
||||
'schema field' => 'filesize',
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The web-accessible URL for the file."),
|
||||
'getter callback' => 'entity_metadata_system_get_file_properties',
|
||||
);
|
||||
$properties['timestamp'] = array(
|
||||
'label' => t("Timestamp"),
|
||||
'description' => t("The date the file was most recently changed."),
|
||||
'type' => 'date',
|
||||
'schema field' => 'timestamp',
|
||||
);
|
||||
$properties['owner'] = array(
|
||||
'label' => t("Owner"),
|
||||
'description' => t("The user who originally uploaded the file."),
|
||||
'type' => 'user',
|
||||
'getter callback' => 'entity_metadata_system_get_file_properties',
|
||||
'schema field' => 'uid',
|
||||
);
|
||||
return $info;
|
||||
}
|
124
sites/all/modules/contrib/dev/entity/modules/taxonomy.info.inc
Normal file
124
sites/all/modules/contrib/dev/entity/modules/taxonomy.info.inc
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about the taxonomy entity.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of taxonomy module.
|
||||
*
|
||||
* @see entity_entity_property_info()
|
||||
*/
|
||||
function entity_metadata_taxonomy_entity_property_info() {
|
||||
$info = array();
|
||||
// Add meta-data about the basic taxonomy properties.
|
||||
$properties = &$info['taxonomy_term']['properties'];
|
||||
|
||||
$properties['tid'] = array(
|
||||
'label' => t("Term ID"),
|
||||
'description' => t("The unique ID of the taxonomy term."),
|
||||
'type' => 'integer',
|
||||
'schema field' => 'tid',
|
||||
);
|
||||
$properties['name'] = array(
|
||||
'label' => t("Name"),
|
||||
'description' => t("The name of the taxonomy term."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'name',
|
||||
);
|
||||
$properties['description'] = array(
|
||||
'label' => t("Description"),
|
||||
'description' => t("The optional description of the taxonomy term."),
|
||||
'sanitized' => TRUE,
|
||||
'raw getter callback' => 'entity_property_verbatim_get',
|
||||
'getter callback' => 'entity_metadata_taxonomy_term_get_properties',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'schema field' => 'description',
|
||||
);
|
||||
$properties['weight'] = array(
|
||||
'label' => t("Weight"),
|
||||
'type' => 'integer',
|
||||
'description' => t('The weight of the term, which is used for ordering terms during display.'),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'schema field' => 'weight',
|
||||
);
|
||||
$properties['node_count'] = array(
|
||||
'label' => t("Node count"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The number of nodes tagged with the taxonomy term."),
|
||||
'getter callback' => 'entity_metadata_taxonomy_term_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The URL of the taxonomy term."),
|
||||
'getter callback' => 'entity_metadata_entity_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['vocabulary'] = array(
|
||||
'label' => t("Vocabulary"),
|
||||
'description' => t("The vocabulary the taxonomy term belongs to."),
|
||||
'setter callback' => 'entity_metadata_taxonomy_term_setter',
|
||||
'type' => 'taxonomy_vocabulary',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'vid',
|
||||
);
|
||||
$properties['parent'] = array(
|
||||
'label' => t("Parent terms"),
|
||||
'description' => t("The parent terms of the taxonomy term."),
|
||||
'getter callback' => 'entity_metadata_taxonomy_term_get_properties',
|
||||
'setter callback' => 'entity_metadata_taxonomy_term_setter',
|
||||
'type' => 'list<taxonomy_term>',
|
||||
);
|
||||
$properties['parents_all'] = array(
|
||||
'label' => t("All parent terms"),
|
||||
'description' => t("Ancestors of the term, i.e. parent of all above hierarchy levels."),
|
||||
'getter callback' => 'entity_metadata_taxonomy_term_get_properties',
|
||||
'type' => 'list<taxonomy_term>',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
|
||||
// Add meta-data about the basic vocabulary properties.
|
||||
$properties = &$info['taxonomy_vocabulary']['properties'];
|
||||
|
||||
// Taxonomy vocabulary related variables.
|
||||
$properties['vid'] = array(
|
||||
'label' => t("Vocabulary ID"),
|
||||
'description' => t("The unique ID of the taxonomy vocabulary."),
|
||||
'type' => 'integer',
|
||||
'schema field' => 'vid',
|
||||
);
|
||||
$properties['name'] = array(
|
||||
'label' => t("Name"),
|
||||
'description' => t("The name of the taxonomy vocabulary."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'name',
|
||||
);
|
||||
$properties['machine_name'] = array(
|
||||
'label' => t("Machine name"),
|
||||
'type' => 'token',
|
||||
'description' => t("The machine name of the taxonomy vocabulary."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'required' => TRUE,
|
||||
'schema field' => 'machine_name',
|
||||
);
|
||||
$properties['description'] = array(
|
||||
'label' => t("Description"),
|
||||
'description' => t("The optional description of the taxonomy vocabulary."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'sanitize' => 'filter_xss',
|
||||
'schema field' => 'description',
|
||||
);
|
||||
$properties['term_count'] = array(
|
||||
'label' => t("Term count"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The number of terms belonging to the taxonomy vocabulary."),
|
||||
'getter callback' => 'entity_metadata_taxonomy_vocabulary_get_properties',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
return $info;
|
||||
}
|
108
sites/all/modules/contrib/dev/entity/modules/user.info.inc
Normal file
108
sites/all/modules/contrib/dev/entity/modules/user.info.inc
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides info about the user entity.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_property_info() on top of user module.
|
||||
*
|
||||
* @see entity_entity_property_info()
|
||||
*/
|
||||
function entity_metadata_user_entity_property_info() {
|
||||
$info = array();
|
||||
// Add meta-data about the user properties.
|
||||
$properties = &$info['user']['properties'];
|
||||
|
||||
$properties['uid'] = array(
|
||||
'label' => t("User ID"),
|
||||
'type' => 'integer',
|
||||
'description' => t("The unique ID of the user account."),
|
||||
'schema field' => 'uid',
|
||||
);
|
||||
$properties['name'] = array(
|
||||
'label' => t("Name"),
|
||||
'description' => t("The login name of the user account."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'sanitize' => 'filter_xss',
|
||||
'required' => TRUE,
|
||||
'access callback' => 'entity_metadata_user_properties_access',
|
||||
'schema field' => 'name',
|
||||
);
|
||||
$properties['mail'] = array(
|
||||
'label' => t("Email"),
|
||||
'description' => t("The email address of the user account."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'validation callback' => 'valid_email_address',
|
||||
'required' => TRUE,
|
||||
'access callback' => 'entity_metadata_user_properties_access',
|
||||
'schema field' => 'mail',
|
||||
);
|
||||
$properties['url'] = array(
|
||||
'label' => t("URL"),
|
||||
'description' => t("The URL of the account profile page."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['edit_url'] = array(
|
||||
'label' => t("Edit URL"),
|
||||
'description' => t("The url of the account edit page."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'type' => 'uri',
|
||||
'computed' => TRUE,
|
||||
);
|
||||
$properties['last_access'] = array(
|
||||
'label' => t("Last access"),
|
||||
'description' => t("The date the user last accessed the site."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'type' => 'date',
|
||||
'schema field' => 'access',
|
||||
);
|
||||
$properties['last_login'] = array(
|
||||
'label' => t("Last login"),
|
||||
'description' => t("The date the user last logged in to the site."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'type' => 'date',
|
||||
'schema field' => 'login',
|
||||
);
|
||||
$properties['created'] = array(
|
||||
'label' => t("Created"),
|
||||
'description' => t("The date the user account was created."),
|
||||
'type' => 'date',
|
||||
'schema field' => 'created',
|
||||
);
|
||||
$properties['roles'] = array(
|
||||
'label' => t("User roles"),
|
||||
'description' => t("The roles of the user."),
|
||||
'type' => 'list<integer>',
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'setter callback' => 'entity_metadata_user_set_properties',
|
||||
'setter permission' => 'administer users',
|
||||
'options list' => 'entity_metadata_user_roles',
|
||||
'access callback' => 'entity_metadata_user_properties_access',
|
||||
);
|
||||
$properties['status'] = array(
|
||||
'label' => t("Status"),
|
||||
'description' => t("Whether the user is active or blocked."),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
// Although the status is expected to be boolean, its schema suggests
|
||||
// it is an integer, so we follow the schema definition.
|
||||
'type' => 'integer',
|
||||
'options list' => 'entity_metadata_user_status_options_list',
|
||||
'setter permission' => 'administer users',
|
||||
'schema field' => 'status',
|
||||
);
|
||||
$properties['theme'] = array(
|
||||
'label' => t("Default theme"),
|
||||
'description' => t("The user's default theme."),
|
||||
'getter callback' => 'entity_metadata_user_get_properties',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
'access callback' => 'entity_metadata_user_properties_access',
|
||||
'schema field' => 'theme',
|
||||
);
|
||||
return $info;
|
||||
}
|
||||
|
Reference in New Issue
Block a user