Skip to content

Commit

Permalink
[FEATURE] Add ModifySoundcloudOutputEvent
Browse files Browse the repository at this point in the history
Related #2
  • Loading branch information
ayacoo committed Oct 29, 2023
1 parent db4545d commit 74f1472
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Classes/Event/ModifySoundcloudOutputEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Ayacoo\AyacooSoundcloud\Event;

final class ModifySoundcloudOutputEvent
{
public function __construct(
protected string $output = ''
)
{
}

public function getOutput(): string
{
return $this->output;
}

public function setOutput(string $output): void
{
$this->output = $output;
}
}
13 changes: 12 additions & 1 deletion Classes/Rendering/SoundcloudRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Ayacoo\AyacooSoundcloud\Rendering;

use Ayacoo\AyacooSoundcloud\Event\ModifySoundcloudOutputEvent;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\FileReference;
Expand All @@ -17,6 +19,12 @@
*/
class SoundcloudRenderer implements FileRendererInterface
{
public function __construct(
private readonly EventDispatcherInterface $eventDispatcher
) {

}

/**
* @var OnlineMediaHelperInterface|false
*/
Expand Down Expand Up @@ -49,7 +57,10 @@ public function canRender(FileInterface $file)

public function render(FileInterface $file, $width, $height, array $options = [], $usedPathsRelativeToCurrentScript = false)
{
return $file->getProperty('soundcloud_html') ?? '';
$modifySoundcloudOutputEvent = $this->eventDispatcher->dispatch(
new ModifySoundcloudOutputEvent($file->getProperty('soundcloud_html') ?? '')
);
return $modifySoundcloudOutputEvent->getOutput();
}

/**
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,48 @@ Run the following command within your [Composer][1] based TYPO3 project:
composer require ayacoo/ayacoo-soundcloud
```

And as database fields are added, the DB Analyzer must also be run once.

### 2.2 Hints

#### Output

For the output, the HTML is used directly from [Soundcloud][4].

#### ModifySoundcloudOutputEvent

If you want to modify the output of the Soundcloud HTML, you can use the `ModifySoundcloudOutputEvent`.

##### EventListener registration

In your extension, extend `Configuration/Services.yaml` once:

```yaml
Vendor\ExtName\EventListener\SoundcloudOutputEventListener:
tags:
- name: event.listener
identifier: 'soundcloud/output'
event: Ayacoo\AyacooSoundcloud\Event\ModifySoundcloudOutputEvent
```
```php
<?php

namespace Vendor\ExtName\EventListener;

use Ayacoo\AyacooSoundcloud\Event\ModifySoundcloudOutputEvent;

class SoundcloudOutputEventListener
{
public function __invoke(ModifySoundcloudOutputEvent $event): void
{
$output = $event->getOutput();
$output = str_replace('src', 'data-src', $output);
$event->setOutput($output);
}
}
```

#### SQL changes

In order not to have to access the oEmbed interface permanently, four fields are
Expand Down

0 comments on commit 74f1472

Please sign in to comment.