Skip to content

Commit

Permalink
Merge pull request #264 from localgovdrupal/1.x
Browse files Browse the repository at this point in the history
PR for 1.6.0
  • Loading branch information
andybroomfield authored Jul 6, 2023
2 parents 7e88fc6 + c675bc8 commit 95d559c
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 44 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"minimum-stability": "dev",
"license": "GPL-2.0-or-later",
"require": {
"drupal/condition_field": "^2.0"
"drupal/condition_field": "^2.0",
"drupal/core": "^9.4 || ^10.0"
},
"require-dev": {
"drupal/scheduled_transitions": "^2.1"
Expand Down
2 changes: 1 addition & 1 deletion localgov_alert_banner.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'LocalGov Alert Banner'
type: module
description: 'Provides a sitewide alert banner for urgent alerts.'
core_version_requirement: ^8.8 || ^9 || ^10
core_version_requirement: ^9.4 || ^10
package: LocalGov Drupal
dependencies:
- drupal:block
Expand Down
2 changes: 1 addition & 1 deletion localgov_alert_banner.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Symfony\Component\Yaml\Yaml;
use Drupal\user\RoleInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Implements hook_install().
Expand Down
2 changes: 1 addition & 1 deletion localgov_alert_banner.page.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Page callback for Alert banner entities.
*/

use Drupal\Core\Render\Element;
use Drupal\Core\Link;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;

/**
Expand Down
2 changes: 1 addition & 1 deletion localgov_alert_banner.permissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ manage all localgov alert banner entities:

# Per bundle permissions.
permission_callbacks:
- \Drupal\localgov_alert_banner\AlertBannerEntityPermissions::generatePermissions
- \Drupal\localgov_alert_banner\AlertBannerEntityPermissions::alertBannerTypePermissions
4 changes: 2 additions & 2 deletions src/Access/AlertBannerEntityPageAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Drupal\localgov_alert_banner\Access;

use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;

/**
* Checks access to alert banner entity pages.
Expand Down
2 changes: 1 addition & 1 deletion src/AlertBannerEntityAccessControlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Drupal\localgov_alert_banner;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;

/**
* Access controller for the Alert banner entity.
Expand Down
53 changes: 42 additions & 11 deletions src/AlertBannerEntityPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,64 @@

namespace Drupal\localgov_alert_banner;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\BundlePermissionHandlerTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntityType;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides dynamic permissions for Alert banner of different types.
*
* @ingroup localgov_alert_banner
*/
class AlertBannerEntityPermissions {
class AlertBannerEntityPermissions implements ContainerInjectionInterface {

use BundlePermissionHandlerTrait;
use StringTranslationTrait;

/**
* Returns an array of node type permissions.
* The entity type manager service.
*
* @return array
* The AlertBannerEntity by bundle permissions.
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
public function generatePermissions() {
$perms = [];
protected $entityTypeManager;

foreach (AlertBannerEntityType::loadMultiple() as $type) {
$perms += $this->buildPermissions($type);
}
/**
* Alert banner permissions constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity_type.manager'));
}

return $perms;
/**
* Returns an array of alert banner type permissions.
*
* @return array
* The alert banner type permissions.
*
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function alertBannerTypePermissions() {
// Generate media permissions for all media types.
$alert_banner_types = $this->entityTypeManager
->getStorage('localgov_alert_banner_type')
->loadMultiple();
return $this->generatePermissions($alert_banner_types, [
$this,
'buildPermissions',
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AlertBannerEntityStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Drupal\localgov_alert_banner;

use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntityInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AlertBannerEntityStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Drupal\localgov_alert_banner;

use Drupal\Core\Entity\ContentEntityStorageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntityInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AlertBannerEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down
6 changes: 3 additions & 3 deletions src/Entity/AlertBannerEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Drupal\condition_field\ConditionAccessResolver;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\EditorialContentEntityBase;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityPublishedTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\user\UserInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/AlertBannerEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Drupal\localgov_alert_banner\Entity;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\user\EntityOwnerInterface;

/**
Expand Down
14 changes: 8 additions & 6 deletions src/Entity/AlertBannerEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\workflows\Entity\Workflow;
use Drupal\user\RoleInterface;
use Drupal\workflows\Entity\Workflow;

/**
* Defines the Alert banner type entity.
Expand All @@ -26,6 +26,7 @@
* },
* "route_provider" = {
* "html" = "Drupal\localgov_alert_banner\AlertBannerEntityTypeHtmlRouteProvider",
* "permissions" = "Drupal\user\Entity\EntityPermissionsRouteProvider",
* },
* },
* config_prefix = "localgov_alert_banner_type",
Expand All @@ -41,11 +42,12 @@
* "label"
* },
* links = {
* "canonical" = "/admin/structure/alert-banner-types/localgov_alert_banner_type/{localgov_alert_banner_type}",
* "add-form" = "/admin/structure/alert-banner-types/localgov_alert_banner_type/add",
* "edit-form" = "/admin/structure/alert-banner-types/localgov_alert_banner_type/{localgov_alert_banner_type}/edit",
* "delete-form" = "/admin/structure/alert-banner-types/localgov_alert_banner_type/{localgov_alert_banner_type}/delete",
* "collection" = "/admin/structure/alert-banner-types/localgov_alert_banner_type"
* "canonical" = "/admin/structure/alert-banner-types/{localgov_alert_banner_type}",
* "add-form" = "/admin/structure/alert-banner-types/add",
* "edit-form" = "/admin/structure/alert-banner-types/{localgov_alert_banner_type}/edit",
* "delete-form" = "/admin/structure/alert-banner-types/{localgov_alert_banner_type}/delete",
* "entity-permissions-form" = "/admin/structure/alert-banner-types/{localgov_alert_banner_type}/permissions",
* "collection" = "/admin/structure/alert-banner-types"
* }
* )
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Form/AlertBannerEntityStatusForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\localgov_alert_banner\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntity;
use Drupal\localgov_alert_banner\Entity\AlertBannerEntityInterface;

Expand Down
8 changes: 4 additions & 4 deletions src/Plugin/Block/AlertBannerBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Drupal\localgov_alert_banner\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Block\BlockBase;
use Drupal\field\Entity\FieldStorageConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides the Alert banner block.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/AdminViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\Tests\localgov_alert_banner\Functional;

use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Url;

/**
* Functional tests for LocalGovDrupal Alert banner admin view.
Expand Down
10 changes: 5 additions & 5 deletions tests/src/Functional/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Drupal\Tests\localgov_alert_banner\Functional;

use Drupal\Tests\BrowserTestBase;
use Symfony\Component\HttpFoundation\Response;
use Drupal\user\RoleInterface;
use Symfony\Component\HttpFoundation\Response;

/**
* Functional tests for LocalGovDrupal Alert banner permissions.
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testAlertBannerUserAccess() {
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);

// Check that anonymous user cannot access the alert banner types.
$this->drupalGet('admin/structure/alert-banner-types/localgov_alert_banner_type');
$this->drupalGet('admin/structure/alert-banner-types');
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);

$normalAdminUser = $this->createUser(['access administration pages']);
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testAlertBannerUserAccess() {
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);

// Check that authenticated user cannot access the alert banner types.
$this->drupalGet('admin/structure/alert-banner-types/localgov_alert_banner_type');
$this->drupalGet('admin/structure/alert-banner-types');
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);

$this->drupalLogout();
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testAlertBannerUserAccess() {
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);

// Check that emergency publisher user cannot access the alert banner types.
$this->drupalGet('admin/structure/alert-banner-types/localgov_alert_banner_type');
$this->drupalGet('admin/structure/alert-banner-types');
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);

$this->drupalLogout();
Expand Down Expand Up @@ -229,7 +229,7 @@ public function testAlertBannerUserAccess() {
$this->drupalLogin($adminUser);

// Check that the admin user can access the alert banner types.
$this->drupalGet('admin/structure/alert-banner-types/localgov_alert_banner_type');
$this->drupalGet('admin/structure/alert-banner-types');
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);

// Check user access of the banner itself can be restricted.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/SchedulingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Drupal\Core\Extension\MissingDependencyException;
use Drupal\KernelTests\KernelTestBase;
use Drupal\scheduled_transitions\Entity\ScheduledTransition;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\scheduled_transitions\Entity\ScheduledTransition;

/**
* Kernel test for scheduling transitions.
Expand Down

0 comments on commit 95d559c

Please sign in to comment.