Skip to content
Snippets Groups Projects
Commit 3c766271 authored by jrockowitz's avatar jrockowitz
Browse files

Issue #3455664: Add diagram to relationships

parent b2794fe6
No related branches found
No related tags found
1 merge request!173Resolve #3455862 "Diagram excluded schema properties"
diagram_excluded_schema_properties:
- about
- subjectOf
- relatedLink
- significantLink
about:
- title: 'Schema.org Documentation'
uri: 'https://schema.org/docs/documents.html'
......
......@@ -2,6 +2,12 @@ schemadotorg_report.settings:
type: config_object
label: 'Schema.org Report settings'
mapping:
diagram_excluded_schema_properties:
type: sequence
label: 'Diagram excluded Schema.org properties'
sequence:
type: string
label: 'Diagram excluded Schema.org property'
about:
type: sequence
label: 'About Scheme.org links'
......
<?php
/**
* @file
* Installation hooks for the Schema.org Blueprints Report module.
*/
declare(strict_types=1);
use Drupal\Component\Serialization\Yaml;
/**
* Issue #3455862: Allow diagram to excluded Schema.org properties.
*/
function schemadotorg_report_update_10000(): void {
$module_path = \Drupal::service('extension.list.module')->getPath('schemadotorg_report');
$data = Yaml::decode(file_get_contents($module_path . '/config/install/schemadotorg_report.settings.yml'));
\Drupal::configFactory()
->getEditable('schemadotorg_report.settings')
->set('diagram_excluded_schema_properties', $data['diagram_excluded_schema_properties'])
->save();
}
......@@ -7,6 +7,7 @@
declare(strict_types=1);
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
......@@ -105,3 +106,35 @@ function schemadotorg_report_menu_local_tasks_alter(array &$data, string $route_
$data['tabs'][0]['schemadotorg_report']['#link']['url'] = Url::fromRoute('schemadotorg_report');
}
}
/* ************************************************************************** */
// Schema.org general settings form.
/* ************************************************************************** */
/**
* Implements hook_form_FORM_ID_alter().
*
* @see \Drupal\schemadotorg\Form\SchemaDotOrgSettingsFormBase::afterBuildDetails
* @see \Drupal\schemadotorg\Form\SchemaDotOrgSettingsFormBase::formAlter
*/
function schemadotorg_report_form_schemadotorg_general_settings_form_alter(array &$form, FormStateInterface $form_state): void {
$form['schemadotorg_report'] = [
'#type' => 'details',
'#title' => t('Report settings'),
];
$form['schemadotorg_report']['diagram_excluded_schema_properties'] = [
'#title' => t('Diagram excluded Schema.org properties'),
'#type' => 'schemadotorg_settings',
'#description' => t('Enter Schema.org properties that should not be included in the default relationships diagram.')
. ' '
. t('Excluding Schema.org properties that can reference all content types, will help simplify the default relationships diagram.'),
'#description_link' => 'properties',
'#example' => '
- about
- subjectOf
- relatedLink
- significantLink
',
];
}
......@@ -327,6 +327,13 @@ class SchemaDotOrgReportRelationshipsController extends SchemaDotOrgReportContro
filter: $filter,
);
$relationships = $relationships['hierarchical'] + $relationships['relationship'];
// If there are no filters (a.k.a., query), exclude some Schema.org
// properties from the default diagram.
if (empty($filter)) {
$relationships = array_diff($relationships, $this->getDiagramExcludedSchemaProperties());
}
foreach ($relationships as $field_name => $schema_property) {
$field_definition = $field_definitions[$field_name];
$target_bundles = array_keys($this->getTargets($field_definition));
......
......@@ -114,30 +114,42 @@ class SchemaDotOrgReportRelationshipsFilterForm extends FormBase {
// Limit diagram relationship types to only hierarchy and relationships.
if ($display === 'diagram') {
$relationship_types = array_intersect_key(
$relationship_types,
$relationships = array_intersect_key(
$relationships,
array_flip(['hierarchical', 'relationship'])
);
}
foreach ($relationship_types as $relationship_type => $relationship_type_label) {
$relationship_options = $relationships[$relationship_type] ?? NULL;
if ($relationship_options) {
$relationship_options = array_combine($relationship_options, $relationship_options);
ksort($relationship_options);
$form['filter'][$relationship_type] = [
'#type' => 'select',
'#title' => $relationship_type_label['plural'],
'#multiple' => TRUE,
'#options' => $relationship_options,
'#default_value' => ($query)
? $query[$relationship_type] ?? []
: $relationship_options,
'#attributes' => [
'data-placeholder' => $this->t('Select @label', ['@label' => $relationship_type_label['plural']]),
],
];
foreach ($relationships as $relationship_type => $relationship_options) {
$relationship_type_label = $relationship_types[$relationship_type];
$relationship_options = array_combine($relationship_options, $relationship_options);
ksort($relationship_options);
if ($query) {
$relationship_default_value = $query[$relationship_type] ?? [];
}
else {
$relationship_default_value = $relationship_options;
// If there is no query (a.k.a, filters), exclude some Schema.org
// properties from the relationship default values for the diagram.
if ($display === 'diagram') {
$relationship_default_value = array_diff(
$relationship_default_value,
$this->getDiagramExcludedSchemaProperties()
);
}
}
$form['filter'][$relationship_type] = [
'#type' => 'select',
'#title' => $relationship_type_label['plural'],
'#multiple' => TRUE,
'#options' => $relationship_options,
'#default_value' => $relationship_default_value,
'#attributes' => [
'data-placeholder' => $this->t('Select @label', ['@label' => $relationship_type_label['plural']]),
],
];
}
$form['filter']['submit'] = [
'#type' => 'submit',
......
......@@ -83,6 +83,17 @@ trait SchemaDotOrgReportRelationshipsTrait {
];
}
/**
* Get Schema.org properties initially excluded from diagram relationships.
*
* @return string[]
* Schema.org properties initially excluded from diagram relationships.
*/
protected function getDiagramExcludedSchemaProperties(): array {
return $this->config('schemadotorg_report.settings')
->get('diagram_excluded_schema_properties') ?? [];
}
/**
* Gets the relationships based on a Schema.org mapping.
*
......
......@@ -33,10 +33,15 @@ class SchemaDotOrgReportSettingsFormTest extends SchemaDotOrgBrowserTestBase {
* Test Schema.org report settings form.
*/
public function testSchemaDotOrgReportSettingsForm(): void {
$this->assertSaveSettingsConfigForm(
'schemadotorg_report.settings',
'/admin/config/schemadotorg/settings/general'
);
$this->assertSaveSettingsConfigForm(
'schemadotorg_report.settings',
'/admin/config/schemadotorg/settings/references'
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment