Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ content:
weight: 2
region: content
field_helfi_chart_url:
type: helfi_chart
type: link
label: hidden
settings: { }
settings:
trim_length: 80
url_only: true
url_plain: false
rel: ''
target: ''
third_party_settings: { }
weight: 1
region: content
Expand Down
4 changes: 2 additions & 2 deletions modules/helfi_media_chart/helfi_media_chart.install
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function helfi_media_chart_install($is_syncing) : void {
}

/**
* UHF-9088 Updated translations for media chart.
* UHF-11329 Removed ChartFormatter and use Link formatter instead.
*/
function helfi_media_chart_update_9002(): void {
function helfi_media_chart_update_9003(): void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_media_chart');
}
7 changes: 0 additions & 7 deletions modules/helfi_media_chart/helfi_media_chart.libraries.yml

This file was deleted.

10 changes: 10 additions & 0 deletions modules/helfi_media_chart/helfi_media_chart.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ declare(strict_types=1);

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\helfi_media_chart\Entity\HelfiChart;

/**
* Implements hook_entity_bundle_info_alter().
*/
function helfi_media_chart_entity_bundle_info_alter(array &$bundles): void {
if (isset($bundles['media']['helfi_chart'])) {
$bundles['media']['helfi_chart']['class'] = HelfiChart::class;
}
}

/**
* Implements hook_entity_bundle_field_info_alter().
Expand Down
47 changes: 47 additions & 0 deletions modules/helfi_media_chart/src/Entity/HelfiChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_media_chart\Entity;

use Drupal\helfi_media\Entity\MediaEntityBundle;
use Drupal\media\MediaInterface;

/**
* Bundle class for helfi media chart media entity.
*/
class HelfiChart extends MediaEntityBundle implements MediaInterface {

/**
* Get service provider url.
*
* @return string
* Url of the service provider.
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
public function getServiceUrl(): string {
$chart_url = $this->get('field_helfi_chart_url')
?->first()
?->getString();
$url_parts = parse_url($chart_url);
return $url_parts['scheme'] . "://" . $url_parts['host'];
}

/**
* Get the title of chart.
*
* @return string|null
* The title of the chart.
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
public function getMediaTitle(): ?string {
$title = (string) $this->get('field_helfi_chart_title')
?->first()
?->getString();

return empty($title) ? NULL : $title;
}

}

This file was deleted.

3 changes: 0 additions & 3 deletions modules/helfi_media_chart/templates/chart-iframe.html.twig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests\helfi_media_chart\Kernel\Entity;

use Drupal\helfi_media_chart\Entity\HelfiChart;
use Drupal\KernelTests\KernelTestBase;

/**
* Tests HelfiChart entity bundle class.
*
* @group helfi_media_chart
*/
class HelfiChartTest extends KernelTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'allowed_formats',
'datetime',
'field',
'file',
'helfi_media',
'helfi_media_chart',
'image',
'language',
'link',
'media',
'media_library',
'path',
'system',
'text',
'user',
'views',
];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['system', 'media', 'media_library']);
$this->installEntitySchema('user');
$this->installEntitySchema('media');
$this->installEntitySchema('file');
$this->installSchema('file', ['file_usage']);
$this->installConfig('helfi_media_chart');
}

/**
* Tests Helfi Chart bundle class.
*/
public function testBundleClass() : void {
/** @var \Drupal\media\MediaStorage $storage */
$storage = $this->container->get('entity_type.manager')
->getStorage('media');

$data = [
'uri' => 'https://playground.powerbi.com/sampleReportEmbed',
];

$entity = $storage->create([
'name' => 'test',
'bundle' => 'helfi_chart',
'field_helfi_chart_url' => $data,
]);
$entity->save();
$this->assertInstanceOf(HelfiChart::class, $entity);

$this->assertEquals('https://playground.powerbi.com', $entity->getServiceUrl());
$this->assertNull($entity->getMediaTitle());

$entity->set('field_helfi_chart_title', 'Test title');
$entity->save();

$this->assertEquals('Test title', $entity->getMediaTitle());
}

}
1 change: 1 addition & 0 deletions modules/helfi_test_content/helfi_test_content.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ core_version_requirement: ^9 || ^10
package: HELfi
dependencies:
- default_content:default_content
- helfi_platform_config:hdbt_cookie_banner
- helfi_platform_config:helfi_calculator
- helfi_platform_config:helfi_etusivu_entities
- helfi_platform_config:helfi_paragraphs_image_gallery
Expand Down
46 changes: 46 additions & 0 deletions modules/helfi_test_content/helfi_test_content.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* @file
* Contains installation tasks for helfi_test_content module.
*/

declare(strict_types=1);

/**
* Implements hook_install().
*/
function helfi_test_content_install($is_syncing) : void {
// Do not perform following steps if the module is being installed as part
// of a configuration import.
if ($is_syncing) {
return;
}

/** @var \Drupal\Core\Extension\ModuleHandler $module_handler */
$module_handler = \Drupal::moduleHandler();

// Return if the hdbt_cookie_banner module is not installed.
if (!$module_handler->moduleExists('hdbt_cookie_banner')) {
return;
}

// Install the default configuration for the hdbt_cookie_banner module.
$config_factory = \Drupal::configFactory();
$module_path = \Drupal::service('extension.list.module')
->getPath('hdbt_cookie_banner');
$json_file_path = $module_path . '/assets/json/siteSettingsTemplate.json';

try {
$json_content = file_get_contents($json_file_path);
}
catch (\Throwable $e) {
return;
}

$config = $config_factory->getEditable('hdbt_cookie_banner.settings');
$config
->set('use_custom_settings', TRUE)
->set('site_settings', $json_content)
->save();
}