Mercurial > hg > cmmr2012-drupal-site
diff core/modules/comment/src/Entity/Comment.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/core/modules/comment/src/Entity/Comment.php Thu Feb 28 13:11:55 2019 +0000 +++ b/core/modules/comment/src/Entity/Comment.php Thu May 09 15:34:47 2019 +0100 @@ -13,7 +13,7 @@ use Drupal\Core\Field\BaseFieldDefinition; use Drupal\field\Entity\FieldStorageConfig; use Drupal\user\Entity\User; -use Drupal\user\UserInterface; +use Drupal\user\EntityOwnerTrait; /** * Defines the comment entity class. @@ -52,6 +52,7 @@ * "langcode" = "langcode", * "uuid" = "uuid", * "published" = "status", + * "owner" = "uid", * }, * links = { * "canonical" = "/comment/{comment}", @@ -70,6 +71,7 @@ class Comment extends ContentEntityBase implements CommentInterface { use EntityChangedTrait; + use EntityOwnerTrait; use EntityPublishedTrait; /** @@ -209,7 +211,7 @@ * {@inheritdoc} */ public function permalink() { - $uri = $this->urlInfo(); + $uri = $this->toUrl(); $uri->setOption('fragment', 'comment-' . $this->id()); return $uri; } @@ -221,6 +223,7 @@ /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ $fields = parent::baseFieldDefinitions($entity_type); $fields += static::publishedBaseFieldDefinitions($entity_type); + $fields += static::ownerBaseFieldDefinitions($entity_type); $fields['cid']->setLabel(t('Comment ID')) ->setDescription(t('The comment ID.')); @@ -256,12 +259,8 @@ ]) ->setDisplayConfigurable('form', TRUE); - $fields['uid'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('User ID')) - ->setDescription(t('The user ID of the comment author.')) - ->setTranslatable(TRUE) - ->setSetting('target_type', 'user') - ->setDefaultValue(0); + $fields['uid'] + ->setDescription(t('The user ID of the comment author.')); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) @@ -307,12 +306,14 @@ $fields['entity_type'] = BaseFieldDefinition::create('string') ->setLabel(t('Entity type')) + ->setRequired(TRUE) ->setDescription(t('The entity type to which this comment is attached.')) ->setSetting('is_ascii', TRUE) ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH); $fields['field_name'] = BaseFieldDefinition::create('string') ->setLabel(t('Comment field name')) + ->setRequired(TRUE) ->setDescription(t('The field name through which this comment was added.')) ->setSetting('is_ascii', TRUE) ->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH); @@ -323,6 +324,13 @@ /** * {@inheritdoc} */ + public static function getDefaultEntityOwner() { + return 0; + } + + /** + * {@inheritdoc} + */ public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { if ($comment_type = CommentType::load($bundle)) { $fields['entity_id'] = clone $base_field_definitions['entity_id']; @@ -525,29 +533,6 @@ } /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('uid')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('uid', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('uid', $account->id()); - return $this; - } - - /** * Get the comment type ID for this comment. * * @return string @@ -576,7 +561,10 @@ * The client host name. */ public static function getDefaultHostname() { - return \Drupal::request()->getClientIP(); + if (\Drupal::config('comment.settings')->get('log_ip_addresses')) { + return \Drupal::request()->getClientIP(); + } + return ''; } }