Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix voting widget on featured legislation #228

Merged
merged 9 commits into from
Sep 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ mode: default
content:
field_featured_legislation:
type: entity_reference_revisions_entity_view
label: above
label: hidden
settings:
view_mode: default
link: ''
third_party_settings: { }
weight: 0
region: content
hidden:
entity_print_view_epub: true
entity_print_view_pdf: true
entity_print_view_word_docx: true
langcode: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ bundle: committee_featured_legislation
mode: default
content:
field_featured_bill:
type: entity_reference_label
type: entity_reference_entity_view
label: hidden
settings:
link: true
view_mode: featured_content
link: false
third_party_settings: { }
weight: 0
region: content
Expand All @@ -37,4 +38,7 @@ content:
weight: 1
region: content
hidden:
entity_print_view_epub: true
entity_print_view_pdf: true
entity_print_view_word_docx: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ bundle: featured_legislation
mode: default
content:
field_featured_bill:
type: entity_reference_label
label: above
type: entity_reference_entity_view
label: hidden
settings:
link: true
view_mode: featured_content
link: false
third_party_settings: { }
weight: 0
region: content
field_featured_quote:
type: string
label: above
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 1
region: content
hidden:
entity_print_view_epub: true
entity_print_view_pdf: true
entity_print_view_word_docx: true
search_api_excerpt: true
18 changes: 11 additions & 7 deletions web/modules/custom/nys_accumulator/src/Service/Accumulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\nys_senators\SenatorsHelper;
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand All @@ -34,11 +33,11 @@ class Accumulator implements ContainerInjectionInterface {
protected Connection $database;

/**
* Drupal's Current Request service.
* Symfony's RequestStack service.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected Request $request;
protected RequestStack $requestStack;

/**
* NYS Senators Helper service.
Expand All @@ -50,10 +49,15 @@ class Accumulator implements ContainerInjectionInterface {
/**
* Constructor.
*/
public function __construct(EventDispatcherInterface $dispatcher, Connection $database, RequestStack $request, SenatorsHelper $helper) {
public function __construct(
EventDispatcherInterface $dispatcher,
Connection $database,
RequestStack $requestStack,
SenatorsHelper $helper,
) {
$this->dispatcher = $dispatcher;
$this->database = $database;
$this->request = $request->getCurrentRequest();
$this->requestStack = $requestStack;
$this->helper = $helper;
}

Expand All @@ -76,7 +80,7 @@ public function newEntry(): AccumulatorEntry {
return new AccumulatorEntry(
$this->dispatcher,
$this->database,
$this->request,
$this->requestStack->getCurrentRequest(),
$this->helper
);
}
Expand Down
25 changes: 12 additions & 13 deletions web/modules/custom/nys_senators/src/SenatorsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Drupal\nys_senators\Service\Microsites;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\TermInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand All @@ -33,11 +32,11 @@ class SenatorsHelper {
protected CacheBackendInterface $cache;

/**
* The current request from Drupal's Request Stack service.
* Symfony's RequestStack service.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected Request $request;
protected RequestStack $requestStack;

/**
* NYS Senators Microsites service.
Expand All @@ -53,20 +52,20 @@ class SenatorsHelper {
* The entity type manager service.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The backend cache.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* A request stack service.
* @param \Drupal\nys_senators\Service\Microsites $microsites
* NYS Senators Microsites service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, CacheBackendInterface $cache_backend, RequestStack $request_stack, Microsites $microsites) {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
CacheBackendInterface $cache_backend,
RequestStack $requestStack,
Microsites $microsites,
) {
$this->entityTypeManager = $entity_type_manager;
$this->cache = $cache_backend;
// Adding this condition because for some reason
// it throws an error for anonymous users
// when viewing a bill.
if ($request_stack->getCurrentRequest() !== NULL) {
$this->request = $request_stack->getCurrentRequest();
}
$this->requestStack = $requestStack;
$this->microsites = $microsites;
}

Expand Down Expand Up @@ -111,7 +110,7 @@ public function getMicrositeUrl(Term $senator): string {
* @see static::compileMicrosites()
*/
protected function generateMicrositeUrl(string $name): string {
return $this->request->getSchemeAndHttpHost() .
return $this->requestStack->getCurrentRequest()->getSchemeAndHttpHost() .
'/senators/' . strtolower(str_replace([' ', '.'], ['-', ''], $name));
}

Expand Down
11 changes: 5 additions & 6 deletions web/modules/custom/nys_senators/src/Service/Microsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand Down Expand Up @@ -71,11 +70,11 @@ class Microsites {
protected EntityTypeManagerInterface $entityTypeManager;

/**
* Symphony's Request object.
* Symfony's RequestStack service.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected Request $request;
protected RequestStack $requestStack;

/**
* Constructor.
Expand All @@ -89,7 +88,7 @@ public function __construct(
$this->cache = $cache;
$this->theme = $theme;
$this->entityTypeManager = $entityTypeManager;
$this->request = $requestStack->getCurrentRequest();
$this->requestStack = $requestStack;
}

/**
Expand Down Expand Up @@ -228,7 +227,7 @@ protected function compileMicrosites(): array {
$senator_id = $page->field_senator_multiref->entity->id() ?? 0;
$url_options = [
'absolute' => TRUE,
'base_url' => $this->request->getSchemeAndHttpHost(),
'base_url' => $this->requestStack->getCurrentRequest()->getSchemeAndHttpHost(),
];
$url = $page->toUrl('canonical', $url_options)->toString();
}
Expand Down
Loading
Loading