commit ebe82ddb1e09052678ea400dd880dd483d81da4e Author: Lee Rowlands Date: Tue May 27 07:35:42 2014 +1000 Patch 62 diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index e35bead..03de0f8 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -70,7 +70,7 @@ function comment_schema() { 'field_name' => array( 'type' => 'varchar', 'not null' => TRUE, - 'default' => 'comment', + 'default' => '', 'length' => 255, 'description' => 'The field_name of the field that was used to add this comment.', ), @@ -205,7 +205,7 @@ function comment_schema() { 'field_name' => array( 'type' => 'varchar', 'not null' => TRUE, - 'default' => 'comment', + 'default' => '', 'length' => 255, 'description' => 'The field_name of the field that was used to add this comment.', ), diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 61d94bf..baf41f6 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -12,6 +12,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; +use Drupal\comment\Entity\CommentType; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\entity\Entity\EntityViewDisplay; @@ -97,19 +98,6 @@ function comment_help($route_name, Request $request) { } /** - * Implements hook_entity_bundle_info(). - */ -function comment_entity_bundle_info() { - $bundles = array(); - foreach (entity_load_multiple('comment_type') as $comment_type) { - $bundles['comment'][$comment_type->id] = array( - 'label' => $comment_type->label, - ); - } - return $bundles; -} - -/** * Entity URI callback. */ function comment_uri(CommentInterface $comment) { @@ -127,7 +115,7 @@ function comment_uri(CommentInterface $comment) { */ function comment_entity_extra_field_info() { $return = array(); - foreach (entity_load_multiple('comment_type') as $comment_type) { + foreach (CommentType::loadMultiple() as $comment_type) { $return['comment'][$comment_type->id] = array( 'form' => array( 'author' => array( @@ -540,7 +528,6 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie * The renderable array for the comment addition form. */ function comment_add(EntityInterface $entity, $field_name = 'comment', $pid = NULL) { - /** @var \Drupal\field\FieldConfigInterface $field */ $field = Fieldconfig::loadByName($entity->getEntityTypeId(), $field_name); $values = array( 'entity_type' => $entity->getEntityTypeId(), diff --git a/core/modules/comment/config/schema/comment.schema.yml b/core/modules/comment/config/schema/comment.schema.yml index f6810e5..82c9e30 100644 --- a/core/modules/comment/config/schema/comment.schema.yml +++ b/core/modules/comment/config/schema/comment.schema.yml @@ -53,7 +53,7 @@ comment.type.*: uuid: type: string label: 'UUID' - targetEntityTypeId: + target_entity_type_id: type: string label: 'Target Entity Type ID' label: diff --git a/core/modules/comment/lib/Drupal/comment/CommentForm.php b/core/modules/comment/lib/Drupal/comment/CommentForm.php index 1f509c6..228c3a5 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentForm.php +++ b/core/modules/comment/lib/Drupal/comment/CommentForm.php @@ -158,6 +158,15 @@ public function form(array $form, array &$form_state) { $form['author']['name']['#account'] = $this->currentUser; } + $language_configuration = \Drupal::moduleHandler()->invoke('language', 'get_default_configuration', array('comment', $comment->getTypeId())); + $form['langcode'] = array( + '#title' => t('Language'), + '#type' => 'language_select', + '#default_value' => $comment->getUntranslated()->language()->id, + '#languages' => Language::STATE_ALL, + '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], + ); + // Add author e-mail and homepage fields depending on the current user. $form['author']['mail'] = array( '#type' => 'email', @@ -213,13 +222,6 @@ public function form(array $form, array &$form_state) { '#value' => ($comment->id() ? !$comment->getOwnerId() : $this->currentUser->isAnonymous()), ); - // Add internal comment properties. - $original = $comment->getUntranslated(); - foreach (array('cid', 'pid', 'entity_id', 'entity_type', 'comment_type', 'field_name', 'uid', 'langcode') as $key) { - $key_name = key($comment->$key->getFieldDefinition()->getPropertyDefinitions()); - $form[$key] = array('#type' => 'value', '#value' => $original->$key->{$key_name}); - } - return parent::form($form, $form_state, $comment); } @@ -265,8 +267,9 @@ protected function actions(array $form, array &$form_state) { */ public function validate(array $form, array &$form_state) { parent::validate($form, $form_state); + $entity = $this->entity; - if (!empty($form_state['values']['cid'])) { + if (!$entity->isNew()) { // Verify the name in case it is being changed from being anonymous. $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state['values']['name'])); $account = reset($accounts); @@ -366,8 +369,8 @@ public function preview(array &$form, array &$form_state) { * Overrides Drupal\Core\Entity\EntityForm::save(). */ public function save(array $form, array &$form_state) { - $entity = entity_load($form_state['values']['entity_type'], $form_state['values']['entity_id']); $comment = $this->entity; + $entity = $comment->getCommentedEntity(); $field_name = $comment->getFieldName(); $uri = $entity->urlInfo(); diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 0a976d9..0489a79 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -119,7 +119,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $comment_type_storage->create(array( 'id' => $comment_type_id, 'label' => $comment_type_id, - 'targetEntityTypeId' => $entity_type, + 'target_entity_type_id' => $entity_type, 'description' => 'Default comment field', ))->save(); } @@ -239,8 +239,6 @@ public function addBodyField($comment_type_id) { 'weight' => 0, )) ->save(); - - $this->entityManager->clearCachedFieldDefinitions(); } } diff --git a/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php b/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php index 3650e45..d7aab3b 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php +++ b/core/modules/comment/lib/Drupal/comment/CommentTypeForm.php @@ -83,9 +83,9 @@ public function form(array $form, array &$form_state) { $options[$entity_type->id()] = $entity_type->getLabel(); } } - $form['targetEntityTypeId'] = array( + $form['target_entity_type_id'] = array( '#type' => 'select', - '#default_value' => $comment_type->targetEntityTypeId, + '#default_value' => $comment_type->getTargetEntityTypeId(), '#description' => t('Select the target entity type for this comment type.'), '#title' => t('Target entity type'), '#options' => $options, diff --git a/core/modules/comment/lib/Drupal/comment/CommentTypeInterface.php b/core/modules/comment/lib/Drupal/comment/CommentTypeInterface.php index e768063..215fe12 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentTypeInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentTypeInterface.php @@ -28,7 +28,6 @@ public function getDescription(); * The new description. * * @return $this - * */ public function setDescription($description); diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 33e5fef..9a69cc4 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\FieldDefinition; +use Drupal\field\Entity\FieldConfig; use Drupal\user\UserInterface; /** @@ -299,14 +300,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { * {@inheritdoc} */ public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { - if ($entity_type->id() == 'comment') { - 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(); + if ($comment_type = CommentType::load($bundle)) { + $fields['entity_id'] = clone $base_field_definitions['entity_id']; + $fields['entity_id']->setSetting('target_type', $comment_type->getTargetEntityTypeId()); + return $fields; } + return array(); } /** @@ -496,8 +495,7 @@ public function getChangedTime() { */ public static function preCreate(EntityStorageInterface $storage, array &$values) { if (empty($values['comment_type']) && !empty($values['field_name']) && !empty($values['entity_type'])) { - /** @var \Drupal\field\FieldConfigInterface $field */ - $field = entity_load('field_config', $values['entity_type'] . '.' . $values['field_name']); + $field = FieldConfig::loadByName($values['entity_type'], $values['field_name']); $values['comment_type'] = $field->getSetting('comment_type'); } } diff --git a/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php b/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php index eaf8232..4d7dd1d 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/CommentType.php @@ -68,7 +68,7 @@ class CommentType extends ConfigEntityBundleBase implements CommentTypeInterface * * @var string */ - public $targetEntityTypeId; + public $target_entity_type_id; /** * {@inheritdoc} @@ -89,7 +89,7 @@ public function setDescription($description) { * {@inheritdoc} */ public function getTargetEntityTypeId() { - return $this->targetEntityTypeId; + return $this->target_entity_type_id; } /** 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 637f2a8..fcea82c 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 @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\Field\FieldType; +use Drupal\comment\Entity\CommentType; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; @@ -196,10 +197,9 @@ public function isEmpty() { public function settingsForm(array &$form, array &$form_state, $has_data) { $element = array(); - // @todo Inject storage controller once typed-data supports container - // injection. - $comment_types = entity_load_multiple('comment_type'); - $options = array('new' => t('Create new')); + // @todo Inject entity storage once typed-data supports container injection. + $comment_types = CommentType::loadMultiple(); + $options = array('' => t('Create new')); $entity_type = $this->getEntity()->getEntityTypeId(); foreach ($comment_types as $comment_type) { if ($comment_type->getTargetEntityTypeId() == $entity_type) { @@ -250,7 +250,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { '#description' => t('Enter a description for the new comment type.'), '#title' => t('Description'), ); - $element['new_comment_type']['targetEntityTypeId'] = array( + $element['new_comment_type']['target_entity_type_id'] = array( '#type' => 'value', '#value' => $entity_type, ); @@ -264,7 +264,7 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { */ public function createNewCommentType($form, &$form_state) { $settings = $form_state['values']['field']['settings']; - if ($settings['comment_type'] == 'new') { + if ($settings['comment_type'] === '') { // @todo Inject this once typed-data supports ContainerInjectionInterface. $comment_type = entity_create('comment_type', $settings['new_comment_type']); $comment_type->save(); @@ -277,7 +277,7 @@ public function createNewCommentType($form, &$form_state) { */ public function validateNewCommentType($form, &$form_state) { $settings = $form_state['values']['field']['settings']; - if ($settings['comment_type'] == 'new') { + if ($settings['comment_type'] == '') { if (empty($settings['new_comment_type']['label'])) { \Drupal::formBuilder()->setErrorByName('field][settings][new_comment_type][label', $form_state, t('Please provide a label for the new comment type')); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index d3c2ccd..884e9f6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -43,7 +43,7 @@ function setUp() { 'id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', - 'targetEntityTypeId' => 'entity_test', + 'target_entity_type_id' => 'entity_test', ))->save(); // Create comment field on entity_test bundle. $this->container->get('comment.manager')->addDefaultField('entity_test', 'entity_test'); @@ -370,13 +370,13 @@ function testCommentFunctionality() { $this->drupalPostForm(NULL, $edit, t('Save')); // Attempt to save with a new comment-type but incomplete form. $this->drupalPostForm(NULL, array( - 'field[settings][comment_type]' => 'new', + 'field[settings][comment_type]' => '', ), t('Save field settings')); $this->assertText(t('Please provide a label for the new comment type')); $this->assertText(t('Please provide a machine name for the new comment type')); // Now provide the required values. $this->drupalPostForm(NULL, array( - 'field[settings][comment_type]' => 'new', + 'field[settings][comment_type]' => '', 'field[settings][new_comment_type][id]' => 'foobar', 'field[settings][new_comment_type][label]' => 'Foobar', ), t('Save field settings')); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTypeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTypeTest.php index 924b5e5..02f3a46 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTypeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTypeTest.php @@ -72,7 +72,7 @@ public function testCommentTypeCreation() { 'id' => 'foo', 'label' => 'title for foo', 'description' => '', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', ); $this->drupalPostForm('admin/structure/comment/types/add', $edit, t('Save')); $comment_type = entity_load('comment_type', 'foo'); @@ -193,7 +193,7 @@ protected function createCommentType($label) { 'id' => $label, 'label' => $label, 'description' => '', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', )); $bundle->save(); return $bundle; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php index 168c875..47d77e7 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentValidationTest.php @@ -50,7 +50,7 @@ public function testValidation() { $this->entityManager->getStorage('comment_type')->create(array( 'id' => 'comment', 'label' => 'comment', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', ))->save(); // Add comment field to content. diff --git a/core/modules/hal/lib/Drupal/hal/Tests/EntityTest.php b/core/modules/hal/lib/Drupal/hal/Tests/EntityTest.php index c2873c8..c54b238 100644 --- a/core/modules/hal/lib/Drupal/hal/Tests/EntityTest.php +++ b/core/modules/hal/lib/Drupal/hal/Tests/EntityTest.php @@ -58,7 +58,7 @@ public function testNode() { $this->container->get('entity.manager')->getStorage('comment_type')->create(array( 'id' => 'comment', 'label' => 'comment', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', ))->save(); $this->container->get('comment.manager')->addDefaultField('node', 'example_type'); @@ -142,7 +142,7 @@ public function testComment() { $this->container->get('entity.manager')->getStorage('comment_type')->create(array( 'id' => 'comment', 'label' => 'comment', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', ))->save(); $this->container->get('comment.manager')->addDefaultField('node', 'example_type'); diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml index c1d303b..18137ee 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_comment_type.yml @@ -15,7 +15,7 @@ source: label: comment description: comment process: - targetEntityTypeId: constants.entity_type + target_entity_type_id: constants.entity_type id: constants.id label: constants.label description: constants.description diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php index ffc3752..1c84d28 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php @@ -40,7 +40,7 @@ public function setUp() { $this->container->get('entity.manager')->getStorage('comment_type')->create(array( 'id' => 'comment', 'label' => 'comment', - 'targetEntityTypeId' => 'node', + 'target_entity_type_id' => 'node', ))->save(); $node = entity_create('node', array( diff --git a/core/profiles/standard/config/install/comment.type.comment.yml b/core/profiles/standard/config/install/comment.type.comment.yml index ee77bbe..b75349c 100644 --- a/core/profiles/standard/config/install/comment.type.comment.yml +++ b/core/profiles/standard/config/install/comment.type.comment.yml @@ -1,7 +1,7 @@ id: comment label: comment description: 'Default comment field' -targetEntityTypeId: node +target_entity_type_id: node status: true langcode: en dependencies: