-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #899 from City-of-Helsinki/UHF-11329
UHF-11329 Chart refactor
- Loading branch information
Showing
11 changed files
with
194 additions
and
133 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
modules/helfi_media_chart/assets/js/helfi-charts-cookie-compliance.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
84 changes: 0 additions & 84 deletions
84
modules/helfi_media_chart/src/Plugin/Field/FieldFormatter/ChartFormatter.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
modules/helfi_media_chart/tests/src/Kernel/Entity/HelfiChartTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |