Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.
This commit is contained in:
parent
4afb23bbd3
commit
7784f4c23d
929 changed files with 19798 additions and 5304 deletions
|
@ -23,6 +23,7 @@ entity.comment.edit_form:
|
|||
_entity_form: 'comment.default'
|
||||
requirements:
|
||||
_entity_access: 'comment.update'
|
||||
comment: \d+
|
||||
|
||||
comment.approve:
|
||||
path: '/comment/{comment}/approve'
|
||||
|
@ -33,6 +34,7 @@ comment.approve:
|
|||
requirements:
|
||||
_entity_access: 'comment.approve'
|
||||
_csrf_token: 'TRUE'
|
||||
comment: \d+
|
||||
|
||||
entity.comment.canonical:
|
||||
path: '/comment/{comment}'
|
||||
|
@ -41,6 +43,7 @@ entity.comment.canonical:
|
|||
_controller: '\Drupal\comment\Controller\CommentController::commentPermalink'
|
||||
requirements:
|
||||
_entity_access: 'comment.view'
|
||||
comment: \d+
|
||||
|
||||
entity.comment.delete_form:
|
||||
path: '/comment/{comment}/delete'
|
||||
|
@ -49,6 +52,7 @@ entity.comment.delete_form:
|
|||
_entity_form: 'comment.delete'
|
||||
requirements:
|
||||
_entity_access: 'comment.delete'
|
||||
comment: \d+
|
||||
|
||||
comment.reply:
|
||||
path: '/comment/reply/{entity_type}/{entity}/{field_name}/{pid}'
|
||||
|
@ -77,6 +81,7 @@ comment.node_redirect:
|
|||
requirements:
|
||||
_entity_access: 'node.view'
|
||||
_module_dependencies: 'node'
|
||||
node: \d+
|
||||
|
||||
entity.comment_type.collection:
|
||||
path: '/admin/structure/comment'
|
||||
|
|
|
@ -39,6 +39,34 @@ class CommentSelection extends DefaultSelection {
|
|||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
|
||||
$comment = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
|
||||
|
||||
// In order to create a referenceable comment, it needs to published.
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
$comment->setPublished(TRUE);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateReferenceableNewEntities(array $entities) {
|
||||
$entities = parent::validateReferenceableNewEntities($entities);
|
||||
// Mirror the conditions checked in buildEntityQuery().
|
||||
if (!$this->currentUser->hasPermission('administer comments')) {
|
||||
$entities = array_filter($entities, function ($comment) {
|
||||
/** @var \Drupal\comment\CommentInterface $comment */
|
||||
return $comment->isPublished();
|
||||
});
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\comment\Plugin\migrate\destination;
|
|||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
|
@ -62,13 +63,15 @@ class EntityComment extends EntityContentBase {
|
|||
* The list of bundles this entity type has.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
|
||||
* The field type plugin manager service.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state storage object.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The query object that can query the given entity type.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, StateInterface $state, QueryFactory $entity_query) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager);
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, QueryFactory $entity_query) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
|
||||
$this->state = $state;
|
||||
$this->entityQuery = $entity_query;
|
||||
}
|
||||
|
@ -86,6 +89,7 @@ class EntityComment extends EntityContentBase {
|
|||
$container->get('entity.manager')->getStorage($entity_type),
|
||||
array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('state'),
|
||||
$container->get('entity.query')
|
||||
);
|
||||
|
@ -110,32 +114,9 @@ class EntityComment extends EntityContentBase {
|
|||
*/
|
||||
protected function processStubRow(Row $row) {
|
||||
parent::processStubRow($row);
|
||||
$stub_commented_entity_type = $row->getDestinationProperty('entity_type');
|
||||
|
||||
// While parent::getEntity() fills the bundle property for stub entities
|
||||
// if it's still empty, here we must also make sure entity_id/entity_type
|
||||
// are filled (so $comment->getCommentedEntity() always returns a value).
|
||||
if (empty($this->stubCommentedEntityIds[$stub_commented_entity_type])) {
|
||||
// Fill stub entity id. Any id will do, as long as it exists.
|
||||
$entity_type = $this->entityManager->getDefinition($stub_commented_entity_type);
|
||||
$id_key = $entity_type->getKey('id');
|
||||
$result = $this->entityQuery
|
||||
->get($stub_commented_entity_type)
|
||||
->range(0, 1)
|
||||
->execute();
|
||||
if ($result) {
|
||||
$this->stubCommentedEntityIds[$stub_commented_entity_type] = array_pop($result);
|
||||
$row->setSourceProperty($id_key, $this->stubCommentedEntityIds[$stub_commented_entity_type]);
|
||||
}
|
||||
else {
|
||||
throw new MigrateException(t('Could not find parent entity to use for comment %id', ['%id' => implode(':', $row->getSourceIdValues())]), MigrationInterface::MESSAGE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$row->setDestinationProperty('entity_id', $this->stubCommentedEntityIds[$stub_commented_entity_type]);
|
||||
$row->setDestinationProperty('entity_type', $stub_commented_entity_type);
|
||||
$row->setDestinationProperty('created', REQUEST_TIME);
|
||||
$row->setDestinationProperty('changed', REQUEST_TIME);
|
||||
// Neither uid nor name is required in itself, but it is required to set one
|
||||
// of them.
|
||||
$row->setDestinationProperty('name', 'anonymous_stub');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class CommentValidationTest extends EntityUnitTestBase {
|
|||
*/
|
||||
public function testValidation() {
|
||||
// Add a user.
|
||||
$user = User::create(array('name' => 'test'));
|
||||
$user = User::create(array('name' => 'test', 'status' => TRUE));
|
||||
$user->save();
|
||||
|
||||
// Add comment type.
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\comment\Tests\Migrate\MigrateCommentStubTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\comment\Tests\Migrate;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
||||
use Drupal\migrate_drupal\Tests\StubTestTrait;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Test stub creation for comment entities.
|
||||
*
|
||||
* @group comment
|
||||
*/
|
||||
class MigrateCommentStubTest extends MigrateDrupalTestBase {
|
||||
|
||||
use StubTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('node');
|
||||
// Make sure uid 0 is created (default uid for comments is 0).
|
||||
$storage = \Drupal::entityManager()->getStorage('user');
|
||||
// Insert a row for the anonymous user.
|
||||
$storage
|
||||
->create(array(
|
||||
'uid' => 0,
|
||||
'status' => 0,
|
||||
'name' => '',
|
||||
))
|
||||
->save();
|
||||
// Need at least one node type and comment type present.
|
||||
NodeType::create([
|
||||
'type' => 'testnodetype',
|
||||
'name' => 'Test node type',
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => 'testcommenttype',
|
||||
'label' => 'Test comment type',
|
||||
'target_entity_type_id' => 'node',
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creation of comment stubs.
|
||||
*/
|
||||
public function testStub() {
|
||||
try {
|
||||
// We expect an exception, because there's no node to reference.
|
||||
$this->performStubTest('comment');
|
||||
$this->fail('Expected exception has not been thrown.');
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->assertIdentical($e->getMessage(),
|
||||
'Stubbing failed, unable to generate value for field entity_id');
|
||||
}
|
||||
|
||||
// The stub should pass when there's a node to point to.
|
||||
$this->createStub('node');
|
||||
$this->performStubTest('comment');
|
||||
}
|
||||
|
||||
}
|
|
@ -22,13 +22,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'comment',
|
||||
// Directly testing that a stub comment's entity_id is populated upon
|
||||
// importing is not straightforward, but RDF module serves as an implicit
|
||||
// test - its hook_comment_storage_load() references a stubbed comment.
|
||||
'rdf',
|
||||
];
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
Reference in a new issue