commit 81a4869e5fa96ea18d458802d2b628ed42b27e26 Author: Lee Rowlands Date: Mon May 19 16:55:40 2014 +1000 Fixes diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 30f300e..e35bead 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -77,7 +77,6 @@ function comment_schema() { 'comment_type' => array( 'type' => 'varchar', 'not null' => TRUE, - 'default' => 'comment', 'length' => 32, 'description' => 'The comment_type of this comment.', ), @@ -158,8 +157,8 @@ function comment_schema() { 'comment_status_pid' => array('pid', 'status'), 'comment_num_new' => array( 'entity_id', - array('entity_type', 32), - array('comment_type', 32), + 'entity_type', + 'comment_type', 'status', 'created', 'cid', @@ -168,8 +167,8 @@ function comment_schema() { 'comment_uid' => array('uid'), 'comment_entity_langcode' => array( 'entity_id', - array('entity_type', 32), - array('comment_type', 32), + 'entity_type', + 'comment_type', 'langcode', ), 'comment_created' => array('created'), @@ -243,7 +242,7 @@ function comment_schema() { 'description' => 'The total number of comments on this entity.', ), ), - 'primary key' => array('entity_id', array('entity_type', 32), array('field_name', 32)), + 'primary key' => array('entity_id', 'entity_type', array('field_name', 32)), 'indexes' => array( 'last_comment_timestamp' => array('last_comment_timestamp'), 'comment_count' => array('comment_count'), diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index f57219d..bcc482d 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -18,6 +18,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; use Drupal\Core\Url; +use Drupal\field\Entity\FieldConfig; use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface; use Drupal\file\FileInterface; @@ -549,7 +550,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie */ function comment_add(EntityInterface $entity, $field_name = 'comment', $pid = NULL) { /** @var \Drupal\field\FieldConfigInterface $field */ - $field = entity_load('field_config', $entity->getEntityTypeId() . '.' . $field_name); + $field = Fieldconfig::loadByName($entity->getEntityTypeId(), $field_name); $values = array( 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 05e0cd1..8d9c39e 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -351,7 +351,7 @@ function comment_views_data() { $data['comment']['comment_type'] = array( 'title' => t('Comment type'), - 'help' => t('The comment type from which the comment originated.'), + 'help' => t('The comment type for this comment.'), 'field' => array( 'id' => 'standard', ), diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index 01f8a99..9af4c0e 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -249,4 +249,12 @@ public function setThread($thread); */ public function permalink(); + /** + * Get the comment type id for this comment. + * + * @return string + * The id of the comment type. + */ + public function getTypeId(); + } diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 51dbb80..cbe33a2 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -16,6 +16,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\field\Entity\FieldConfig; /** * Comment manager contains common functions to manage comment fields. @@ -106,7 +107,7 @@ public function getAllFields() { public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment') { $comment_type_storage = $this->entityManager->getStorage('comment_type'); if ($comment_type = $comment_type_storage->load($comment_type_id)) { - if ($comment_type->targetEntityTypeId !== $entity_type) { + if ($comment_type->getTargetEntityTypeId() !== $entity_type) { throw new \InvalidArgumentException($this->t('The given comment type id %id can only be used with the %entity_type entity type', array( '%id' => $comment_type_id, '%entity_type' => $entity_type, @@ -114,6 +115,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', } } else { + // Silently create the comment-type for the calling code. $comment_type_storage->create(array( 'id' => $comment_type_id, 'label' => $comment_type_id, @@ -122,7 +124,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', ))->save(); } // Make sure the field doesn't already exist. - if (!$this->entityManager->getStorage('field_config')->load($entity_type . '.' . $field_name)) { + if (!FieldConfig::loadByName($entity_type, $field_name)) { // Add a default comment field for existing node comments. $field = $this->entityManager->getStorage('field_config')->create(array( 'entity_type' => $entity_type, diff --git a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php index d50c955..8797065 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php @@ -48,13 +48,14 @@ public function getAllFields(); * @param string $bundle * The bundle to attach the default comment field instance to. * @param string $field_name - * (optional) Field name to use for the comment field. Defaults to 'comment'. + * (optional) Field name to use for the comment field. Defaults to + * 'comment'. * @param int $default_value * (optional) Default value, one of CommentItemInterface::HIDDEN, * CommentItemInterface::OPEN, CommentItemInterface::CLOSED. Defaults to * CommentItemInterface::OPEN. * @param string $comment_type_id - * ID of comment type to use. + * (optional) ID of comment type to use. Defaults to 'comment'. */ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentTypeFormController.php b/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php similarity index 96% rename from core/modules/comment/lib/Drupal/comment/CommentTypeFormController.php rename to core/modules/comment/lib/Drupal/comment/CommentTypeForm.php index 0d93b0e..0915384 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentTypeFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\comment\CommentTypeFormController. + * Contains \Drupal\comment\CommentTypeForm. */ namespace Drupal\comment; @@ -16,7 +16,7 @@ /** * Base form controller for category edit forms. */ -class CommentTypeFormController extends EntityForm implements ContainerInjectionInterface { +class CommentTypeForm extends EntityForm implements ContainerInjectionInterface { /** * Entity manager service. diff --git a/core/modules/comment/lib/Drupal/comment/CommentTypeListBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentTypeListBuilder.php index d347a71..faadcdc 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentTypeListBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentTypeListBuilder.php @@ -88,11 +88,4 @@ public function buildRow(EntityInterface $entity) { return $row + parent::buildRow($entity); } - /** - * {@inheritdoc} - */ - protected function getTitle() { - return $this->t('Comment types'); - } - } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 944d2fe..33e5fef 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -300,10 +300,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { */ public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { if ($entity_type->id() == 'comment') { - $comment_type = entity_load('comment_type', $bundle); - $fields['entity_id'] = clone $base_field_definitions['entity_id']; - $fields['entity_id']->setSetting('target_type', $comment_type->targetEntityTypeId); - return $fields; + if ($comment_type = entity_load('comment_type', $bundle)) { + $fields['entity_id'] = clone $base_field_definitions['entity_id']; + $fields['entity_id']->setSetting('target_type', $comment_type->getTargetEntityTypeId()); + return $fields; + } + return array(); } } @@ -530,4 +532,14 @@ public function setOwner(UserInterface $account) { return $this; } + /** + * Get the comment type id for this comment. + * + * @return string + * The id of the comment type. + */ + public function getTypeId() { + return $this->bundle(); + } + } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php b/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php index 887fbce..600e78c 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php @@ -7,7 +7,7 @@ namespace Drupal\comment\Entity; -use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\comment\CommentTypeInterface; @@ -19,9 +19,9 @@ * label = @Translation("Comment type"), * controllers = { * "form" = { - * "default" = "Drupal\comment\CommentTypeFormController", - * "add" = "Drupal\comment\CommentTypeFormController", - * "edit" = "Drupal\comment\CommentTypeFormController", + * "default" = "Drupal\comment\CommentTypeForm", + * "add" = "Drupal\comment\CommentTypeForm", + * "edit" = "Drupal\comment\CommentTypeForm", * "delete" = "Drupal\comment\Form\CommentTypeDeleteForm" * }, * "list_builder" = "Drupal\comment\CommentTypeListBuilder" @@ -40,7 +40,7 @@ * } * ) */ -class CommentType extends ConfigEntityBase implements CommentTypeInterface { +class CommentType extends ConfigEntityBundleBase implements CommentTypeInterface { /** * The comment type ID. @@ -73,34 +73,6 @@ class CommentType extends ConfigEntityBase implements CommentTypeInterface { /** * {@inheritdoc} */ - public function postSave(EntityStorageInterface $storage, $update = TRUE) { - parent::postSave($storage, $update); - - if (!$update && !$this->isSyncing()) { - entity_invoke_bundle_hook('create', 'comment', $this->id()); - if (!$this->isSyncing()) { - \Drupal::service('comment.manager')->addBodyField($this->id()); - } - } - elseif ($this->getOriginalId() != $this->id()) { - entity_invoke_bundle_hook('rename', 'comment', $this->getOriginalId(), $this->id()); - } - } - - /** - * {@inheritdoc} - */ - public static function postDelete(EntityStorageInterface $storage, array $entities) { - parent::postDelete($storage, $entities); - - foreach ($entities as $entity) { - entity_invoke_bundle_hook('delete', 'comment', $entity->id()); - } - } - - /** - * {@inheritdoc} - */ public function getDescription() { return $this->description; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php index 4113451..2e06410 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php @@ -103,8 +103,6 @@ public function instanceSettingsForm(array $form, array &$form_state) { $settings = $this->getSettings(); - $entity_type = $this->getEntity()->getEntityTypeId(); - $field_name = $this->getFieldDefinition()->getName(); $anonymous_user = new AnonymousUserSession(); $element['comment'] = array( @@ -204,8 +202,8 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { $options = array('new' => t('Create new')); $entity_type = $this->getEntity()->getEntityTypeId(); foreach ($comment_types as $comment_type) { - if ($comment_type->targetEntityTypeId == $entity_type) { - $options[$comment_type->id] = $comment_type->label; + if ($comment_type->getTargetEntityTypeId() == $entity_type) { + $options[$comment_type->id()] = $comment_type->label(); } } $element['comment_type'] = array( @@ -224,7 +222,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { 'visible' => array( ':input[name="field[settings][comment_type]"]' => array('value' => 'new'), ), - ) + ), ); $element['new_comment_type']['label'] = array( '#type' => 'textfield', @@ -239,7 +237,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { '#machine_name' => array( 'exists' => 'comment_type_load', 'source' => array( - 'field', 'settings', 'new_comment_type', 'label' + 'field', 'settings', 'new_comment_type', 'label', ), ), '#required' => FALSE, diff --git a/core/profiles/standard/config/install/comment.type.comment.yml b/core/profiles/standard/config/install/comment.type.comment.yml index 78d4fc4..ee77bbe 100644 --- a/core/profiles/standard/config/install/comment.type.comment.yml +++ b/core/profiles/standard/config/install/comment.type.comment.yml @@ -4,4 +4,6 @@ description: 'Default comment field' targetEntityTypeId: node status: true langcode: en -dependencies: { } +dependencies: + entity: + - comment.type.comment diff --git a/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml b/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml index 1eff5ad..00abf0c 100644 --- a/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml +++ b/core/profiles/standard/config/install/rdf.mapping.comment.comment.yml @@ -27,3 +27,5 @@ fieldMappings: dependencies: module: - comment + entity: + - comment.type.comment diff --git a/core/vendor/behat/mink-goutte-driver b/core/vendor/behat/mink-goutte-driver new file mode 160000 index 0000000..b114b9b --- /dev/null +++ b/core/vendor/behat/mink-goutte-driver @@ -0,0 +1 @@ +Subproject commit b114b9b9706fa880ede66081322f5a86bdf020d8