Skip to content
Snippets Groups Projects
Commit b63d14ef authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Issue #3449070 by kristiaanvandeneynde: Clean up code before full release

parent 51fd694e
No related branches found
No related tags found
1 merge request!4Updated code according to latest standards (where possible)
Pipeline #179191 passed
......@@ -16,7 +16,7 @@ use Symfony\Component\Validator\ConstraintViolation;
/**
* Implements hook_entity_type_alter().
*/
function group_context_domain_entity_type_alter(array &$entity_types) {
function group_context_domain_entity_type_alter(array &$entity_types): void {
assert($entity_types['domain'] instanceof EntityTypeInterface);
$entity_types['domain']->addConstraint('DomainGroupUnique');
}
......@@ -24,7 +24,7 @@ function group_context_domain_entity_type_alter(array &$entity_types) {
/**
* Implements hook_form_FORM_ID_alter().
*/
function group_context_domain_form_domain_form_alter(&$form, FormStateInterface $form_state, $form_id) {
function group_context_domain_form_domain_form_alter(&$form, FormStateInterface $form_state, $form_id): void {
$cacheable_metadata = (new CacheableMetadata())->addCacheContexts(['user.permissions']);
$cacheable_metadata->applyTo($form);
......@@ -65,7 +65,7 @@ function group_context_domain_form_domain_form_alter(&$form, FormStateInterface
/**
* Entity builder for the domain entity.
*/
function _group_context_domain_save_group_uuid($entity_type, $entity, &$form, FormStateInterface $form_state) {
function _group_context_domain_save_group_uuid($entity_type, $entity, &$form, FormStateInterface $form_state): void {
if ($group_uuid = $form_state->getValue('group_uuid')) {
$entity->setThirdPartySetting('group_context_domain', 'group_uuid', $group_uuid);
}
......@@ -77,7 +77,7 @@ function _group_context_domain_save_group_uuid($entity_type, $entity, &$form, Fo
/**
* Form validate handler.
*/
function _group_context_domain_validate_group_uuid(&$form, FormStateInterface $form_state) {
function _group_context_domain_validate_group_uuid(&$form, FormStateInterface $form_state): void {
$form_object = $form_state->getFormObject();
assert($form_object instanceof EntityForm);
......
......@@ -6,7 +6,7 @@ use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\domain\DomainNegotiatorInterface;
use Drupal\group_context_domain\Context\GroupFromDomainContextTrait;
use Drupal\group_context_domain\GroupFromDomainContextTrait;
/**
* Defines a cache context for "per group from domain" caching.
......@@ -17,17 +17,10 @@ class DomainGroupCacheContext implements CacheContextInterface {
use GroupFromDomainContextTrait;
/**
* Constructs a new DomainGroupCacheContext.
*
* @param \Drupal\domain\DomainNegotiatorInterface $domain_negotiator
* The domain negotiator.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(DomainNegotiatorInterface $domain_negotiator, EntityRepositoryInterface $entity_repository) {
$this->domainNegotiator = $domain_negotiator;
$this->entityRepository = $entity_repository;
public function __construct(
protected DomainNegotiatorInterface $domainNegotiator,
protected EntityRepositoryInterface $entityRepository,
) {
}
/**
......
......@@ -11,6 +11,7 @@ use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\domain\DomainNegotiatorInterface;
use Drupal\group_context_domain\GroupFromDomainContextTrait;
/**
* Sets the group tied to the domain as a context.
......@@ -20,19 +21,11 @@ class GroupFromDomainContext implements ContextProviderInterface {
use GroupFromDomainContextTrait;
use StringTranslationTrait;
/**
* Constructs a new GroupFromDomainContext.
*
* @param \Drupal\domain\DomainNegotiatorInterface $domain_negotiator
* The domain negotiator.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(DomainNegotiatorInterface $domain_negotiator, EntityRepositoryInterface $entity_repository, TranslationInterface $string_translation) {
$this->domainNegotiator = $domain_negotiator;
$this->entityRepository = $entity_repository;
public function __construct(
protected DomainNegotiatorInterface $domainNegotiator,
protected EntityRepositoryInterface $entityRepository,
TranslationInterface $string_translation,
) {
$this->stringTranslation = $string_translation;
}
......
<?php
namespace Drupal\group_context_domain\Context;
declare(strict_types=1);
namespace Drupal\group_context_domain;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\domain\DomainNegotiatorInterface;
......@@ -22,14 +24,14 @@ trait GroupFromDomainContextTrait {
*
* @var \Drupal\domain\DomainNegotiatorInterface
*/
protected $domainNegotiator;
protected DomainNegotiatorInterface $domainNegotiator;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
protected EntityRepositoryInterface $entityRepository;
/**
* Gets the domain negotiator.
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Functional;
use Drupal\Tests\group\Functional\GroupBrowserTestBase;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Functional;
use Drupal\domain\DomainInterface;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Kernel;
use Drupal\Core\StringTranslation\TranslatableMarkup;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Kernel;
use Drupal\Tests\group\Kernel\GroupKernelTestBase;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Kernel;
use Drupal\Core\Plugin\Context\EntityContext;
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Traits;
use Drupal\domain\DomainInterface;
/**
* Functionality trait for a group_membership bundle class.
*/
......@@ -20,10 +24,10 @@ trait GroupContextDomainTestTrait {
* @param array $values
* (optional) The values used to create the entity.
*
* @return \Drupal\domain\Entity\Domain
* @return \Drupal\domain\DomainInterface
* The created domain entity.
*/
protected function createDomain(array $values = []) {
protected function createDomain(array $values = []): DomainInterface {
$storage = $this->entityTypeManager->getStorage('domain');
$domain = $storage->create($values + [
'id' => $this->randomMachineName(),
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\group_context_domain\Unit;
use Drupal\Core\Cache\CacheableMetadata;
......@@ -57,7 +59,7 @@ class DomainGroupCacheContextTest extends UnitTestCase {
*
* @covers ::getContext
*/
public function testGetContextNoDomain() {
public function testGetContextNoDomain(): void {
$this->domainNegotiator->getActiveDomain()->willReturn(NULL);
$this->assertSame('group.none', $this->cacheContext->getContext());
}
......@@ -67,7 +69,7 @@ class DomainGroupCacheContextTest extends UnitTestCase {
*
* @covers ::getContext
*/
public function testGetContextNoDomainGroup() {
public function testGetContextNoDomainGroup(): void {
$domain = $this->prophesize(DomainInterface::class);
$this->domainNegotiator->getActiveDomain()->willReturn($domain->reveal());
$domain->getThirdPartySetting('group_context_domain', 'group_uuid')->willReturn(NULL);
......@@ -79,7 +81,7 @@ class DomainGroupCacheContextTest extends UnitTestCase {
*
* @covers ::getContext
*/
public function testGetContext() {
public function testGetContext(): void {
$domain = $this->prophesize(DomainInterface::class);
$domain->getThirdPartySetting('group_context_domain', 'group_uuid')->willReturn('foo');
$this->domainNegotiator->getActiveDomain()->willReturn($domain->reveal());
......@@ -96,7 +98,7 @@ class DomainGroupCacheContextTest extends UnitTestCase {
*
* @covers ::getCacheableMetadata
*/
public function testGetCacheableMetadataNoDomain() {
public function testGetCacheableMetadataNoDomain(): void {
$this->domainNegotiator->getActiveDomain()->willReturn(NULL);
$this->assertEquals(new CacheableMetadata(), $this->cacheContext->getCacheableMetadata());
}
......@@ -106,7 +108,7 @@ class DomainGroupCacheContextTest extends UnitTestCase {
*
* @covers ::getCacheableMetadata
*/
public function testGetCacheableMetadata() {
public function testGetCacheableMetadata(): void {
$cache_context_manager = $this->prophesize(CacheContextsManager::class);
$cache_context_manager->assertValidTokens(Argument::any())->willReturn(TRUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment