Skip to content

Commit

Permalink
Update Entity API to 7.x-1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hunt committed Dec 14, 2021
1 parent 512ad64 commit 13a8bbf
Show file tree
Hide file tree
Showing 46 changed files with 584 additions and 321 deletions.
2 changes: 1 addition & 1 deletion docroot/sites/all/modules/contrib/entity/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ developing, you may stop reading now.
To see how to provide a separate class have a look at the "EntityClass" from
the "entity_test.module".

* Implement hook_entity_info() for your entity. At least specifiy the
* Implement hook_entity_info() for your entity. At least specify the
controller class (EntityAPIController, EntityAPIControllerExportable or your
own), your db table and your entity's keys.
Again just look at "entity_test.module"'s hook_entity_info() for guidance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $plugin = array(
'defaults' => array(
'selector' => '',
'target_context' => 'entity',
'concatenator' => ','
'concatenator' => ',',
),
);

Expand Down Expand Up @@ -90,7 +90,7 @@ function entity_entity_property_edit_form($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Data selector'),
'#description' => t('Any valid data selector, e.g. "title" to select a node\'s title, or "field_tags:1" to select the second tag.'),
'#default_value' => $conf['selector'],
'#default_value' => $conf['selector'],
'#required' => TRUE,
);
$form['concatenator'] = array(
Expand All @@ -116,7 +116,7 @@ function entity_entity_property_edit_form_validate($form, &$form_state) {
$parts = explode(':', $form_state['values']['selector']);
foreach ($parts as $part) {
if (!($wrapper instanceof EntityStructureWrapper || $wrapper instanceof EntityListWrapper)) {
form_set_error('selector', t('Unable to apply the data selector part %key.'. array('%key' => $part)));
form_set_error('selector', t('Unable to apply the data selector part %key.', array('%key' => $part)));
continue;
}
$wrapper = $wrapper->get($part);
Expand All @@ -142,7 +142,7 @@ function entity_entity_property_map_data_type($type) {
while ($item_type = entity_property_list_extract_type($type)) {
$type = $item_type;
}
// Massage data type of entites to c
// Massage data type of entities to ctools type.
if (entity_get_info($type)) {
$type = "entity:$type";
}
Expand Down
106 changes: 98 additions & 8 deletions docroot/sites/all/modules/contrib/entity/entity.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@
* In case the 'admin ui' is used, no callback needs to be specified.
* - entity cache: (optional) Whether entities should be cached using the cache
* system. Requires the entitycache module to be installed and enabled and the
* module key to be specified. As cached entities are only retrieved by id key,
* the cache would not apply to exportable entities retrieved by name key.
* If enabled and the entitycache module is active, 'field cache' is obsolete
* and is automatically disabled. Defaults to FALSE.
* module key to be specified. As cached entities are only retrieved by id
* key, the cache would not apply to exportable entities retrieved by name
* key. If enabled and the entitycache module is active, 'field cache' is
* obsolete and is automatically disabled. Defaults to FALSE.
*
* @see hook_entity_info()
* @see entity_metadata_hook_entity_info()
Expand Down Expand Up @@ -256,7 +256,7 @@ function entity_metadata_hook_entity_info() {
* by entity_metadata_wrapper().
* For providing property information for fields see entity_hook_field_info().
*
* @return
* @return array
* An array whose keys are entity type names and whose values are arrays
* containing the keys:
* - properties: The array describing all properties for this entity. Entries
Expand Down Expand Up @@ -380,9 +380,9 @@ function entity_metadata_hook_entity_info() {
* with an array of info about the bundle specific properties, structured in
* the same way as the entity properties array.
*
* @see hook_entity_property_info_alter()
* @see entity_get_property_info()
* @see entity_metadata_wrapper()
* @see hook_entity_property_info_alter()
* @see entity_get_property_info()
* @see entity_metadata_wrapper()
*/
function hook_entity_property_info() {
$info = array();
Expand Down Expand Up @@ -462,6 +462,96 @@ function hook_entity_views_field_handlers_alter(array &$field_handlers) {
$field_handlers['node'] = 'example_node_handler';
}

/**
* Act after default entities have been rebuilt.
*
* This hook is invoked after default entities have been fully saved to the
* database, but with the lock still active.
*
* @param array $entities
* An array of the entities that have been saved, keyed by name.
* @param array $originals
* An array of the original copies of the entities that have been saved,
* keyed by name.
*
* @see _entity_defaults_rebuild()
*/
function hook_ENTITY_TYPE_defaults_rebuild($entities, $originals) {

}

/**
* Act on an entity before it is about to be created or updated.
*
* @param $entity
* The entity object.
*
* @see hook_entity_presave()
*/
function hook_ENTITY_TYPE_presave($entity) {
$entity->changed = REQUEST_TIME;
}

/**
* Act on entities when inserted.
*
* @param $entity
* The entity object.
*
* @see hook_entity_insert()
*/
function hook_ENTITY_TYPE_insert($entity) {
// Insert the new entity into a fictional table of all entities.
list($id) = entity_extract_ids($type, $entity);
db_insert('example_entity')
->fields(array(
'type' => $type,
'id' => $id,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
}

/**
* Act on entities when updated.
*
* @param $entity
* The entity object.
*
* @see hook_entity_update()
*/
function hook_ENTITY_TYPE_update($entity) {
// Update the entity's entry in a fictional table of all entities.
$info = entity_get_info($type);
list($id) = entity_extract_ids($type, $entity);
db_update('example_entity')
->fields(array(
'updated' => REQUEST_TIME,
))
->condition('type', $type)
->condition('id', $id)
->execute();
}

/**
* Act on entities when deleted.
*
* @param $entity
* The entity object.
*
* @see hook_entity_delete()
*/
function hook_ENTITY_TYPE_delete($entity) {
// Delete the entity's entry from a fictional table of all entities.
$info = entity_get_info($type);
list($id) = entity_extract_ids($type, $entity);
db_delete('example_entity')
->condition('type', $type)
->condition('id', $id)
->execute();
}

/**
* @} End of "addtogroup hooks".
*/
17 changes: 9 additions & 8 deletions docroot/sites/all/modules/contrib/entity/entity.features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EntityDefaultFeaturesController {
else {
$export['features'][$this->type][$name] = $name;

// If this is a bundle of a fieldable entity, add its fields to the pipe.
// If this is a bundle of a fieldable entity add its fields to the pipe.
if (!empty($this->info['bundle of'])) {
$fields = field_info_instances($this->info['bundle of'], $entity->{$this->bundleKey});
foreach ($fields as $name => $field) {
Expand All @@ -110,11 +110,11 @@ class EntityDefaultFeaturesController {
/**
* Generates the result for hook_features_export_render().
*/
function export_render($module, $data, $export = NULL) {
public function export_render($module, $data, $export = NULL) {
$output = array();
$output[] = ' $items = array();';
foreach (entity_load_multiple_by_name($this->type, $data) as $name => $entity) {
$export = " \$items['$name'] = entity_import('{$this->type}', '";
$export = " \$items['$name'] = entity_import('{$this->type}', '";
// Make sure to escape the characters \ and '.
$export .= addcslashes(entity_export($this->type, $entity, ' '), '\\\'');
$export .= "');";
Expand All @@ -130,15 +130,16 @@ class EntityDefaultFeaturesController {
/**
* Generates the result for hook_features_revert().
*/
function revert($module = NULL) {
public function revert($module = NULL) {
if ($defaults = features_get_default($this->type, $module)) {
entity_delete_multiple($this->type, array_keys($defaults));
}
}

}

/**
* Implements of hook_features_api().
* Implements hook_features_api().
*/
function entity_features_api() {
$items = array();
Expand Down Expand Up @@ -168,7 +169,7 @@ function entity_features_export_options($a1, $a2 = NULL) {
*
* Features component callback.
*/
function entity_features_export($data, &$export, $module_name = '', $entity_type) {
function entity_features_export($data, &$export, $module_name, $entity_type) {
return entity_features_get_controller($entity_type)->export($data, $export, $module_name);
}

Expand All @@ -177,7 +178,7 @@ function entity_features_export($data, &$export, $module_name = '', $entity_type
*
* Features component callback.
*/
function entity_features_export_render($module, $data, $export = NULL, $entity_type) {
function entity_features_export_render($module, $data, $export, $entity_type) {
return entity_features_get_controller($entity_type)->export_render($module, $data, $export);
}

Expand All @@ -186,7 +187,7 @@ function entity_features_export_render($module, $data, $export = NULL, $entity_t
*
* Features component callback.
*/
function entity_features_revert($module = NULL, $entity_type) {
function entity_features_revert($module, $entity_type) {
return entity_features_get_controller($entity_type)->revert($module);
}

Expand Down
2 changes: 2 additions & 0 deletions docroot/sites/all/modules/contrib/entity/entity.i18n.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file
* Internationalization (i18n) integration.
Expand Down Expand Up @@ -207,4 +208,5 @@ class EntityDefaultI18nStringController {
public function hook_string_objects() {
return entity_load_multiple_by_name($this->entityType, FALSE);
}

}
17 changes: 12 additions & 5 deletions docroot/sites/all/modules/contrib/entity/entity.info
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name = Entity API
description = Enables modules to work with any entity type and to provide entities.
test_dependencies[] = rules:rules
test_dependencies[] = i18n:i18n_string
core = 7.x

files[] = entity.features.inc
files[] = entity.i18n.inc
files[] = entity.info.inc
files[] = entity.rules.inc
files[] = entity.test
files[] = includes/entity.inc
files[] = includes/entity.controller.inc
files[] = includes/entity.ui.inc
files[] = includes/entity.wrapper.inc

; Test cases
files[] = entity.test

; Views handlers
files[] = views/entity.views.inc
files[] = views/handlers/entity_views_field_handler_helper.inc
files[] = views/handlers/entity_views_handler_area_entity.inc
Expand All @@ -25,9 +32,9 @@ files[] = views/handlers/entity_views_handler_field_uri.inc
files[] = views/handlers/entity_views_handler_relationship_by_bundle.inc
files[] = views/handlers/entity_views_handler_relationship.inc
files[] = views/plugins/entity_views_plugin_row_entity_view.inc
; Information added by Drupal.org packaging script on 2018-02-14
version = "7.x-1.9"

; Information added by Drupal.org packaging script on 2021-11-20
version = "7.x-1.10"
core = "7.x"
project = "entity"
datestamp = "1518620551"

datestamp = "1637434458"
10 changes: 8 additions & 2 deletions docroot/sites/all/modules/contrib/entity/entity.info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ class EntityDefaultMetadataController {
protected function convertSchema() {
return entity_metadata_convert_schema($this->info['base table']);
}

}

/**
* Converts the schema information available for the given table to property info.
*
* @param $table
* The name of the table as used in hook_schema().
* @return
*
* @return array
* An array of property info as suiting for hook_entity_property_info().
*/
function entity_metadata_convert_schema($table) {
Expand Down Expand Up @@ -171,9 +173,11 @@ function _entity_metadata_convert_schema_type($type) {
case 'serial':
case 'date':
return 'integer';

case 'float':
case 'numeric':
return 'decimal';

case 'char':
case 'varchar':
case 'text':
Expand All @@ -192,9 +196,10 @@ interface EntityExtraFieldsControllerInterface {
/**
* Returns extra fields for this entity type.
*
* @see hook_field_extra_fields().
* @see hook_field_extra_fields()
*/
public function fieldExtraFields();

}

/**
Expand Down Expand Up @@ -262,4 +267,5 @@ class EntityDefaultExtraFieldsController implements EntityExtraFieldsControllerI
}
return $info;
}

}
4 changes: 2 additions & 2 deletions docroot/sites/all/modules/contrib/entity/entity.install
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ function entity_entitycache_uninstalled_modules($modules = NULL) {
*/
function _entity_entitycache_get_module_info($modules) {
// Prepare a keyed array of all modules with their entity types and infos.
// Structure: [module][entity][info]
// Structure: [module][entity][info].
$entity_crud_info = entity_crud_get_info();
$info = array();
foreach ($entity_crud_info as $entity_name => $entity_info) {
// Make sure that the entity info specifies a module and supports entitycache.
// Make sure that entity_info specifies a module and supports entitycache.
if (!isset($entity_info['module']) || empty($entity_info['entity cache'])) {
continue;
}
Expand Down
Loading

0 comments on commit 13a8bbf

Please sign in to comment.