diff --git a/content_model_documentation.routing.yml b/content_model_documentation.routing.yml index 06760115186af7bd9534f0447a84321781bc2ad8..82245d7e18d596d52d36e1668f75bf987a669e51 100644 --- a/content_model_documentation.routing.yml +++ b/content_model_documentation.routing.yml @@ -130,6 +130,12 @@ entity.taxonomy_vocabulary.document: requirements: _permission: 'view content model documentation' +# For showing the documentation tabs on view. +entity.view.document: + path: '/admin/structure/views/view/{view}/document' + requirements: + _permission: 'view content model documentation' + # For showing the documentation tabs on media. entity.media_type.document: path: '/admin/structure/media/manage/{media_type}/document' diff --git a/src/CMDocumentConnectorTrait.php b/src/CMDocumentConnectorTrait.php index 1ffdee9669db94db08b4c205220ec03e96277736..ac843e525d8d9844d3c67531bcd8ab7492b3c14f 100644 --- a/src/CMDocumentConnectorTrait.php +++ b/src/CMDocumentConnectorTrait.php @@ -82,6 +82,11 @@ trait CMDocumentConnectorTrait { } break; + case ($type === 'view'): + $view_id = $bundle; + $alias = "/admin/structure/views/view/{$view_id}/document"; + break; + case ($type === 'node') && (!empty($field)): $alias = "/admin/structure/types/manage/{$bundle}/fields/node.{$bundle}.{$field}/document"; break; @@ -303,6 +308,7 @@ trait CMDocumentConnectorTrait { $documentable_entities['node'] = $config->get('node'); $documentable_entities['paragraph'] = $config->get('paragraph'); $documentable_entities['taxonomy_term'] = $config->get('taxonomy'); + $documentable_entities['view'] = $config->get('view'); // Remove any that are disabled. $documentable_entities = array_filter($documentable_entities); $documentable_entities = array_keys($documentable_entities); diff --git a/src/CMDocumentManager.php b/src/CMDocumentManager.php index 847910a3cc1bfca3839c5e3ad2ffed6d88e260bb..f0d1b0cd91f322db3e0120950dd9a301ccd08b57 100644 --- a/src/CMDocumentManager.php +++ b/src/CMDocumentManager.php @@ -103,6 +103,7 @@ class CMDocumentManager { 'taxonomy_vocabulary' => 'taxonomy_term', 'field_storage_config' => 'base.field', 'field_config' => '', + 'view' => 'view', ]; } diff --git a/src/CmDocumentViewBuilder.php b/src/CmDocumentViewBuilder.php index b973415db8e4a680f035ecdbabd6afa2bc050391..725481b8ddcfa2cfe7c1e9d9b1d8e8dd947c1cfb 100644 --- a/src/CmDocumentViewBuilder.php +++ b/src/CmDocumentViewBuilder.php @@ -92,7 +92,7 @@ class CmDocumentViewBuilder extends EntityViewBuilder { $add_ons = ['AppearsOn', 'BaseField', 'SiblingFields']; break; - case ((empty($field)) && ($type !== 'site') && ($type !== 'module')): + case ((empty($field)) && ($type !== 'site') && ($type !== 'module') && ($type !== 'view')): // This is fieldable entity. $add_ons = ['FieldsOnEntity']; if ($type === 'node' || $type === 'taxonomy_term') { diff --git a/src/DocumentableEntityProvider.php b/src/DocumentableEntityProvider.php index bc66d1270b17cadd143f7c88498887848fb2ffca..e2f3cb6585497256011da269c606a058bfcc3fb2 100644 --- a/src/DocumentableEntityProvider.php +++ b/src/DocumentableEntityProvider.php @@ -96,6 +96,7 @@ class DocumentableEntityProvider extends ServiceProviderBase { $documentable_entities = $this->getModules(); $documentable_entities = array_merge($documentable_entities, $this->getAllDocumentableEntities()); + $documentable_entities = array_merge($documentable_entities, $this->getViews()); $documentable_entities = $this->removeBaseEntities($documentable_entities); asort($documentable_entities, SORT_NATURAL); $documentable_entities = array_merge($documentable_non_entities, $documentable_entities); @@ -135,6 +136,25 @@ class DocumentableEntityProvider extends ServiceProviderBase { return $modules ?? []; } + /** + * Gets the list of views for documenting. + * + * @return array + * An array of unique strings representing views. + */ + protected function getViews(): array { + if ($this->config->get('view')) { + $view_storage = $this->entityTypeManager->getStorage('view'); + $views = $view_storage->loadMultiple(); + $view_ids = []; + foreach ($views as $view) { + $view_ids['view.' . $view->id()] = 'view.' . $view->id(); + } + + } + return $view_ids ?? []; + } + /** * Removes base entities that make no sense to document and other cruft. * diff --git a/src/Entity/CMDocument.php b/src/Entity/CMDocument.php index a8450261f3aa81867fe24d3115eb77f683028931..f36e2a593235f31a28bcb9835b562356fb8427d4 100644 --- a/src/Entity/CMDocument.php +++ b/src/Entity/CMDocument.php @@ -263,6 +263,14 @@ class CMDocument extends EditorialContentEntityBase implements CMDocumentInterfa 'module' => $elements[2] ?? $elements[1] ?? '', ]; + } + if ($documented_entity['type'] === 'view') { + // Realign the parameters to match view. + $documented_entity = [ + 'type' => $elements[0] ?? '', + 'view_id' => $elements[1] ?? '', + ]; + } $return = !empty($documented_entity[$element]) ? $documented_entity[$element] : ''; } @@ -333,6 +341,10 @@ class CMDocument extends EditorialContentEntityBase implements CMDocumentInterfa $module = $this->getDocumentedEntityParameter('module'); $alias = $this->getCmDocumentPath($type, $project, $module); } + elseif ($type === 'view') { + $view_id = $this->getDocumentedEntityParameter('view_id'); + $alias = $this->getCmDocumentPath($type, $view_id); + } else { $bundle = $this->getDocumentedEntityParameter('bundle'); $field = $this->getDocumentedEntityParameter('field'); diff --git a/src/Form/CMDocumentForm.php b/src/Form/CMDocumentForm.php index 8146eb4f6a74a17b4364d78e5de75adf78486d85..6ef531f012d1057f30dd55fdb0c510fa8f4cc1f1 100644 --- a/src/Form/CMDocumentForm.php +++ b/src/Form/CMDocumentForm.php @@ -236,6 +236,12 @@ class CMDocumentForm extends ContentEntityForm { return "Base field: {$fieldname}"; } + elseif ($entity_type === 'view') { + $view_id = $document->getDocumentedEntityParameter('view_id'); + $view_storage = $this->entityTypeManager->getStorage('view'); + $view = $view_storage->load($view_id); + return "View: {$view->label()}"; + } else { // This is a real entity. $bundlename = $document->getDocumentedEntityParameter('bundle'); diff --git a/src/Form/ContentModelDocumentationConfigForm.php b/src/Form/ContentModelDocumentationConfigForm.php index b91e23eabdd8ac049a8c693bba11f452c13ba9d8..79bcd80fed0a2249a93e41a29a1bc771b9177c79 100644 --- a/src/Form/ContentModelDocumentationConfigForm.php +++ b/src/Form/ContentModelDocumentationConfigForm.php @@ -79,6 +79,7 @@ class ContentModelDocumentationConfigForm extends ConfigFormBase { $documentable_entities['node'] = $this->moduleHandler->moduleExists('node'); $documentable_entities['paragraph'] = $this->moduleHandler->moduleExists('paragraphs'); $documentable_entities['taxonomy'] = $this->moduleHandler->moduleExists('taxonomy'); + $documentable_entities['view'] = $this->moduleHandler->moduleExists('views'); return $documentable_entities; } diff --git a/src/Plugin/Derivative/DocumentLocalTab.php b/src/Plugin/Derivative/DocumentLocalTab.php index 0a29f51236ef4b3bf77331b6571d43fc911429a1..accb3133243a7a209a9ba601888ac66c522ea5dd 100644 --- a/src/Plugin/Derivative/DocumentLocalTab.php +++ b/src/Plugin/Derivative/DocumentLocalTab.php @@ -180,6 +180,10 @@ class DocumentLocalTab extends DeriverBase implements ContainerDeriverInterface // Vocabulary edit /admin/structure/taxonomy/manage/VOCABULARYNAME. $base_route = "entity.{$base_entity_type_id}.overview_form"; break; + + case ($entity_type === 'view'): + $base_route = 'entity.view.edit_form'; + break; } return $base_route ?? '';