From e9f71b3286cf77c858eb57dbeb2e016d20f10544 Mon Sep 17 00:00:00 2001 From: Hirenkumar Parmar Date: Tue, 14 Dec 2021 19:41:36 +0530 Subject: [PATCH 1/3] Adding API product field in API Doc --- apigee_api_catalog.info.yml | 2 + apigee_api_catalog.install | 7 ++ composer.json | 3 +- ...ntity_form_display.node.apidoc.default.yml | 11 ++++ ...ntity_view_display.node.apidoc.default.yml | 2 + ...ld.field.node.apidoc.field_api_product.yml | 22 +++++++ .../field.storage.node.field_api_product.yml | 22 +++++++ src/UpdateService.php | 66 +++++++++++++++++++ tests/src/Kernel/ApidocEntityTest.php | 2 + 9 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 config/install/field.field.node.apidoc.field_api_product.yml create mode 100644 config/install/field.storage.node.field_api_product.yml diff --git a/apigee_api_catalog.info.yml b/apigee_api_catalog.info.yml index c1c64b5..5f6ed99 100644 --- a/apigee_api_catalog.info.yml +++ b/apigee_api_catalog.info.yml @@ -5,9 +5,11 @@ core_version_requirement: ^8.8.0 || ^9 package: 'Apigee' dependencies: - drupal:text +- drupal:entity - drupal:file - drupal:user - drupal:node - drupal:path - drupal:options - drupal:file_link +- drupal:apigee_edge diff --git a/apigee_api_catalog.install b/apigee_api_catalog.install index 314053f..4dcf320 100644 --- a/apigee_api_catalog.install +++ b/apigee_api_catalog.install @@ -134,3 +134,10 @@ function apigee_api_catalog_update_8806() { function apigee_api_catalog_update_8807() { return \Drupal::service('apigee_api_catalog.updates')->update8807(); } + +/** + * Add API Product field. + */ +function apigee_api_catalog_update_8808() { + return \Drupal::service('apigee_api_catalog.updates')->update8808(); +} diff --git a/composer.json b/composer.json index 87af847..e900f86 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "require": { "php": ">=7.1", "drupal/entity": "^1.1", - "drupal/file_link": "^2.0" + "drupal/file_link": "^2.0", + "drupal/apigee_edge": "^2.0" }, "require-dev": { "cweagans/composer-patches": "^1.6", diff --git a/config/install/core.entity_form_display.node.apidoc.default.yml b/config/install/core.entity_form_display.node.apidoc.default.yml index 7953528..e55c716 100644 --- a/config/install/core.entity_form_display.node.apidoc.default.yml +++ b/config/install/core.entity_form_display.node.apidoc.default.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - field.field.node.apidoc.body + - field.field.node.apidoc.field_api_product - field.field.node.apidoc.field_apidoc_fetched_timestamp - field.field.node.apidoc.field_apidoc_file_link - field.field.node.apidoc.field_apidoc_spec @@ -54,6 +55,16 @@ content: third_party_settings: { } type: options_select region: content + field_api_product: + weight: 7 + settings: + match_operator: CONTAINS + match_limit: 10 + size: 60 + placeholder: '' + third_party_settings: { } + type: entity_reference_autocomplete + region: content path: type: path weight: 9 diff --git a/config/install/core.entity_view_display.node.apidoc.default.yml b/config/install/core.entity_view_display.node.apidoc.default.yml index db69385..dc07221 100644 --- a/config/install/core.entity_view_display.node.apidoc.default.yml +++ b/config/install/core.entity_view_display.node.apidoc.default.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - field.field.node.apidoc.body + - field.field.node.apidoc.field_api_product - field.field.node.apidoc.field_apidoc_fetched_timestamp - field.field.node.apidoc.field_apidoc_file_link - field.field.node.apidoc.field_apidoc_spec @@ -42,3 +43,4 @@ hidden: field_apidoc_file_link: true field_apidoc_spec_file_source: true field_apidoc_spec_md5: true + field_api_product: true diff --git a/config/install/field.field.node.apidoc.field_api_product.yml b/config/install/field.field.node.apidoc.field_api_product.yml new file mode 100644 index 0000000..dd28a0d --- /dev/null +++ b/config/install/field.field.node.apidoc.field_api_product.yml @@ -0,0 +1,22 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_api_product + - node.type.apidoc +id: node.apidoc.field_api_product +field_name: field_api_product +entity_type: node +bundle: apidoc +label: 'API Product' +description: 'Apigee API Product' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:api_product' + handler_settings: + target_bundles: null + auto_create: false +field_type: entity_reference diff --git a/config/install/field.storage.node.field_api_product.yml b/config/install/field.storage.node.field_api_product.yml new file mode 100644 index 0000000..e7211ac --- /dev/null +++ b/config/install/field.storage.node.field_api_product.yml @@ -0,0 +1,22 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - apigee_api_catalog + module: + - apigee_edge + - node +id: node.field_api_product +field_name: field_api_product +entity_type: node +type: entity_reference +settings: + target_type: api_product +module: apigee_api_catalog +locked: false +cardinality: -1 +translatable: false +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/src/UpdateService.php b/src/UpdateService.php index b20825c..9b0e64e 100644 --- a/src/UpdateService.php +++ b/src/UpdateService.php @@ -28,6 +28,8 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Utility\UpdateException; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -347,6 +349,70 @@ public function update8807() { return 'Updated field_apidoc_spec_file_source required attribute to false.'; } + /** + * This will add the field API Product. + */ + public function update8808() { + $module = 'apigee_api_catalog'; + $configPath = drupal_get_path('module', $module) . '/config'; + $configToImport['install'] = [ + 'node.type.apidoc', + 'field.field.node.apidoc.field_api_product', + 'core.entity_form_display.node.apidoc.default', + 'core.entity_view_display.node.apidoc.default', + ]; + if (!$this->moduleHandler->moduleExists('apigee_edge')) { + throw new UpdateException('Apigee Edge is required to add API Product field, install the Apigee Edge and update again.'); + } + + foreach ($configToImport as $dir => $configs) { + foreach ($configs as $config) { + if (!$this->configFactory->listAll($config)) { + $raw = file_get_contents("$configPath/$dir/$config.yml"); + $data = Yaml::decode($raw); + $this->configFactory + ->getEditable($config) + ->setData($data) + ->set('uuid', $this->uuid->generate()) + ->save(TRUE); + } + } + } + + $fields = [ + 'field_api_product', + ]; + $source = new FileStorage("$configPath/install"); + foreach ($fields as $field) { + + if (!FieldStorageConfig::loadByName('node', $field)) { + $contents = $source->read("field.storage.node.$field"); + + $this->entityTypeManager->getStorage('field_storage_config') + ->create($contents) + ->save(); + } + + if (!FieldConfig::loadByName('node', 'apidoc', $field)) { + $this->entityTypeManager->getStorage('field_config') + ->create($source->read("field.field.node.apidoc.$field")) + ->save(); + } + } + + // Display field_api_product on the form display. + \Drupal::entityTypeManager() + ->getStorage('entity_form_display') + ->load('node.apidoc.default') + ->setComponent('field_api_product', ['weight' => 7]) + ->save(); + + $this->entityTypeManager->clearCachedDefinitions(); + + return 'Added API Product field for apidoc.'; + + } + /** * Get the field map from apidoc fields to node fields. * diff --git a/tests/src/Kernel/ApidocEntityTest.php b/tests/src/Kernel/ApidocEntityTest.php index e59661d..1d2f0d8 100755 --- a/tests/src/Kernel/ApidocEntityTest.php +++ b/tests/src/Kernel/ApidocEntityTest.php @@ -57,6 +57,7 @@ class ApidocEntityTest extends KernelTestBase { 'link', 'file_link', 'path_alias', + 'apigee_edge', 'apigee_api_catalog', ]; @@ -72,6 +73,7 @@ protected function setUp() { $this->installEntitySchema('node'); $this->installEntitySchema('node_type'); $this->installEntitySchema('path_alias'); + $this->installEntitySchema('apigee_edge'); $this->installConfig(static::$modules); $this->entityTypeManager = $this->container->get('entity_type.manager'); From 1c81d23c337c808b5c68717fed8d2dff7e19b483 Mon Sep 17 00:00:00 2001 From: Hirenkumar Parmar Date: Tue, 14 Dec 2021 20:29:11 +0530 Subject: [PATCH 2/3] Adding Test dependency --- tests/src/Functional/ApiDocsJsonApi.php | 1 + tests/src/Kernel/ApidocEntityTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/Functional/ApiDocsJsonApi.php b/tests/src/Functional/ApiDocsJsonApi.php index 13fdc80..17bf6b9 100644 --- a/tests/src/Functional/ApiDocsJsonApi.php +++ b/tests/src/Functional/ApiDocsJsonApi.php @@ -44,6 +44,7 @@ class ApiDocsJsonApi extends BrowserTestBase { * @var array */ public static $modules = [ + 'apigee_edge', 'apigee_api_catalog', 'jsonapi', 'basic_auth', diff --git a/tests/src/Kernel/ApidocEntityTest.php b/tests/src/Kernel/ApidocEntityTest.php index 1d2f0d8..b3a3f6c 100755 --- a/tests/src/Kernel/ApidocEntityTest.php +++ b/tests/src/Kernel/ApidocEntityTest.php @@ -57,6 +57,7 @@ class ApidocEntityTest extends KernelTestBase { 'link', 'file_link', 'path_alias', + 'key', 'apigee_edge', 'apigee_api_catalog', ]; @@ -73,7 +74,6 @@ protected function setUp() { $this->installEntitySchema('node'); $this->installEntitySchema('node_type'); $this->installEntitySchema('path_alias'); - $this->installEntitySchema('apigee_edge'); $this->installConfig(static::$modules); $this->entityTypeManager = $this->container->get('entity_type.manager'); From b9e48c0fe0051e6a0cbf0ddec54cb66676702c5c Mon Sep 17 00:00:00 2001 From: Hirenkumar Parmar Date: Wed, 15 Dec 2021 17:35:13 +0530 Subject: [PATCH 3/3] Patching known issue of jsonapi --- .circleci/RoboFile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/RoboFile.php b/.circleci/RoboFile.php index 6be7012..760f3ef 100644 --- a/.circleci/RoboFile.php +++ b/.circleci/RoboFile.php @@ -499,6 +499,7 @@ public function drupalVersion($drupalCoreVersion) default: break; } + $config->extra->{"patches"}->{"drupal/core"}->{"Support entities that are neither content nor config entities"} = 'https://www.drupal.org/files/issues/2020-12-02/3042467-50.patch'; file_put_contents('composer.json', json_encode($config, JSON_PRETTY_PRINT)); }