Skip to content

Commit

Permalink
Merge pull request #111 from SU-SWS/capx-tamper-rebase
Browse files Browse the repository at this point in the history
HSDO-641 CAPx Tamper Functionality
  • Loading branch information
sherakama authored Dec 21, 2016
2 parents 04416c9 + 279eea4 commit b30015e
Show file tree
Hide file tree
Showing 13 changed files with 1,447 additions and 4 deletions.
6 changes: 5 additions & 1 deletion includes/CAPx/Drupal/Mapper/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function execute($entity, $data) {
// Always attach the profileId to the entity
$raw = $entity->value();
$raw->capx['profileId'] = $data['profileId'];
$raw->capxMapper = $this;
$entity->set($raw);

// Store this for later.
Expand Down Expand Up @@ -100,6 +101,7 @@ public function mapFields($data) {
/** @var \EntityDrupalWrapper $entity */
$entity = $this->getEntity();
$error = FALSE;
$d = $data;

// Loop through each field and run a field processor on it.
foreach ($config['fields'] as $fieldName => $remoteDataPaths) {
Expand All @@ -111,7 +113,7 @@ public function mapFields($data) {
if ($fieldInfoInstance) {
$info = array();

drupal_alter('capx_pre_map_field', $entity, $fieldName, $remoteDataPaths);
drupal_alter('capx_pre_map_field', $entity, $fieldName, $remoteDataPaths, $data);

// Allow just one path as a string.
// @todo For data structures like files we shouldn't convert data path to array.
Expand Down Expand Up @@ -175,6 +177,7 @@ public function mapFields($data) {
drupal_alter('capx_post_map_field', $entity, $fieldName);
}
}
$data = $d;
}

// Set the entity again for changes.
Expand Down Expand Up @@ -205,6 +208,7 @@ public function mapProperties($data) {

// Loop through each property and run a property processor on it.
foreach ($config['properties'] as $propertyName => $remoteDataPath) {
drupal_alter('capx_pre_property_set', $entity, $data, $propertyName);
try {
$info = $this->getRemoteDataByJsonPath($data, $remoteDataPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function put($data) {

$data = is_array($data) ? array_shift($data) : $data;

drupal_alter('capx_pre_property_set', $entity, $data, $propertyName);

if (empty($data)) {
// @todo Do we really need to log this?
$this->logIssue(new \Exception(t('Got empty property value.')));
Expand Down
96 changes: 96 additions & 0 deletions modules/capx_tamper/CapxTamper.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* @file
* CAPx Tamper classes to fake feeds importer.
*/

use \CAPx\Drupal\Entities\CFEntity;

/**
* Class CapxTamper.
*/
class CapxTamper {

/**
* Mapper to use for processing.
*
* @var CFEntity
*/
public $mapper;
public $parser;
public $processor;

/**
* CapxTamper constructor.
*
* @param \CAPx\Drupal\Entities\CFEntity $mapper
* Mapper in use.
*/
public function __construct(CFEntity $mapper, CapxTamperParser $parser, CapxTamperProcessor $processor) {
$this->mapper = $mapper;
$this->parser = $parser;
$this->processor = $processor;
}

}

/**
* Class CapxTamperParser.
*/
class CapxTamperParser {

/**
* Simulates FeedsCSVParser::getMappingSources().
*
* @return bool
* Similar to FeedsCSVParser
*/
public function getMappingSources() {
return FALSE;
}

}

/**
* Class CapxTamperProcessor.
*/
class CapxTamperProcessor {

/**
* Mapper to use for processing.
*
* @var CFEntity
*/
public $mapper;

/**
* CapxTamperProcessor constructor.
*
* @param CFEntity $mapper
* CAPx Mapper to use.
*/
public function __construct(CFEntity $mapper) {
$this->mapper = $mapper;
}

/**
* Passes the available sources & targets.
*
* @return array
* Available sources.
*/
public function getMappings() {
$mapper_sources = capx_tamper_get_mapper_sources($this->mapper);
$sources = array();
foreach ($mapper_sources as $target => $path) {
$sources[] = array(
'source' => $path,
'target' => $target,
'unique' => FALSE,
'language' => LANGUAGE_NONE,
);
}
return $sources;
}

}
20 changes: 20 additions & 0 deletions modules/capx_tamper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stanford CAPx Tampers
#### Version 2.0-dev

CAPx Tampers provide the option to alter the data from the API before saving it to a profile. Much of this functionality is inspired by the feeds_tamper module and additional help can be found at that resource.

## Installation

Install this module like [any other Drupal module](https://www.drupal.org/documentation/install/modules-themes/modules-7).

## Configuration

When enabled please first create a mapper. After the mapper has been created there will be an additional link titled 'Tampers' under the actions in the mapper list page. (/admin/config/capx/mappers). Click on the 'Tampers' link and choose from the options available to create your tampers.

## Troubleshooting

If you are experiencing issues with this module try reverting the feature first. If you are still experiencing issues try posting an issue on the GitHub issues page.

## Contribution / Collaboration

You are welcome to contribute functionality, bug fixes, or documentation to this module. If you would like to suggest a fix or new functionality you may add a new issue to the GitHub issue queue or you may fork this repository and submit a pull request. For more help please see [GitHub's article on fork, branch, and pull requests](https://help.github.com/articles/using-pull-requests)
Loading

0 comments on commit b30015e

Please sign in to comment.