Skip to content
Snippets Groups Projects
Commit fd1121ca authored by Ashutosh Ahirwal's avatar Ashutosh Ahirwal Committed by Marcin Grabias
Browse files

Issue #3291938 by Ashutosh Ahirwal, akshaydalvi212: Module is not compitable...

Issue #3291938 by Ashutosh Ahirwal, akshaydalvi212: Module is not compitable to Drupal coding standard
parent 13df9cae
Branches
Tags
No related merge requests found
......@@ -38,7 +38,7 @@ function group_domain_group_presave(GroupInterface $group): void {
*/
function group_domain_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle): void {
if (\array_key_exists(PathProcessor::DOMAIN_FIELD_NAME, $fields)) {
// Use the ID as defined in the annotation of the constraint definition
// Use the ID as defined in the annotation of the constraint definition.
$fields[PathProcessor::DOMAIN_FIELD_NAME]->addConstraint('UniqueField');
}
}
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace Drupal\group_domain\Form;
......@@ -11,10 +13,30 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\group_domain\PathProcessor;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the group domain settings form.
*/
final class GroupDomainSettingsForm extends ConfigFormBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private EntityTypeManagerInterface $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
private EntityFieldManagerInterface $entityFieldManager;
/**
* The render cache.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
private CacheBackendInterface $cacheRender;
/**
......@@ -74,7 +96,7 @@ final class GroupDomainSettingsForm extends ConfigFormBase {
'#type' => 'textfield',
'#title' => $this->t('Main domain'),
'#description' => $this->t('Without https://, example: "www.example.com".'),
'#default_value' => $config->get('main_domain')
'#default_value' => $config->get('main_domain'),
];
$form['group_types_behaviour'] = [
......@@ -119,7 +141,7 @@ final class GroupDomainSettingsForm extends ConfigFormBase {
if (count($group_types) === 0) {
$form['info'] = [
'#weight' => -1,
'#markup' => $this->t('There are no group types at the moment.'),
'#markup' => $this->t('There are no group types at the moment.'),
];
$form['actions']['submit']['#disabled'] = TRUE;
return $form;
......@@ -182,7 +204,7 @@ final class GroupDomainSettingsForm extends ConfigFormBase {
'field_storage' => $field_storage_config,
'bundle' => $group_type_id,
'label' => $this->t('Domain'),
'description' => $this->t('Enter domain name without http:// or https:// (www.example.com).')
'description' => $this->t('Enter domain name without http:// or https:// (www.example.com).'),
])->save();
// Build or retrieve the 'default' form mode and add the domain field.
......
......@@ -30,14 +30,44 @@ final class PathProcessor extends CacheCollector implements OutboundPathProcesso
public const IGNORE_MAIN_DOMAIN_OUTBOUND = 'ignore';
public const CONVERT_MAIN_DOMAIN_OUTBOUND = 'convert';
/**
* The main domain.
*
* @var string|null
*/
private ?string $mainDomain;
/**
* Behaviour for different group types from config.
*
* @var mixed[]
*/
private array $groupTypesBehaviour;
/**
* Recursive call flag.
*
* @var bool
*/
private bool $recursiveCall = FALSE;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private EntityTypeManagerInterface $entityTypeManager;
/**
* The path validator service.
*
* @var \Drupal\Core\Path\PathValidatorInterface|null
*/
private ?PathValidatorInterface $pathValidator = NULL;
/**
* Constructs a new PathProcessor object.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
CacheBackendInterface $cache,
......@@ -54,6 +84,9 @@ final class PathProcessor extends CacheCollector implements OutboundPathProcesso
}
/**
* Inbound links process method.
*/
public function processInbound($path, Request $request): string {
if ($request === NULL || $this->recursiveCall) {
return $path;
......@@ -78,6 +111,9 @@ final class PathProcessor extends CacheCollector implements OutboundPathProcesso
return $path;
}
/**
* Outbound links process method.
*/
public function processOutbound($path, &$options = [], ?Request $request = NULL, ?BubbleableMetadata $bubbleable_metadata = NULL): string {
if ($request === NULL) {
return $path;
......@@ -145,12 +181,18 @@ final class PathProcessor extends CacheCollector implements OutboundPathProcesso
return $path instanceof Url;
}
/**
* Path validator setter.
*/
public function setPathValidator(PathValidatorInterface $path_validator): self {
$this->pathValidator = $path_validator;
return $this;
}
/**
* Path validator getter.
*/
private function getPathValidator(): PathValidatorInterface {
if ($this->pathValidator === NULL) {
// Normal dependency injection won't work for path validator as it causes
......@@ -164,6 +206,9 @@ final class PathProcessor extends CacheCollector implements OutboundPathProcesso
return $this->pathValidator;
}
/**
* Resolve cache miss.
*/
protected function resolveCacheMiss($key) {
if (\str_starts_with($key, '/group')) {
$value = $this->getDomainInfoByPath($key);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment