From f25a12a9e068bcd4d24a9947bf97f4a387ab0037 Mon Sep 17 00:00:00 2001 From: yanniboi Date: Sat, 20 May 2017 13:06:21 +0000 Subject: [PATCH] By yanniboi: Basic content generation module. --- modules/contacts_demo/contacts_demo.info.yml | 7 + .../contacts_demo.links.menu.yml | 5 + .../contacts_demo.links.task.yml | 9 + .../contacts_demo/contacts_demo.routing.yml | 15 ++ .../contacts_demo/contacts_demo.services.yml | 10 + modules/contacts_demo/content/entity/file.yml | 22 +++ modules/contacts_demo/content/entity/user.yml | 43 +++++ .../content/files/file79KuSX.jpg | Bin 0 -> 4410 bytes .../content/files/fileAEmLXi.jpg | Bin 0 -> 4067 bytes .../content/files/fileaZZVtU.jpg | Bin 0 -> 4356 bytes modules/contacts_demo/flavours/complex.yml | 4 + modules/contacts_demo/flavours/default.yml | 9 + .../src/Annotation/DemoContent.php | 42 +++++ modules/contacts_demo/src/DemoContent.php | 144 ++++++++++++++ .../src/DemoContentInterface.php | 61 ++++++ .../contacts_demo/src/DemoContentManager.php | 62 ++++++ .../contacts_demo/src/DemoContentParser.php | 23 +++ .../src/DemoContentParserInterface.php | 33 ++++ modules/contacts_demo/src/DemoEntity.php | 80 ++++++++ modules/contacts_demo/src/DemoFile.php | 108 +++++++++++ modules/contacts_demo/src/DemoFlavour.php | 178 ++++++++++++++++++ .../src/DemoFlavourInterface.php | 61 ++++++ .../contacts_demo/src/DemoFlavourManager.php | 92 +++++++++ .../src/DemoFlavourManagerInterface.php | 23 +++ modules/contacts_demo/src/DemoUser.php | 178 ++++++++++++++++++ .../src/Form/GenerateDeleteForm.php | 90 +++++++++ .../contacts_demo/src/Form/GenerateForm.php | 111 +++++++++++ .../src/Plugin/DemoContent/File.php | 17 ++ .../src/Plugin/DemoContent/User.php | 17 ++ 29 files changed, 1444 insertions(+) create mode 100644 modules/contacts_demo/contacts_demo.info.yml create mode 100644 modules/contacts_demo/contacts_demo.links.menu.yml create mode 100644 modules/contacts_demo/contacts_demo.links.task.yml create mode 100644 modules/contacts_demo/contacts_demo.routing.yml create mode 100644 modules/contacts_demo/contacts_demo.services.yml create mode 100644 modules/contacts_demo/content/entity/file.yml create mode 100644 modules/contacts_demo/content/entity/user.yml create mode 100644 modules/contacts_demo/content/files/file79KuSX.jpg create mode 100644 modules/contacts_demo/content/files/fileAEmLXi.jpg create mode 100644 modules/contacts_demo/content/files/fileaZZVtU.jpg create mode 100644 modules/contacts_demo/flavours/complex.yml create mode 100644 modules/contacts_demo/flavours/default.yml create mode 100644 modules/contacts_demo/src/Annotation/DemoContent.php create mode 100644 modules/contacts_demo/src/DemoContent.php create mode 100644 modules/contacts_demo/src/DemoContentInterface.php create mode 100644 modules/contacts_demo/src/DemoContentManager.php create mode 100644 modules/contacts_demo/src/DemoContentParser.php create mode 100644 modules/contacts_demo/src/DemoContentParserInterface.php create mode 100644 modules/contacts_demo/src/DemoEntity.php create mode 100644 modules/contacts_demo/src/DemoFile.php create mode 100644 modules/contacts_demo/src/DemoFlavour.php create mode 100644 modules/contacts_demo/src/DemoFlavourInterface.php create mode 100644 modules/contacts_demo/src/DemoFlavourManager.php create mode 100644 modules/contacts_demo/src/DemoFlavourManagerInterface.php create mode 100644 modules/contacts_demo/src/DemoUser.php create mode 100644 modules/contacts_demo/src/Form/GenerateDeleteForm.php create mode 100644 modules/contacts_demo/src/Form/GenerateForm.php create mode 100644 modules/contacts_demo/src/Plugin/DemoContent/File.php create mode 100644 modules/contacts_demo/src/Plugin/DemoContent/User.php diff --git a/modules/contacts_demo/contacts_demo.info.yml b/modules/contacts_demo/contacts_demo.info.yml new file mode 100644 index 0000000..ef7a3c1 --- /dev/null +++ b/modules/contacts_demo/contacts_demo.info.yml @@ -0,0 +1,7 @@ +name: Contacts Demo +type: module +description: 'Generate demo content for contacts.' +package: Contacts +core: '8.x' +dependencies: + - contacts \ No newline at end of file diff --git a/modules/contacts_demo/contacts_demo.links.menu.yml b/modules/contacts_demo/contacts_demo.links.menu.yml new file mode 100644 index 0000000..136efff --- /dev/null +++ b/modules/contacts_demo/contacts_demo.links.menu.yml @@ -0,0 +1,5 @@ +contacts_demo.generate: + title: 'Generate demo contacts' + description: 'Generate and remove demo content for the contacts module.' + route_name: contacts_demo.generate + parent: 'system.admin_config_development' diff --git a/modules/contacts_demo/contacts_demo.links.task.yml b/modules/contacts_demo/contacts_demo.links.task.yml new file mode 100644 index 0000000..6aefb68 --- /dev/null +++ b/modules/contacts_demo/contacts_demo.links.task.yml @@ -0,0 +1,9 @@ +contacts_demo.generate: + route_name: contacts_demo.generate + base_route: contacts_demo.generate + title: 'Generate' + +contacts_demo.generate_delete: + route_name: contacts_demo.generate_delete + base_route: contacts_demo.generate + title: 'Delete' diff --git a/modules/contacts_demo/contacts_demo.routing.yml b/modules/contacts_demo/contacts_demo.routing.yml new file mode 100644 index 0000000..418fc2d --- /dev/null +++ b/modules/contacts_demo/contacts_demo.routing.yml @@ -0,0 +1,15 @@ +contacts_demo.generate: + path: '/admin/config/development/contacts-demo' + defaults: + _form: '\Drupal\contacts_demo\Form\GenerateForm' + _title: 'Generate Demo Contacts' + requirements: + _permission: 'administer site configuration' + +contacts_demo.generate_delete: + path: '/admin/config/development/contacts-demo/delete' + defaults: + _form: '\Drupal\contacts_demo\Form\GenerateDeleteForm' + _title: 'Delete Demo Contacts' + requirements: + _permission: 'administer site configuration' diff --git a/modules/contacts_demo/contacts_demo.services.yml b/modules/contacts_demo/contacts_demo.services.yml new file mode 100644 index 0000000..81ecd95 --- /dev/null +++ b/modules/contacts_demo/contacts_demo.services.yml @@ -0,0 +1,10 @@ +services: + contacts_demo.yaml_parser: + class: \Drupal\contacts_demo\DemoContentParser + arguments: ~ + plugin.manager.demo_content: + class: \Drupal\contacts_demo\DemoContentManager + parent: default_plugin_manager + plugin.manager.demo_flavour: + class: Drupal\contacts_demo\DemoFlavourManager + arguments: ['@module_handler'] diff --git a/modules/contacts_demo/content/entity/file.yml b/modules/contacts_demo/content/entity/file.yml new file mode 100644 index 0000000..ff64a21 --- /dev/null +++ b/modules/contacts_demo/content/entity/file.yml @@ -0,0 +1,22 @@ +--- +636d6ded-c1fd-47c4-b43a-02054a0ba17d: + uuid: 636d6ded-c1fd-47c4-b43a-02054a0ba17d + langcode: en + path: content/files/file79KuSX.jpg + uri: public://file79KuSX.jpg + filemime: image/jpeg + status: 1 +71bf39b6-868b-4d7b-a76e-ee34534ddd82: + uuid: 71bf39b6-868b-4d7b-a76e-ee34534ddd82 + langcode: en + path: content/files/fileAEmLXi.jpg + uri: public://fileAEmLXi.jpg + filemime: image/jpeg + status: 1 +d06145bb-e63c-474a-9326-99f44a6e6936: + uuid: aa51ee1e-dee0-11e5-b86d-9a79f06e9478 + langcode: en + path: content/files/fileaZZVtU.jpg + uri: public://fileaZZVtU.jpg + filemime: image/jpeg + status: 1 diff --git a/modules/contacts_demo/content/entity/user.yml b/modules/contacts_demo/content/entity/user.yml new file mode 100644 index 0000000..2bb04d4 --- /dev/null +++ b/modules/contacts_demo/content/entity/user.yml @@ -0,0 +1,43 @@ +--- +75d9689e-3227-4f16-a5bf-5a179f70978d: + uuid: 75d9689e-3227-4f16-a5bf-5a179f70978d + mail: susanna.ramirez@example.com + user_name: blackrabbit442 + decoupled: 1 + status: 1 + picture: 636d6ded-c1fd-47c4-b43a-02054a0ba17d + roles: + - crm_indiv + full_name: "Mrs Susanna Ramirez" + gender: female + dob: 1979-03-18 + phone: "07000 142124" + address: "7645 Mill Road|Portsmouth|J0T 2SA|United Kingdom" +ec2d9ca0-6e85-4023-b056-6368e865f274: + uuid: ec2d9ca0-6e85-4023-b056-6368e865f274 + mail: rich.rhodes@example.com + user_name: + decoupled: 0 + status: 1 + picture: 71bf39b6-868b-4d7b-a76e-ee34534ddd82 + roles: + - crm_indiv + full_name: "Mr Rich Rhodes" + gender: male + dob: 1986-10-22 + phone: "07000 832892" + address: "7034 The Grove|Carlisle|D74 8XW|United Kingdom" +283ce822-c4c8-4f5e-9b44-a87c5228cf25: + uuid: 283ce822-c4c8-4f5e-9b44-a87c5228cf25 + mail: eleanor.mccoy@example.com + user_name: + decoupled: 0 + status: 1 + picture: d06145bb-e63c-474a-9326-99f44a6e6936 + roles: + - crm_indiv + full_name: "Miss Eleanor Mccoy" + gender: female + dob: 1964-09-27 + phone: "07000 844870" + address: "4295 Station Road|Sunderland|M19 7GX|United Kingdom" \ No newline at end of file diff --git a/modules/contacts_demo/content/files/file79KuSX.jpg b/modules/contacts_demo/content/files/file79KuSX.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5c3569b62fc1daa16f9a50c2ec88646732340e6c GIT binary patch literal 4410 zcmbtWc{G%7`@hFv6k>)U#0XKgl6@z#FJoUqwrm;8*s@HLWR2`amYT5^nzEH_B}B?r z*6f93jjT1l$M<{A`~Cg#zJI*uz3%he*XLZ<_4(Y_eVyky=b;Q!rU0{^maZ0n!C*iK zT7WV`Rj8|>aT#lBtfgyk5lR3+b=TVk7eIXu0Gv-C-c6v3 zE*?&<5GFxb6c05B;oifz^WS*x5WD}4cMdV$+*AX)8v}%S-T%g-huHaVe0UdL7Y{rR zs_}-f0M0uI>ftXtya~e<9}6?cpZMzu0H#12TmZbl83X}O;0*$S803ARnf-g-`M-EZ zz!&1UK)W9Z1$cPC=?9>0pJSc-JtjtXn8{wkR8tc&;#(#Oat5`5A~ocGw1<8 zGfScT6b1m13&8JK3T6Khh4PyS0DKsLmW+S+z8TOsSD^Uae_{f805C-ZP}}rR%()1F zI%vknC;Xi7PJf*PhjuDAHvl$D0AREMfCZZM(M$hp{_lB1+K2jpI0S%sH~sO2+j(h+bUD>AXODRWpq_R?3- zM2VDZw=Cd(k&NxTD{q$Ju1vS>ONjj(d)F>d z>iW;-WWnmJbLwLm#geOAMLD$3%dKA!WU()zvR8Rk3i!!yQQNkm&N69>&eWYg7IrS< zD|klPR=>~h83K+lC$UdD5?Z-}RxQoMc$n5X-0zD9O^RJsYW6UR5$a7{-m^&WI!bL;TX@vrOwO8gi|aP-^l*++;>so0|Osb-lSL5Rv`PS{OYWLQb_$-tgLF({GtF!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YxQe2KXg;v2lWxQI2>x{k&B=eX5= zb~DtS2=Qcd+xf-Cb0ezPWo$HKQc_ofanY!J_UNE{*9bG@nG${&wM7Q9`%hwpe#J=5-+jNNgRP`TS=%o+Ey;O#aCnN<%@*{|*Ik zev@mS+lbmW6H=L{fQ&}g*=#Q87dXo=VBBbK(>r+BeLn})mXM~d6e82#Sl#!4lu9-& xA){5NFSAK=fvgC9`parE?EW_dO@3<-uWQd^U!-Rj!da8AOwOPU`7o4`{{xf~Oz{8! literal 0 HcmV?d00001 diff --git a/modules/contacts_demo/content/files/fileAEmLXi.jpg b/modules/contacts_demo/content/files/fileAEmLXi.jpg new file mode 100644 index 0000000000000000000000000000000000000000..15e3d671473143911eff8d5083b556bebedee39c GIT binary patch literal 4067 zcmbu8c{tQ>_s8$CjqJ;0$-bo-OV$|s60(n7MJ3xzF~-;$l2B+ODN9k=w`>U^DYAo0DuEtz#qs!9uLjz-`6Spsj~n+P>n0J z5&#Jhp$bocg=(dtXaMj7?vVF@;_lGn1?_pr=z8Z!{LVx(K9e1n3)(EnRq!kSrGz9gaieS@be3c%SsB1N{jLHA5%d} z%gHM#DG5oUHB}WfWEGVZ4n$yw4jp1*Wa43F=1~yg7g6}HjnV+v>A`hyof;+zsMulD z>@Z66!3P1OJ@}vg�(rXzAcEKo4bA*#H%cnu_MY=>BvGqoM{h?6e$oBJ#SNqE;>l z-^_BjLU_VqF}+58YvR4W$%w2KsFDW;sQfHbJ6pyiJubTE`+=MbTh z=hPLo@^uN%q>KP2Y8Z4$YIdLv>K$}=GrB`G=2?t~vz}BPl}X5+A(yqtn}i7bvWggp z;}85UbE98e?`*DW@(llU>XPDU)cOgj$ZTByrAYJL{?T8egx7o?4;R3f*Qs&*kS5lvj#y5HSmzZ_= zIC9r zz{kI?WRC1E@RiWCV1bx=?OHYPy*QskUnxNq&CH7m^F0&KcunHUx`BJ~bw(Ha1w-v| zwQE^P#k@ywUR!0kJ6G;E{@^*&5fM0a4+OQaz~o&NjV@DC|e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QI4v_{5!*c27eBV%x^<;6-wKWTV}LBO#?RCuW?V^DgGYa`l4 z*Y;OC0v;ThR1yBU17kT`O48io{xNOkz{uT|lkztBTRX9yKsi{VljIk4`MK>z)f#*< znJUKP_bMHx!_zbLN^;U|)TKuREHgtPn#0*uf4SCr5DLN~`d^z!8(O!?QQO!VyLF_`?@@rL=^ zC`?}MIvG)|x#YSk#jUzym~cIT`WkX9@ui)NZ^PODa{&%&eY)qv*rvK4WM(HdDXPs{ zm3|IL7hn=l&WqCia{}0y7-U?yVL5lEVooU-#AtPoW32_36~0b>V7oMq@zmJ*RrGwp*lYbOV4 e%#w*H{N~G@>ocjl2gAOsource; + } + + /** + * {@inheritdoc} + */ + public function getModule() { + $definition = $this->getPluginDefinition(); + return isset($definition['provider']) ? $definition['provider'] : NULL; + } + + /** + * {@inheritdoc} + */ + public function removeContent() { + $data = $this->fetchData(); + + foreach ($data as $uuid => $item) { + // Must have uuid and same key value. + if ($uuid !== $item['uuid']) { + continue; + } + + $entities = $this->entityStorage->loadByProperties([ + 'uuid' => $uuid, + ]); + + foreach ($entities as $entity) { + $entity->delete(); + } + } + } + + /** + * {@inheritdoc} + */ + public function count() { + return count($this->content); + } + + /** + * {@inheritdoc} + */ + public function setEntityStorage(EntityStorageInterface $entity_storage) { + $this->entityStorage = $entity_storage; + } + + /** + * {@inheritdoc} + */ + public function setSource($source) { + $this->source = $source; + } + + /** + * Gets the data from a file. + */ + protected function fetchData() { + if (!$this->data) { + foreach ($this->getSource() as $source) { + $this->data = array_merge($this->data, $this->parser->parseFile($source, $this->getModule())); + } + } + return $this->data; + } + + /** + * Load entity by uuid. + * + * @param string $entity_type_id + * @param string $uuid + * @param bool $all + * @return \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\EntityInterface[]|mixed + */ + protected function loadByUuid($entity_type_id, $uuid, $all = FALSE) { + $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id); + $entities = $storage->loadByProperties([ + 'uuid' => $uuid, + ]); + + if (!$all) { + return current($entities); + } + + return $entities; + } + + /** + * Makes an array with data of an entity. + * + * @param array $item + * @return array + */ + abstract protected function getEntry($item); + +} diff --git a/modules/contacts_demo/src/DemoContentInterface.php b/modules/contacts_demo/src/DemoContentInterface.php new file mode 100644 index 0000000..e44a198 --- /dev/null +++ b/modules/contacts_demo/src/DemoContentInterface.php @@ -0,0 +1,61 @@ +getPluginDefinition(); + $storage = \Drupal::entityTypeManager()->getStorage($definition['entity_type']); + $plugin->setEntityStorage($storage); +// dpm($configuration); + if (!empty($configuration['source'])) { + $plugin->setSource($configuration['source']); + } + + return $plugin; + } + + /** + * Create multiple instances. + * + * @param array $plugin_ids + * Identifiers of plugins. + * @param array $configurations + * Array with configuration for all plugins. + * @return array + * Array with instances of the plugins. + */ + public function createInstances($plugin_ids, array $configurations = []) { + $instances = []; + + foreach ($plugin_ids as $plugin_id) { + $configuration = isset($configurations[$plugin_id]) ? $configurations[$plugin_id] : []; + $instances[$plugin_id] = static::createInstance($plugin_id, $configuration); + } + + return $instances; + } + +} diff --git a/modules/contacts_demo/src/DemoContentParser.php b/modules/contacts_demo/src/DemoContentParser.php new file mode 100644 index 0000000..1612bb4 --- /dev/null +++ b/modules/contacts_demo/src/DemoContentParser.php @@ -0,0 +1,23 @@ +parse($this->getPath($file, $module)); + } + +} diff --git a/modules/contacts_demo/src/DemoContentParserInterface.php b/modules/contacts_demo/src/DemoContentParserInterface.php new file mode 100644 index 0000000..9b20c25 --- /dev/null +++ b/modules/contacts_demo/src/DemoContentParserInterface.php @@ -0,0 +1,33 @@ +parser = $parser; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('contacts_demo.yaml_parser') + ); + } + + /** + * {@inheritdoc} + */ + public function createContent() { + $data = $this->fetchData(); + $entity_type_id = $this->entityStorage->getEntityTypeId(); + + foreach ($data as $uuid => $item) { + // Must have uuid and same key value. + if ($uuid !== $item['uuid']) { +// drush_log(dt("{$entity_type_id} with uuid: {$uuid} has a different uuid in content."), LogLevel::ERROR); + continue; + } + + // Check whether comment with same uuid already exists. + $entities = $this->entityStorage->loadByProperties([ + 'uuid' => $uuid, + ]); + + if ($entities) { +// drush_log(dt("{$entity_type_id} with uuid: {$uuid} already exists."), LogLevel::WARNING); + continue; + } + + $entry = $this->getEntry($item); + $entity = $this->entityStorage->create($entry); + $entity->save(); + + if ($entity->id()) { + $this->content[ $entity->id() ] = $entity; + } + } + } + + /** + * {@inheritdoc} + */ + protected function getEntry($item) { + $entry = [ + 'uuid' => $item['uuid'], + ]; + + return $entry; + } + +} diff --git a/modules/contacts_demo/src/DemoFile.php b/modules/contacts_demo/src/DemoFile.php new file mode 100644 index 0000000..d422cc1 --- /dev/null +++ b/modules/contacts_demo/src/DemoFile.php @@ -0,0 +1,108 @@ +parser = $parser; + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('contacts_demo.yaml_parser'), + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function createContent() { + $data = $this->fetchData(); + + foreach ($data as $uuid => $item) { + // Must have uuid and same key value. + if ($uuid !== $item['uuid']) { +// drush_log(dt("File with uuid: {$uuid} has a different uuid in content."), LogLevel::ERROR); + continue; + } + + // Check whether file with same uuid already exists. + $files = $this->entityStorage->loadByProperties([ + 'uuid' => $uuid, + ]); + + if ($files) { +// drush_log(dt("File with uuid: {$uuid} already exists."), LogLevel::WARNING); + continue; + } + + // Copy file from module. + $item['uri'] = file_unmanaged_copy( + $this->parser->getPath($item['path'], $this->getModule()), + $item['uri'], + FILE_EXISTS_REPLACE + ); + + $item['uid'] = NULL; + $entry = $this->getEntry($item); + $entity = $this->entityStorage->create($entry); + $entity->save(); + + if (!$entity->id()) { + continue; + } + + $this->content[ $entity->id() ] = $entity; + } + + return $this->content; + } + + /** + * {@inheritdoc} + */ + protected function getEntry($item) { + $entry = [ + 'uuid' => $item['uuid'], + 'langcode' => $item['langcode'], + 'uid' => $item['uid'], + 'status' => $item['status'], + 'uri' => $item['uri'], + ]; + + return $entry; + } + +} diff --git a/modules/contacts_demo/src/DemoFlavour.php b/modules/contacts_demo/src/DemoFlavour.php new file mode 100644 index 0000000..17a9e0e --- /dev/null +++ b/modules/contacts_demo/src/DemoFlavour.php @@ -0,0 +1,178 @@ +entityTypeManger = $entity_type_manager; + $this->demoContentManager = $demo_content_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager'), + $container->get('plugin.manager.demo_content') + ); + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return (string) $this->pluginDefinition['label']; + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return (string) $this->pluginDefinition['description']; + } + + /** + * {@inheritdoc} + */ + public function getModule() { + $definition = $this->getPluginDefinition(); + return isset($definition['provider']) ? $definition['provider'] : NULL; + } + + /** + * {@inheritdoc} + */ + public function getFiles() { + $definition = $this->getPluginDefinition(); + + $files = []; + foreach ($definition['files'] as $type => $paths) { + $files[] = [ + 'type' => $type, + 'paths' => $paths, + ]; + } + return $files; + } + + /** + * {@inheritdoc} + */ + public function count() { + // @todo count total entities in manifest. + return 10; + } + + /** + * {@inheritdoc} + */ + public function generate() { + $this->generateElements(); + drupal_set_message('Generate process complete.'); + } + + /** + * {@inheritdoc} + */ + protected function generateElements() { + if ($this->count() <= 20) { + $this->generateContent(); + } + else { + $this->generateBatchContent(); + } + } + + /** + * Method responsible for creating content when + * the number of elements is less than 50. + */ + private function generateContent() { + $num_created = 0; + + foreach ($this->getFiles() as $file) { + + $content_type = $file['type']; + $configuration = [ + 'source' => $file['paths'], + ]; + + $plugin = $this->demoContentManager->createInstance($content_type, $configuration); + + /** @var \Drupal\contacts_demo\DemoContentInterface $plugin */ + $plugin->createContent(); + + if ($file['type'] == 'user') { + $num_created += $plugin->count(); + } + } + + // Only care about number of users created. + drupal_set_message($this->formatPlural($num_created, '1 users created.', 'Finished creating @count users')); + } + + /** + * Method responsible for creating content when + * the number of elements is greater than 50. + */ + private function generateBatchContent() { + // @TODO do batch operations. + } + + /** + * {@inheritdoc} + */ + public function delete() { + foreach ($this->getFiles() as $file) { + $content_type = $file['type']; + $configuration = [ + 'source' => $file['paths'], + ]; + + /** @var \Drupal\contacts_demo\DemoContentInterface $plugin */ + $plugin = $this->demoContentManager->createInstance($content_type, $configuration); + $plugin->removeContent(); + } + drupal_set_message('Delete process complete.'); + } + +} diff --git a/modules/contacts_demo/src/DemoFlavourInterface.php b/modules/contacts_demo/src/DemoFlavourInterface.php new file mode 100644 index 0000000..0242af8 --- /dev/null +++ b/modules/contacts_demo/src/DemoFlavourInterface.php @@ -0,0 +1,61 @@ + '', + 'description' => '', + 'class' => 'Drupal\contacts_demo\DemoFlavour', + 'id' => '', + ); + + /** + * The object that discovers plugins managed by this manager. + * + * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface + */ + protected $discovery; + + /** + * The object that instantiates plugins managed by this manager. + * + * @var \Drupal\Component\Plugin\Factory\FactoryInterface + */ + protected $factory; + + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + + /** + * Constructs a \Drupal\contacts_demo\DemoFlavourManager object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + */ + public function __construct(ModuleHandlerInterface $module_handler) { + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + $definition['id'] = $plugin_id; + } + + /** + * Gets the plugin discovery. + * + * @return \Drupal\Component\Plugin\Discovery\DiscoveryInterface + */ + protected function getDiscovery() { + if (!isset($this->discovery)) { + $directories = array_map(function($directory) { + return [$directory . '/contacts_flavours', $directory . '/flavours']; + }, $this->moduleHandler->getModuleDirectories()); + + $yaml_discovery = new YamlDirectoryDiscovery($directories, 'contacts_demo'); + $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery); + } + return $this->discovery; + } + + /** + * {@inheritdoc} + */ + public function isPluginSupported($plugin_id) { + $definition = $this->getDefinition($plugin_id, FALSE); + return $definition && $definition['supported']; + } + +} diff --git a/modules/contacts_demo/src/DemoFlavourManagerInterface.php b/modules/contacts_demo/src/DemoFlavourManagerInterface.php new file mode 100644 index 0000000..9ae5bac --- /dev/null +++ b/modules/contacts_demo/src/DemoFlavourManagerInterface.php @@ -0,0 +1,23 @@ +parser = $parser; + $this->profileStorage = $profile_storage; + $this->fileStorage = $file_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('contacts_demo.yaml_parser'), + $container->get('entity.manager')->getStorage('profile'), + $container->get('entity.manager')->getStorage('file') + ); + } + + /** + * {@inheritdoc} + */ + public function createContent() { + $data = $this->fetchData(); + + foreach ($data as $uuid => $item) { + // Must have uuid and same key value. + if ($uuid !== $item['uuid']) { +// drush_log(dt("User with uuid: {$uuid} has a different uuid in content."), LogLevel::ERROR); + continue; + } + + // Check whether user with same uuid already exists. + $accounts = $this->entityStorage->loadByProperties([ + 'uuid' => $uuid, + ]); + + if ($accounts) { +// drush_log(dt("User with uuid: {$uuid} already exists."), LogLevel::WARNING); + continue; + } + + // Load image by uuid and set to a profile. + if (!empty($item['picture'])) { + $item['picture'] = $this->preparePicture($item['picture']); + } + else { + // Set "null" to exclude errors during saving (in cases when picture will equal to "false"). + $item['picture'] = NULL; + } + + if ($item['decoupled']) { + $item['roles'] = array_merge($item['roles'], [AccountInterface::ANONYMOUS_ROLE]); + } + else { + $item['roles'] = array_merge($item['roles'], [AccountInterface::AUTHENTICATED_ROLE]); + } + $item['roles'] += array_filter($item['roles']); + + + $entry = $this->getEntry($item); + $account = $this->entityStorage->create($entry); + $account->enforceIsNew(); + $account->save(); + + if (!$account->id()) { + continue; + } + + $this->content[ $account->id() ] = $account; + + // Load the profile, since it's autocreated. + $profile = $this->profileStorage->create([ + 'uid' => $account->id(), + 'type' => ProfileType::load('crm_indiv')->id(), + ]); + $this->fillProfile($profile, $item); + $profile->save(); + } + + return $this->content; + } + + /** + * {@inheritdoc} + */ + protected function getEntry($item) { + $entry = [ + 'uuid' => $item['uuid'], + 'name' => $item['username'], + 'mail' => $item['mail'], + 'init' => $item['mail'], + 'status' => $item['status'], + 'user_picture' => $item['picture'], + 'created' => REQUEST_TIME, + 'changed' => REQUEST_TIME, + 'roles' => array_values($item['roles']), + ]; + + return $entry; + } + + /** + * Prepares data about an image of a profile. + * + * @param $picture + * @return array + */ + protected function preparePicture($picture) { + $value = NULL; + $files = $this->fileStorage->loadByProperties([ + 'uuid' => $picture, + ]); + + if ($files) { + $value = [ + [ + 'target_id' => current($files)->id(), + ], + ]; + } + + return $value; + } + + /** + * Fills the some fields of a profile. + * + * @param \Drupal\profile\Entity\ProfileInterface $profile + * @param array $item + */ + protected function fillProfile($profile, $item) { + $profile->crm_name = $item['full_name']; + $profile->crm_gender = $item['gender']; + $profile->crm_dob = $item['dob']; + $profile->crm_phone = $item['phone']; +// $profile->crm_address = $item['address']; + } + +} diff --git a/modules/contacts_demo/src/Form/GenerateDeleteForm.php b/modules/contacts_demo/src/Form/GenerateDeleteForm.php new file mode 100644 index 0000000..2bcc8db --- /dev/null +++ b/modules/contacts_demo/src/Form/GenerateDeleteForm.php @@ -0,0 +1,90 @@ +demoFlavourManager = $demo_flavour_manager; + $this->demoContentManager = $demo_content_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.demo_flavour'), + $container->get('plugin.manager.demo_content') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'contacts_demo_admin_generate_delete_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) { + // @todo Show information about what content will be deleted. + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Delete'), + '#button_type' => 'primary', + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + // @todo Figure out which flavours have been generated. + $flavour = 'default'; + + /* @var $plugin DemoFlavourInterface */ + $plugin = $this->demoFlavourManager->createInstance($flavour); + // Delete content. + $plugin->delete(); + } + +} diff --git a/modules/contacts_demo/src/Form/GenerateForm.php b/modules/contacts_demo/src/Form/GenerateForm.php new file mode 100644 index 0000000..7aac9d4 --- /dev/null +++ b/modules/contacts_demo/src/Form/GenerateForm.php @@ -0,0 +1,111 @@ +demoFlavourManager = $demo_flavour_manager; + $this->demoContentManager = $demo_content_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.demo_flavour'), + $container->get('plugin.manager.demo_content') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'contacts_demo_admin_generate_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) { + // @todo Work out if flavours have already been generated. + $form['flavours'] = array( + '#type' => 'radios', + '#title' => $this->t('Demo Flavours'), + '#required' => TRUE, + '#default_value' => 'default', + '#options' => [], + '#description' => $this->t('Select the flavour of contacts demo content you wish to install.'), + ); + + foreach ($this->demoFlavourManager->getDefinitions() as $id => $definition) { + $form['flavours']['#options'][$id] = $definition['label']; + + $supported = $this->demoFlavourManager->isPluginSupported($id); + $form['flavours'][$id]['#disabled'] = !$supported; + + $form['flavours'][$id]['#description'] = [ + '#type' => 'inline_template', + '#template' => '{{ description }}{% if not supported %}
{% trans %}Not available. You may need to install external dependencies for use this plugin.{% endtrans %}
{% endif %}', + '#context' => [ + 'description' => $definition['description'], + 'supported' => $supported, + ] + ]; + } + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Generate'), + '#button_type' => 'primary', + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $flavour = $form_state->getValue('flavours'); + $plugin = $this->demoFlavourManager->createInstance($flavour); + // Generate content. + $plugin->generate(); + } + +} diff --git a/modules/contacts_demo/src/Plugin/DemoContent/File.php b/modules/contacts_demo/src/Plugin/DemoContent/File.php new file mode 100644 index 0000000..cf1a6e3 --- /dev/null +++ b/modules/contacts_demo/src/Plugin/DemoContent/File.php @@ -0,0 +1,17 @@ +