Skip to content

Commit 6e2fb5b

Browse files
authored
Adding Apigee API product field in API Doc
Adding Apigee API product field in API Doc content type
2 parents b8ce59d + b9e48c0 commit 6e2fb5b

11 files changed

+137
-1
lines changed

.circleci/RoboFile.php

+1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ public function drupalVersion($drupalCoreVersion)
499499
default:
500500
break;
501501
}
502+
$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';
502503

503504
file_put_contents('composer.json', json_encode($config, JSON_PRETTY_PRINT));
504505
}

apigee_api_catalog.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ dependencies:
1212
- drupal:path
1313
- drupal:options
1414
- drupal:file_link
15+
- drupal:apigee_edge

apigee_api_catalog.install

+7
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,10 @@ function apigee_api_catalog_update_8806() {
134134
function apigee_api_catalog_update_8807() {
135135
return \Drupal::service('apigee_api_catalog.updates')->update8807();
136136
}
137+
138+
/**
139+
* Add API Product field.
140+
*/
141+
function apigee_api_catalog_update_8808() {
142+
return \Drupal::service('apigee_api_catalog.updates')->update8808();
143+
}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"require": {
77
"php": ">=7.1",
88
"drupal/entity": "^1.1",
9-
"drupal/file_link": "^2.0"
9+
"drupal/file_link": "^2.0",
10+
"drupal/apigee_edge": "^2.0"
1011
},
1112
"require-dev": {
1213
"cweagans/composer-patches": "^1.6",

config/install/core.entity_form_display.node.apidoc.default.yml

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ status: true
33
dependencies:
44
config:
55
- field.field.node.apidoc.body
6+
- field.field.node.apidoc.field_api_product
67
- field.field.node.apidoc.field_apidoc_fetched_timestamp
78
- field.field.node.apidoc.field_apidoc_file_link
89
- field.field.node.apidoc.field_apidoc_spec
@@ -54,6 +55,16 @@ content:
5455
third_party_settings: { }
5556
type: options_select
5657
region: content
58+
field_api_product:
59+
weight: 7
60+
settings:
61+
match_operator: CONTAINS
62+
match_limit: 10
63+
size: 60
64+
placeholder: ''
65+
third_party_settings: { }
66+
type: entity_reference_autocomplete
67+
region: content
5768
path:
5869
type: path
5970
weight: 9

config/install/core.entity_view_display.node.apidoc.default.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ status: true
33
dependencies:
44
config:
55
- field.field.node.apidoc.body
6+
- field.field.node.apidoc.field_api_product
67
- field.field.node.apidoc.field_apidoc_fetched_timestamp
78
- field.field.node.apidoc.field_apidoc_file_link
89
- field.field.node.apidoc.field_apidoc_spec
@@ -42,3 +43,4 @@ hidden:
4243
field_apidoc_file_link: true
4344
field_apidoc_spec_file_source: true
4445
field_apidoc_spec_md5: true
46+
field_api_product: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
langcode: en
2+
status: true
3+
dependencies:
4+
config:
5+
- field.storage.node.field_api_product
6+
- node.type.apidoc
7+
id: node.apidoc.field_api_product
8+
field_name: field_api_product
9+
entity_type: node
10+
bundle: apidoc
11+
label: 'API Product'
12+
description: 'Apigee API Product'
13+
required: false
14+
translatable: false
15+
default_value: { }
16+
default_value_callback: ''
17+
settings:
18+
handler: 'default:api_product'
19+
handler_settings:
20+
target_bundles: null
21+
auto_create: false
22+
field_type: entity_reference
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
langcode: en
2+
status: true
3+
dependencies:
4+
enforced:
5+
module:
6+
- apigee_api_catalog
7+
module:
8+
- apigee_edge
9+
- node
10+
id: node.field_api_product
11+
field_name: field_api_product
12+
entity_type: node
13+
type: entity_reference
14+
settings:
15+
target_type: api_product
16+
module: apigee_api_catalog
17+
locked: false
18+
cardinality: -1
19+
translatable: false
20+
indexes: { }
21+
persist_with_no_fields: false
22+
custom_storage: false

src/UpdateService.php

+66
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Drupal\Core\Extension\ModuleHandlerInterface;
2929
use Drupal\Core\Entity\EntityTypeManagerInterface;
3030
use Drupal\Core\Entity\EntityFieldManagerInterface;
31+
use Drupal\Core\Field\BaseFieldDefinition;
32+
use Drupal\Core\Utility\UpdateException;
3133
use Drupal\field\Entity\FieldConfig;
3234
use Drupal\field\Entity\FieldStorageConfig;
3335

@@ -347,6 +349,70 @@ public function update8807() {
347349
return 'Updated field_apidoc_spec_file_source required attribute to false.';
348350
}
349351

352+
/**
353+
* This will add the field API Product.
354+
*/
355+
public function update8808() {
356+
$module = 'apigee_api_catalog';
357+
$configPath = drupal_get_path('module', $module) . '/config';
358+
$configToImport['install'] = [
359+
'node.type.apidoc',
360+
'field.field.node.apidoc.field_api_product',
361+
'core.entity_form_display.node.apidoc.default',
362+
'core.entity_view_display.node.apidoc.default',
363+
];
364+
if (!$this->moduleHandler->moduleExists('apigee_edge')) {
365+
throw new UpdateException('Apigee Edge is required to add API Product field, install the Apigee Edge and update again.');
366+
}
367+
368+
foreach ($configToImport as $dir => $configs) {
369+
foreach ($configs as $config) {
370+
if (!$this->configFactory->listAll($config)) {
371+
$raw = file_get_contents("$configPath/$dir/$config.yml");
372+
$data = Yaml::decode($raw);
373+
$this->configFactory
374+
->getEditable($config)
375+
->setData($data)
376+
->set('uuid', $this->uuid->generate())
377+
->save(TRUE);
378+
}
379+
}
380+
}
381+
382+
$fields = [
383+
'field_api_product',
384+
];
385+
$source = new FileStorage("$configPath/install");
386+
foreach ($fields as $field) {
387+
388+
if (!FieldStorageConfig::loadByName('node', $field)) {
389+
$contents = $source->read("field.storage.node.$field");
390+
391+
$this->entityTypeManager->getStorage('field_storage_config')
392+
->create($contents)
393+
->save();
394+
}
395+
396+
if (!FieldConfig::loadByName('node', 'apidoc', $field)) {
397+
$this->entityTypeManager->getStorage('field_config')
398+
->create($source->read("field.field.node.apidoc.$field"))
399+
->save();
400+
}
401+
}
402+
403+
// Display field_api_product on the form display.
404+
\Drupal::entityTypeManager()
405+
->getStorage('entity_form_display')
406+
->load('node.apidoc.default')
407+
->setComponent('field_api_product', ['weight' => 7])
408+
->save();
409+
410+
$this->entityTypeManager->clearCachedDefinitions();
411+
412+
return 'Added API Product field for apidoc.';
413+
414+
}
415+
350416
/**
351417
* Get the field map from apidoc fields to node fields.
352418
*

tests/src/Functional/ApiDocsJsonApi.php

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ApiDocsJsonApi extends BrowserTestBase {
4444
* @var array
4545
*/
4646
public static $modules = [
47+
'apigee_edge',
4748
'apigee_api_catalog',
4849
'jsonapi',
4950
'basic_auth',

tests/src/Kernel/ApidocEntityTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ApidocEntityTest extends KernelTestBase {
5757
'link',
5858
'file_link',
5959
'path_alias',
60+
'key',
61+
'apigee_edge',
6062
'apigee_api_catalog',
6163
];
6264

0 commit comments

Comments
 (0)