graphql_compose-1.0.0-beta20/modules/graphql_compose_routes/graphql_compose_routes.module
modules/graphql_compose_routes/graphql_compose_routes.module
<?php
/**
* @file
* Add connection routes to entity bundles.
*/
declare(strict_types=1);
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_graphql_compose_entity_type_form_alter().
*/
function graphql_compose_routes_graphql_compose_entity_type_form_alter(array &$form, FormStateInterface $form_state, EntityTypeInterface $entity_type, string $bundle_id, array $settings): void {
if ($entity_type->hasLinkTemplate('canonical')) {
$form['routes_enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enable loading by route'),
'#default_value' => $settings['routes_enabled'] ?? FALSE,
'#element_validate' => ['::validateNullable'],
'#description' => t('Enable loading this type by URL using the route() query.'),
];
}
}
/**
* Implements hook_config_schema_info_alter().
*/
function graphql_compose_routes_config_schema_info_alter(&$definitions) {
$definitions['graphql_compose.entity.*.*']['mapping']['routes_enabled'] = [
'type' => 'boolean',
'label' => t('Enable routes'),
];
}
/**
* Implements hook_graphql_compose_routes_union_alter().
*/
function graphql_compose_routes_graphql_compose_routes_union_alter($value, ?string &$type): void {
if (\Drupal::moduleHandler()->moduleExists('redirect') && get_class($value) === 'Drupal\redirect\Entity\Redirect') {
$type = 'RouteRedirect';
}
}
