diff --git a/core/modules/comment/comment.entity.inc b/core/modules/comment/comment.entity.inc index a89d383..62a23d9 100644 --- a/core/modules/comment/comment.entity.inc +++ b/core/modules/comment/comment.entity.inc @@ -6,7 +6,7 @@ */ /** - * Entity class for comments. + * Defines the comment entity class. */ class Comment extends Entity { @@ -49,7 +49,7 @@ class Comment extends Entity { /** * The comment author's name. * - * In case of anonymous authors the value as typed in the comment form. + * For anonymous authors, this is the value as typed in the comment form. * * @var string */ @@ -58,7 +58,7 @@ class Comment extends Entity { /** * The comment author's e-mail address. * - * In case of anonymous authors the value as typed in the comment form. + * For anonymous authors, this is the value as typed in the comment form. * * @var string */ @@ -67,7 +67,7 @@ class Comment extends Entity { /** * The comment author's home page address. * - * In case of anonymous authors the value as typed in the comment form. + * For anonymous authors, this is the value as typed in the comment form. * * @var string */ @@ -76,13 +76,16 @@ class Comment extends Entity { } /** - * Controller class for comments. + * Defines the controller class for comments. * * This extends the EntityDatabaseStorageController class, adding required * special handling for comment entities. */ class CommentStorageController extends EntityDatabaseStorageController { + /** + * Overrides EntityDatabaseStorageController::buildQuery(). + */ protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) { $query = parent::buildQuery($ids, $conditions, $revision_id); // Specify additional fields from the user and node tables. @@ -94,6 +97,9 @@ class CommentStorageController extends EntityDatabaseStorageController { return $query; } + /** + * Overrides EntityDatabaseStorageController::attachLoad(). + */ protected function attachLoad(&$comments, $revision_id = FALSE) { // Setup standard comment properties. foreach ($comments as $key => $comment) { @@ -106,6 +112,8 @@ class CommentStorageController extends EntityDatabaseStorageController { } /** + * Overrides EntityDatabaseStorageController::preSave(). + * * @see comment_int_to_alphadecimal() */ protected function preSave(EntityInterface $comment) { @@ -179,6 +187,9 @@ class CommentStorageController extends EntityDatabaseStorageController { } } + /** + * Overrides EntityDatabaseStorageController::postSave(). + */ protected function postSave(EntityInterface $comment) { // Update the {node_comment_statistics} table prior to executing the hook. $this->updateNodeStatistics($comment->nid); @@ -188,6 +199,9 @@ class CommentStorageController extends EntityDatabaseStorageController { } } + /** + * Overrides EntityDatabaseStorageController::postDelete(). + */ protected function postDelete($comments) { // Delete the comments' replies. $query = db_select('comment', 'c') @@ -212,6 +226,9 @@ class CommentStorageController extends EntityDatabaseStorageController { * node or the node authors uid if no comments exists for the node. * - comment_count: the total number of approved/published comments on this * node. + * + * @param $nid + * The node ID. */ protected function updateNodeStatistics($nid) { // Allow bulk updates and inserts to temporarily disable the diff --git a/core/modules/entity/entity.class.inc b/core/modules/entity/entity.class.inc index 5459b29..2c98143 100644 --- a/core/modules/entity/entity.class.inc +++ b/core/modules/entity/entity.class.inc @@ -6,32 +6,36 @@ */ /** - * Interface for all entity objects. + * Defines a common interface for all entity objects. */ interface EntityInterface { /** - * Creates a new entity object. + * Constructs a new entity object. * * @param $values - * An array of values to set, keyed by property name. If the entity type has - * bundles the bundle key has to be specified. + * An array of values to set, keyed by property name. If the entity type + * has bundles, the bundle key has to be specified. * @param $entity_type * The type of the entity to create. */ public function __construct(array $values, $entity_type); /** - * Returns the entity identifier, i.e. the entities machine name or numeric ID. + * Returns the entity identifier (the entity's machine name or numeric ID). * * @return - * The identifier of the entity. In case the entity has no identifier yet, - * it returns NULL. + * The identifier of the entity, or NULL if the entity does not yet have + * an identifier. */ public function id(); /** - * Returns whether the entity is new; i.e. whether it has been already saved. + * Returns whether the entity is new. + * + * @return + * TRUE if the entity is new, or FALSE if the entity has already been + * saved. */ public function isNew(); @@ -61,12 +65,12 @@ interface EntityInterface { public function label(); /** - * Returns the uri elements of the entity. + * Returns the URI elements of the entity. * * @return - * An array containing the 'path' and 'options' keys used to build the uri + * An array containing the 'path' and 'options' keys used to build the URI * of the entity, and matching the signature of url(). NULL if the entity - * has no uri of its own. + * has no URI of its own. */ public function uri(); @@ -76,14 +80,14 @@ interface EntityInterface { * @param $property_name * The name of the property to return; e.g., 'title'. * @param $language - * (optional) In case the property is translatable, the language object of - * the language that should be used for getting the property. If set to - * NULL, the default language is being used. + * (optional) If the property is translatable, the language object of the + * language that should be used for getting the property. If set to NULL, + * the default language is being used. * @todo * Which default language should be used. * * @return - * The property value, or NULL in case it is not defined. + * The property value, or NULL if it is not defined. */ public function get($property_name, $language = NULL); @@ -95,8 +99,8 @@ interface EntityInterface { * @param $value * The value to set, or NULL to unset the property. * @param $language - * (optional) In case the property is translatable, the language object of - * the language that should be used for getting the property. If set to + * (optional) If the property is translatable, the language object of the + * language that should be used for getting the property. If set to * NULL, the default language is being used. * @todo * Which default language should be used. @@ -110,8 +114,7 @@ interface EntityInterface { * In case of failures an exception is thrown. * * @return - * Either SAVED_NEW or SAVED_UPDATED is returned, depending on the operation - * performed. + * Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed. */ public function save(); @@ -145,12 +148,14 @@ interface EntityInterface { } /** - * Exception thrown when storage operations fail. + * Defines an exception thrown when storage operations fail. */ class EntityStorageException extends Exception { } /** - * A class implementing the EntityInterface. + * Defines a base entity class. + * + * Default implementation of EntityInterface. * * This class can be used as-is by simple entity types. Entity types requiring * special handling can extend the class. @@ -165,27 +170,29 @@ class Entity implements EntityInterface { protected $entityType; /** - * Info about the entity's type. + * Information about the entity's type. * * @var array */ protected $entityInfo; /** - * The ID entity key. + * The entity ID key. * * @var string */ protected $idKey; /** - * The bundle entity key. + * The entity bundle key. * * @var string */ protected $bundleKey; - + /** + * Constructs a new entity object. + */ public function __construct(array $values = array(), $entity_type) { $this->entityType = $entity_type; $this->setUp(); @@ -196,7 +203,7 @@ class Entity implements EntityInterface { } /** - * Set up the object instance on construction or unserializiation. + * Sets up the object instance on construction or unserializiation. */ protected function setUp() { $this->entityInfo = entity_get_info($this->entityType); @@ -204,26 +211,42 @@ class Entity implements EntityInterface { $this->bundleKey = isset($this->entityInfo['entity keys']['bundle']) ? $this->entityInfo['entity keys']['bundle'] : NULL; } + /** + * Implements EntityInterface::id(). + */ public function id() { return isset($this->{$this->idKey}) ? $this->{$this->idKey} : NULL; } + /** + * Implements EntityInterface::isNew(). + */ public function isNew() { // We support creating entities with pre-defined ids to ease migrations. // For that the "is_new" property may be set to TRUE. return !empty($this->is_new) || empty($this->{$this->idKey}); } + /** + * Implements EntityInterface::entityType(). + */ public function entityType() { return $this->entityType; } + /** + * Implements EntityInterface::bundle(). + */ public function bundle() { return isset($this->bundleKey) ? $this->{$this->bundleKey} : $this->entityType; } + /** + * Implements EntityInterface::label(). + * + * @see entity_label() + */ public function label() { - // @see entity_label() $label = FALSE; if (isset($this->entityInfo['label callback']) && function_exists($this->entityInfo['label callback'])) { $label = $this->entityInfo['label callback']($this->entityType, $this); @@ -234,8 +257,12 @@ class Entity implements EntityInterface { return $label; } + /** + * Implements EntityInterface::uri(). + * + * @see entity_uri() + */ public function uri() { - // @see entity_uri() $bundle = $this->bundle(); // A bundle-specific callback takes precedence over the generic one for the // entity type. @@ -261,6 +288,8 @@ class Entity implements EntityInterface { } /** + * Implements EntityInterface::get(). + * * @todo * Implement default handling of language. */ @@ -273,6 +302,8 @@ class Entity implements EntityInterface { } /** + * Implements EntityInterface::set(). + * * @todo * Implement default handling of language. */ @@ -285,28 +316,42 @@ class Entity implements EntityInterface { } } + /** + * Implements EntityInterface::save(). + */ public function save() { return entity_get_controller($this->entityType)->save($this); } + /** + * Implements EntityInterface::delete(). + */ public function delete() { if (!$this->isNew()) { entity_get_controller($this->entityType)->delete(array($this->id())); } } + /** + * Implements EntityInterface::createDuplicate(). + */ public function createDuplicate() { $duplicate = clone $this; $duplicate->{$this->idKey} = NULL; return $duplicate; } + /** + * Implements EntityInterface::entityInfo(). + */ public function entityInfo() { return $this->entityInfo; } /** - * Magic method to only serialize what is necessary. + * Serializes only what is necessary. + * + * See @link http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep PHP Magic Methods @endlink. */ public function __sleep() { $vars = get_object_vars($this); @@ -317,7 +362,9 @@ class Entity implements EntityInterface { } /** - * Magic method to invoke setUp() on unserialization. + * Invokes setUp() on unserialization. + * + * See @link http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep PHP Magic Methods @endlink */ public function __wakeup() { $this->setUp(); diff --git a/core/modules/entity/entity.controller.inc b/core/modules/entity/entity.controller.inc index 29474a6..2498ab4 100644 --- a/core/modules/entity/entity.controller.inc +++ b/core/modules/entity/entity.controller.inc @@ -6,7 +6,7 @@ */ /** - * Interface for entity controller classes. + * Defines a common interface for entity controller classes. * * All entity controller classes specified via the 'controller class' key * returned by hook_entity_info() or hook_entity_info_alter() have to implement @@ -19,7 +19,7 @@ interface DrupalEntityControllerInterface { /** - * Constructor. + * Constructs a new DrupalEntityControllerInterface object. * * @param $entityType * The entity type for which the instance is created. @@ -50,6 +50,8 @@ interface DrupalEntityControllerInterface { } /** + * Defines a base entity controller class. + * * Default implementation of DrupalEntityControllerInterface. * * This class can be used as-is by most simple entity types. Entity types @@ -122,7 +124,9 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { protected $cache; /** - * Constructor: sets basic variables. + * Implements DrupalEntityControllerInterface::__construct(). + * + * Sets basic variables. */ public function __construct($entityType) { $this->entityType = $entityType; @@ -395,7 +399,7 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface { } /** - * Interface for entity storage controllers. + * Defines a common interface for entity storage controllers. */ interface EntityStorageControllerInterface extends DrupalEntityControllerInterface { @@ -426,12 +430,12 @@ interface EntityStorageControllerInterface extends DrupalEntityControllerInterfa } /** - * A controller implementing EntityAPIStorageControllerInterface for the database. + * Implements the entity storage controller interface for the database. */ class EntityDatabaseStorageController extends DrupalDefaultEntityController implements EntityStorageControllerInterface { /** - * Implements EntityStorageControllerInterface. + * Implements EntityStorageControllerInterface::delete(). */ public function delete($ids) { $entities = $ids ? $this->load($ids) : FALSE; @@ -468,7 +472,7 @@ class EntityDatabaseStorageController extends DrupalDefaultEntityController impl } /** - * Implements EntityStorageControllerInterface. + * Implements EntityStorageControllerInterface::save(). */ public function save(EntityInterface $entity) { $transaction = db_transaction(); @@ -510,22 +514,31 @@ class EntityDatabaseStorageController extends DrupalDefaultEntityController impl } /** - * Act on an entity before the presave hook is invoked. + * Acts on an entity before the presave hook is invoked. + * + * Used before the entity is saved and before invoking the presave hook. */ protected function preSave(EntityInterface $entity) { } /** - * Act on an entity when inserted or updated before the respective hook is invoked. + * Acts on a saved entity before the insert or update hook is invoked. + * + * Used after the entity is saved, but before invoking the insert or update + * hook. */ protected function postSave(EntityInterface $entity) { } /** - * Act on entities before they are deleted. + * Acts on entities before they are deleted. + * + * Used before the entities are deleted and before invoking the delete hook. */ protected function preDelete($entities) { } /** - * Act on entities when deleted before the delete hook is invoked. + * Acts on deleted entities before the delete hook is invoked. + * + * Used after the entities are deleted but before invoking the delete hook. */ protected function postDelete($entities) { } diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index 26efe06..4ac83ff 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -257,7 +257,7 @@ function entity_load_unchanged($entity_type, $id) { } /** - * Permanently delete multiple entities. + * Deletes multiple entities permanently. * * @param $entity_type * The type of the entity. @@ -269,7 +269,7 @@ function entity_delete_multiple($entity_type, $ids) { } /** - * Construct a new entity object, without saving it to the database. + * Constructs a new entity object, without saving it to the database. * * @param $entity_type * The type of the entity. diff --git a/core/modules/entity/tests/entity.test b/core/modules/entity/tests/entity.test index c435541..3733c93 100644 --- a/core/modules/entity/tests/entity.test +++ b/core/modules/entity/tests/entity.test @@ -6,7 +6,7 @@ */ /** - * Test basic API. + * Tests the basic Entity API. */ class EntityAPITestCase extends DrupalWebTestCase { @@ -23,7 +23,7 @@ class EntityAPITestCase extends DrupalWebTestCase { } /** - * Tests basic CRUD functionality of the entity API. + * Tests basic CRUD functionality of the Entity API. */ function testCRUD() { $user1 = $this->drupalCreateUser(); diff --git a/core/modules/entity/tests/entity_test.module b/core/modules/entity/tests/entity_test.module index 39e2752..4d34232 100644 --- a/core/modules/entity/tests/entity_test.module +++ b/core/modules/entity/tests/entity_test.module @@ -25,7 +25,7 @@ function entity_test_entity_info() { } /** - * Load a test-entity. + * Loads a test-entity. * * @param $id * A test-entity ID.