-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a generic Boolean migrate process plugin that uses filter_var($va…
…lue, FILTER_VALIDATE_BOOLEAN).
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
modules/core/migrate/src/Plugin/migrate/process/Boolean.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,47 @@ | ||
<?php | ||
|
||
namespace Drupal\farm_migrate\Plugin\migrate\process; | ||
|
||
use Drupal\migrate\MigrateExecutableInterface; | ||
use Drupal\migrate\ProcessPluginBase; | ||
use Drupal\migrate\Row; | ||
|
||
/** | ||
* This plugin converts values to a boolean. | ||
* | ||
* @codingStandardsIgnoreStart | ||
* | ||
* Example usage: | ||
* @code | ||
* destination: | ||
* plugin: 'entity:log' | ||
* process: | ||
* is_movement: | ||
* plugin: boolean | ||
* source: is_movement | ||
* @endcode | ||
* @codingStandardsIgnoreEnd | ||
* | ||
* @MigrateProcessPlugin( | ||
* id = "boolean" | ||
* ) | ||
*/ | ||
class Boolean extends ProcessPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { | ||
|
||
// If the trimmed value is an empty string, return NULL so that the field's | ||
// default value will be used. | ||
if (trim($value) === '') { | ||
return NULL; | ||
} | ||
|
||
// Use PHP's filter_var() with FILTER_VALIDATE_BOOLEAN constant. | ||
return filter_var($value, FILTER_VALIDATE_BOOLEAN); | ||
} | ||
|
||
} |