Commit b6acaf40 authored by andypost's avatar andypost Committed by larowlan

Issue #2684025 by xaiwant, andypost: Fix coding standards

parent 10c07ee3
......@@ -50,7 +50,7 @@ function default_content_drush_command() {
*
* @param string $entity_type_id
* The entity type ID.
* @param $entity_id
* @param mixed $entity_id
* The entity ID to export.
*/
function drush_default_content_export($entity_type_id, $entity_id) {
......
......@@ -20,6 +20,7 @@ use Symfony\Component\Serializer\Serializer;
/**
* A service for handling import of default content.
*
* @todo throw useful exceptions
*/
class DefaultContentManager implements DefaultContentManagerInterface {
......@@ -352,7 +353,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
}
/**
* Utility to get a default content scanner
* Utility to get a default content scanner.
*
* @return \Drupal\default_content\DefaultContentScanner
* A system listing implementation.
......@@ -372,17 +373,35 @@ class DefaultContentManager implements DefaultContentManagerInterface {
}
/**
* Parses content files
* Parses content files.
*
* @param object $file
* The scanned file.
*
* @return string
* Contents of the file.
*/
protected function parseFile($file) {
return file_get_contents($file->uri);
}
/**
* Resets tree properties.
*/
protected function resetTree() {
$this->graph = [];
$this->vertexes = array();
}
/**
* Sorts dependencies tree.
*
* @param array $graph
* Array of dependencies.
*
* @return array
* Array of sorted dependencies.
*/
protected function sortTree(array $graph) {
$graph_object = new Graph($graph);
$sorted = $graph_object->searchAndSort();
......
......@@ -2,11 +2,11 @@
namespace Drupal\default_content;
/**
* An interface defining a default content importer.
*/
interface DefaultContentManagerInterface {
/**
* Set the scanner.
*
......@@ -31,7 +31,7 @@ interface DefaultContentManagerInterface {
*
* @param string $entity_type_id
* The entity type ID.
* @param $entity_id
* @param mixed $entity_id
* The entity ID to export.
*
* @return string
......@@ -67,8 +67,8 @@ interface DefaultContentManagerInterface {
* Writes an array of serialized entities to a given folder.
*
* @param string[][] $serialized_by_type
* An array of serialized entities keyed by entity type and UUID
* @param $folder
* An array of serialized entities keyed by entity type and UUID.
* @param string $folder
* The folder to write files into.
*/
public function writeDefaultContent($serialized_by_type, $folder);
......
......@@ -13,7 +13,7 @@ class DefaultContentScanner {
* @param string $directory
* Absolute path to the directory to search.
*
* @return array
* @return object[]
* List of stdClass objects with name and uri properties.
*/
public function scan($directory) {
......
......@@ -26,7 +26,7 @@ class DefaultContentServiceProvider extends ServiceProviderBase {
new Reference('module_handler'),
]);
// The priority must be higher than that of
// serializer.normalizer.entity.hal in hal.services.yml
// serializer.normalizer.entity.hal in hal.services.yml.
$service_definition->addTag('normalizer', ['priority' => 30]);
$container->setDefinition('default_content.normalizer.taxonomy_term.halt', $service_definition);
}
......
......@@ -39,4 +39,5 @@ final class DefaultContentEvents {
* @var string
*/
const EXPORT = 'default_content.export';
}
......@@ -5,6 +5,11 @@ namespace Drupal\default_content\Event;
use Drupal\Core\Entity\ContentEntityInterface;
use Symfony\Component\EventDispatcher\Event;
/**
* Defines event fired when content is exported.
*
* @see \Drupal\default_content\Event\DefaultContentEvents
*/
class ExportEvent extends Event {
/**
......@@ -27,7 +32,8 @@ class ExportEvent extends Event {
/**
* Get the entity we've exported.
*
* @return \Drupal\Core\Entity\ContentEntityInterface[]
* @return \Drupal\Core\Entity\ContentEntityInterface
* The exported content entity.
*/
public function getExportedEntity() {
return $this->entity;
......
......@@ -4,6 +4,11 @@ namespace Drupal\default_content\Event;
use Symfony\Component\EventDispatcher\Event;
/**
* Defines event fired when content is imported.
*
* @see \Drupal\default_content\Event\DefaultContentEvents
*/
class ImportEvent extends Event {
/**
......@@ -37,6 +42,7 @@ class ImportEvent extends Event {
* Get the imported entities.
*
* @return \Drupal\Core\Entity\ContentEntityInterface[]
* An array of content entities that were imported.
*/
public function getImportedEntities() {
return $this->entities;
......@@ -53,4 +59,3 @@ class ImportEvent extends Event {
}
}
......@@ -12,10 +12,13 @@ use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\User;
/**
* Tests export functionality.
*
* @coversDefaultClass \Drupal\default_content\DefaultContentManager
* @group default_content
*/
class DefaultContentManagerIntegrationTest extends KernelTestBase {
use EntityReferenceTestTrait;
/**
......@@ -43,7 +46,10 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
* Tests exportContent().
*/
public function testExportContent() {
\Drupal::service('module_installer')->install(['taxonomy', 'default_content']);
\Drupal::service('module_installer')->install([
'taxonomy',
'default_content',
]);
\Drupal::service('router.builder')->rebuild();
$this->defaultContentManager = \Drupal::service('default_content.manager');
......@@ -55,7 +61,8 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
/** @var \Symfony\Component\Serializer\Serializer $serializer */
$serializer = \Drupal::service('serializer');
\Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
\Drupal::service('rest.link_manager')
->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
$expected = $serializer->serialize($term, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
$exported = $this->defaultContentManager->exportContent('taxonomy_term', $term->id());
......@@ -96,14 +103,19 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
$node_type = NodeType::create(['type' => 'test']);
$node_type->save();
$node = Node::create(['type' => $node_type->id(), 'title' => 'test node', 'uid' => $user->id()]);
$node = Node::create([
'type' => $node_type->id(),
'title' => 'test node',
'uid' => $user->id(),
]);
$node->save();
// Reload the node to get the proper casted values from the DB.
$node = Node::load($node->id());
/** @var \Symfony\Component\Serializer\Serializer $serializer */
$serializer = \Drupal::service('serializer');
\Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
\Drupal::service('rest.link_manager')
->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
$expected_node = $serializer->serialize($node, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
$expected_user = $serializer->serialize($user, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
......@@ -126,9 +138,17 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
$node1 = Node::create(['type' => $node_type->id(), 'title' => 'ref 1->3']);
$node1->save();
$node2 = Node::create(['type' => $node_type->id(), 'title' => 'ref 2->1', $field_name => $node1->id()]);
$node2 = Node::create([
'type' => $node_type->id(),
'title' => 'ref 2->1',
$field_name => $node1->id(),
]);
$node2->save();
$node3 = Node::create(['type' => $node_type->id(), 'title' => 'ref 3->2', $field_name => $node2->id()]);
$node3 = Node::create([
'type' => $node_type->id(),
'title' => 'ref 3->2',
$field_name => $node2->id(),
]);
$node3->save();
// Loop reference.
$node1->{$field_name}->target_id = $node3->id();
......@@ -142,7 +162,11 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
* Tests exportModuleContent().
*/
public function testModuleExport() {
\Drupal::service('module_installer')->install(['node', 'default_content', 'default_content_export_test']);
\Drupal::service('module_installer')->install([
'node',
'default_content',
'default_content_export_test',
]);
\Drupal::service('router.builder')->rebuild();
$this->defaultContentManager = \Drupal::service('default_content.manager');
......@@ -154,7 +178,8 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
$node->save();
$node = Node::load($node->id());
$serializer = \Drupal::service('serializer');
\Drupal::service('rest.link_manager')->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
\Drupal::service('rest.link_manager')
->setLinkDomain(DefaultContentManager::LINK_DOMAIN);
$expected_node = $serializer->serialize($node, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
$content = $this->defaultContentManager->exportModuleContent('default_content_export_test');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment