comparison core/modules/comment/src/Entity/Comment.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 7a779792577d
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
54 * "published" = "status", 54 * "published" = "status",
55 * }, 55 * },
56 * links = { 56 * links = {
57 * "canonical" = "/comment/{comment}", 57 * "canonical" = "/comment/{comment}",
58 * "delete-form" = "/comment/{comment}/delete", 58 * "delete-form" = "/comment/{comment}/delete",
59 * "delete-multiple-form" = "/admin/content/comment/delete",
59 * "edit-form" = "/comment/{comment}/edit", 60 * "edit-form" = "/comment/{comment}/edit",
60 * "create" = "/comment", 61 * "create" = "/comment",
61 * }, 62 * },
62 * bundle_entity_type = "comment_type", 63 * bundle_entity_type = "comment_type",
63 * field_ui_base_route = "entity.comment_type.edit_form", 64 * field_ui_base_route = "entity.comment_type.edit_form",
140 $lock_name = "comment:{$this->getCommentedEntityId()}:$thread"; 141 $lock_name = "comment:{$this->getCommentedEntityId()}:$thread";
141 } while (!\Drupal::lock()->acquire($lock_name)); 142 } while (!\Drupal::lock()->acquire($lock_name));
142 $this->threadLock = $lock_name; 143 $this->threadLock = $lock_name;
143 } 144 }
144 $this->setThread($thread); 145 $this->setThread($thread);
145 if (!$this->getHostname()) {
146 // Ensure a client host from the current request.
147 $this->setHostname(\Drupal::request()->getClientIP());
148 }
149 } 146 }
150 // The entity fields for name and mail have no meaning if the user is not 147 // The entity fields for name and mail have no meaning if the user is not
151 // Anonymous. Set them to NULL to make it clearer that they are not used. 148 // Anonymous. Set them to NULL to make it clearer that they are not used.
152 // For anonymous users see \Drupal\comment\CommentForm::form() for mail, 149 // For anonymous users see \Drupal\comment\CommentForm::form() for mail,
153 // and \Drupal\comment\CommentForm::buildEntity() for name setting. 150 // and \Drupal\comment\CommentForm::buildEntity() for name setting.
288 285
289 $fields['hostname'] = BaseFieldDefinition::create('string') 286 $fields['hostname'] = BaseFieldDefinition::create('string')
290 ->setLabel(t('Hostname')) 287 ->setLabel(t('Hostname'))
291 ->setDescription(t("The comment author's hostname.")) 288 ->setDescription(t("The comment author's hostname."))
292 ->setTranslatable(TRUE) 289 ->setTranslatable(TRUE)
293 ->setSetting('max_length', 128); 290 ->setSetting('max_length', 128)
291 ->setDefaultValueCallback(static::class . '::getDefaultHostname');
294 292
295 $fields['created'] = BaseFieldDefinition::create('created') 293 $fields['created'] = BaseFieldDefinition::create('created')
296 ->setLabel(t('Created')) 294 ->setLabel(t('Created'))
297 ->setDescription(t('The time that the comment was created.')) 295 ->setDescription(t('The time that the comment was created.'))
298 ->setTranslatable(TRUE); 296 ->setTranslatable(TRUE);
569 */ 567 */
570 public static function getDefaultStatus() { 568 public static function getDefaultStatus() {
571 return \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED; 569 return \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED;
572 } 570 }
573 571
572 /**
573 * Returns the default value for entity hostname base field.
574 *
575 * @return string
576 * The client host name.
577 */
578 public static function getDefaultHostname() {
579 return \Drupal::request()->getClientIP();
580 }
581
574 } 582 }