-
Notifications
You must be signed in to change notification settings - Fork 2
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 #122 from City-of-Helsinki/UHF-5512-tpr-unit-highl…
…ights UHF-5512: Add highlight connection support for TPR Units
- Loading branch information
Showing
13 changed files
with
192 additions
and
17 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
sonar.exclusions=tests/** | ||
sonar.cpd.exclusions=src/Fixture/* |
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 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,41 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\helfi_tpr\Field\Connection; | ||
|
||
use Drupal\Component\Utility\Html; | ||
|
||
/** | ||
* Provides a domain object for TPR connection type of HIGHLIGHT. | ||
*/ | ||
final class Highlight extends Connection { | ||
|
||
/** | ||
* The type name. | ||
* | ||
* @var string | ||
*/ | ||
public const TYPE_NAME = 'HIGHLIGHT'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFields(): array { | ||
return [ | ||
'name', | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build(): array { | ||
return [ | ||
'name' => [ | ||
'#markup' => Html::escape($this->get('name')), | ||
], | ||
]; | ||
} | ||
|
||
} |
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 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,59 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\helfi_tpr\Plugin\migrate\process; | ||
|
||
use Drupal\migrate\MigrateExecutableInterface; | ||
use Drupal\migrate\ProcessPluginBase; | ||
use Drupal\migrate\Row; | ||
|
||
/** | ||
* Only include array when element (with a given key) matches a given value. | ||
* | ||
* @MigrateProcessPlugin( | ||
* id = "array_element_equals" | ||
* ) | ||
* | ||
* @code | ||
* opening_hours_connections: | ||
* plugin: array_element_equals | ||
* source: connections | ||
* value: OPENING_HOURS | ||
* key: type | ||
* @endcode | ||
*/ | ||
class ArrayElementEquals extends ProcessPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition) { | ||
if (empty($configuration['value']) && !array_key_exists('value', $configuration)) { | ||
throw new \InvalidArgumentException('ArrayElementEquals plugin is missing value configuration.'); | ||
} | ||
if (empty($configuration['key']) && !array_key_exists('key', $configuration)) { | ||
throw new \InvalidArgumentException('ArrayElementEquals plugin is missing key configuration.'); | ||
} | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) : array { | ||
$matchValue = $this->configuration['value']; | ||
$key = $this->configuration['key']; | ||
|
||
if (empty($value) || !is_array($value)) { | ||
return []; | ||
} | ||
|
||
if (!empty($value[$key]) && $value[$key] === $matchValue) { | ||
return $value; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
} |
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 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 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