Skip to content

Commit ee165e2

Browse files
authored
Merge pull request #97 from arlina-espinoza/95-update-error
[#95] Fix update error from 8.x-1.x
2 parents 218f0d5 + aa90b93 commit ee165e2

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

src/Entity/ApiDoc.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
* "views_data" = "Drupal\views\EntityViewsData",
4646
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
4747
* "access" = "Drupal\apigee_api_catalog\Entity\Access\ApiDocAccessControlHandler",
48+
* "route_provider" = {
49+
* "html" = "Drupal\apigee_api_catalog\Entity\Routing\ApiDocHtmlRouteProvider",
50+
* "revision" = "Drupal\entity\Routing\RevisionRouteProvider",
51+
* },
4852
* },
4953
* base_table = "apidoc",
5054
* data_table = "apidoc_field_data",
@@ -66,7 +70,19 @@
6670
* "revision_user" = "revision_user",
6771
* "revision_created" = "revision_created",
6872
* "revision_log_message" = "revision_log_message",
69-
* }
73+
* },
74+
* links = {
75+
* "canonical" = "/api/{apidoc}",
76+
* "add-form" = "/admin/content/api/add",
77+
* "edit-form" = "/admin/content/api/{apidoc}/edit",
78+
* "delete-form" = "/admin/content/api/{apidoc}/delete",
79+
* "reimport-spec-form" = "/admin/content/api/{apidoc}/reimport",
80+
* "version-history" = "/admin/content/api/{apidoc}/revisions",
81+
* "revision" = "/admin/content/api/{apidoc}/revisions/{apidoc_revision}/view",
82+
* "revision-revert-form" = "/admin/content/api/{apidoc}/revisions/{apidoc_revision}/revert",
83+
* "collection" = "/admin/content/apis",
84+
* },
85+
* field_ui_base_route = "entity.apidoc.settings"
7086
* )
7187
*/
7288
class ApiDoc extends EditorialContentEntityBase implements ApiDocInterface {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2019 Google Inc.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* version 2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18+
* MA 02110-1301, USA.
19+
*/
20+
21+
namespace Drupal\apigee_api_catalog\Entity\Routing;
22+
23+
use Drupal\apigee_api_catalog\Controller\ApiDocController;
24+
use Drupal\Core\Entity\EntityTypeInterface;
25+
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
26+
use Drupal\Core\StringTranslation\StringTranslationTrait;
27+
use Symfony\Component\Routing\Route;
28+
29+
/**
30+
* Provides routes for API Doc entities.
31+
*
32+
* @deprecated in 2.x and is removed from 3.x. Use the node "apidoc" bundle instead.
33+
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
34+
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
35+
*/
36+
class ApiDocHtmlRouteProvider extends AdminHtmlRouteProvider {
37+
38+
use StringTranslationTrait;
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function getRoutes(EntityTypeInterface $entity_type) {
44+
$collection = parent::getRoutes($entity_type);
45+
46+
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
47+
$collection->add('entity.apidoc.settings', $settings_form_route);
48+
}
49+
50+
if ($apidoc_collection_route = $collection->get('entity.apidoc.collection')) {
51+
$apidoc_collection_route->setDefault('_title', $this->t('@entity_type catalog', ['@entity_type' => $entity_type->getLabel()])->render());
52+
}
53+
54+
if ($reimport_spec_route = $this->getReimportSpecFormRoute($entity_type)) {
55+
$collection->add("entity.apidoc.reimport_spec_form", $reimport_spec_route);
56+
}
57+
58+
return $collection;
59+
}
60+
61+
/**
62+
* Gets the settings form route.
63+
*
64+
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
65+
* The entity type.
66+
*
67+
* @return \Symfony\Component\Routing\Route|null
68+
* The generated route, if available.
69+
*/
70+
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
71+
if (!$entity_type->getBundleEntityType()) {
72+
$route = new Route('admin/structure/apidoc');
73+
$route
74+
->setDefaults([
75+
'_form' => 'Drupal\apigee_api_catalog\Entity\Form\ApiDocSettingsForm',
76+
'_title_callback' => ApiDocController::class . '::title',
77+
])
78+
->setRequirement('_permission', $entity_type->getAdminPermission())
79+
->setOption('_admin_route', TRUE);
80+
81+
return $route;
82+
}
83+
}
84+
85+
/**
86+
* Gets the reimport-spec-form route.
87+
*
88+
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
89+
* The entity type.
90+
*
91+
* @return \Symfony\Component\Routing\Route|null
92+
* The generated route, if available.
93+
*/
94+
protected function getReimportSpecFormRoute(EntityTypeInterface $entity_type) {
95+
$route = new Route($entity_type->getLinkTemplate('reimport-spec-form'));
96+
97+
$route
98+
->setDefaults([
99+
'_entity_form' => "apidoc.reimport_spec",
100+
'_title' => 'Re-import API Doc OpenAPI specification',
101+
])
102+
->setRequirement('_entity_access', "apidoc.reimport")
103+
->setOption('parameters', [
104+
'apidoc' => ['type' => 'entity:apidoc'],
105+
]);
106+
107+
// Entity types with serial IDs can specify this in their route
108+
// requirements, improving the matching process.
109+
if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
110+
$route->setRequirement('apidoc', '\d+');
111+
}
112+
113+
return $route;
114+
}
115+
116+
}

0 commit comments

Comments
 (0)