Skip to content

Commit

Permalink
Update Redia Legacy API, to match code review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasben committed Oct 7, 2024
1 parent a61d7a6 commit 7cb5bc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Url;
use Drupal\dpl_redia_legacy\RediaEvent;
Expand All @@ -23,15 +23,16 @@ class EventsController extends ControllerBase {
*/
public function __construct(
protected FileUrlGeneratorInterface $fileUrlGenerator,
protected DateFormatterInterface $dateFormatter,
) {}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): static {
return new static(
$container->get('file_url_generator')

$container->get('file_url_generator'),
$container->get('date.formatter'),
);
}

Expand Down Expand Up @@ -74,7 +75,7 @@ private function getItems(): array {
$ids = $query->execute();

/** @var \Drupal\recurring_events\Entity\EventInstance[] $events */
$events = $this->entityTypeManager()->getStorage('eventinstance')->loadMultiple($ids);
$events = $storage->loadMultiple($ids);

$items = [];

Expand All @@ -101,8 +102,7 @@ private function buildRss(array $items, Request $request): string {
$feed_url->setAbsolute();
$feed_url = $feed_url->toString();

$current_date = new DrupalDateTime();
$date = $current_date->format('r');
$date = $this->dateFormatter->format(time(), 'custom', 'r');

$rss_feed = <<<RSS
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
2 changes: 2 additions & 0 deletions web/modules/custom/dpl_redia_legacy/src/RediaEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function __construct(EventInstance $event_instance) {
$this->subtitle = $event_wrapper->getField('event_description')?->getString();
$this->startTime = $start_date->format('U');
$this->endTime = $end_date->format('U');
$this->media = NULL;
$this->mediaThumbnail = NULL;

if ($media) {
$this->media = new RediaEventMedia($media, 'redia_feed_large');
Expand Down
14 changes: 7 additions & 7 deletions web/modules/custom/dpl_redia_legacy/src/RediaEventMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class RediaEventMedia extends ControllerBase {
// We'll disable the documentation rules for the member properties, as
// they are pretty self-explanatory.
// phpcs:disable
public ?string $url;
public ?int $size;
public ?int $width;
public ?int $height;
public ?string $type;
public ?string $md5;
public ?string $url = NULL;
public ?int $size = NULL;
public ?int $width = NULL;
public ?int $height = NULL;
public ?string $type = NULL;
public ?string $md5 = NULL;
public string $medium = 'image';
// phpcs:enable

Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(MediaInterface $media, string $image_style) {
$image_sizes = getimagesize($file_uri);
$file_size = filesize($file_uri);

$image_type = exif_imagetype($file_uri);
$image_type = $image_sizes[2] ?? NULL;

if ($image_type) {
$this->type = image_type_to_mime_type($image_type);
Expand Down
2 changes: 1 addition & 1 deletion web/modules/custom/dpl_update/dpl_update.install
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function dpl_update_update_10017(): string {
}

/**
* Install dpl_search module.
* Install dpl_redia_legacy module.
*/
function dpl_update_update_10018(): string {
return _dpl_update_install_modules(['dpl_redia_legacy']);
Expand Down

0 comments on commit 7cb5bc7

Please sign in to comment.