Skip to content

Commit

Permalink
Clean up code.
Browse files Browse the repository at this point in the history
- Fix lint
- Remove unused code.
  • Loading branch information
markstory committed Aug 7, 2016
1 parent 4d1e37c commit ba06adb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -355,6 +355,7 @@ public function marshalPropertyMap($marshaller, $map, $options)
// match the original form data position.
$entity->errors($errors);
}

return $translations;
}
];
Expand Down
57 changes: 3 additions & 54 deletions src/ORM/Marshaller.php
Expand Up @@ -103,10 +103,12 @@ protected function _buildPropertyMap($data, $options)
}
$new = function ($value, $entity) use ($assoc, $nested) {
$options = $nested + ['associated' => []];

return $this->_marshalAssociation($assoc, $value, $options);
};
$merge = function ($value, $entity) use ($assoc, $nested) {
$options = $nested + ['associated' => []];

return $this->_mergeAssociation($entity->get($assoc->property()), $assoc, $value, $options);
};
$map[$assoc->property()] = isset($options['isMerge']) ? $merge : $new;
Expand Down Expand Up @@ -247,7 +249,7 @@ protected function _validate($data, $options, $isNew)
*/
protected function _prepareDataAndOptions($data, $options)
{
$options += ['validate' => true, 'translations' => true];
$options += ['validate' => true];

$tableName = $this->_table->alias();
if (isset($data[$tableName])) {
Expand Down Expand Up @@ -470,59 +472,6 @@ protected function _loadBelongsToMany($assoc, $ids)
return $this->_loadAssociatedByIds($assoc, $ids);
}

/**
* Call translation merge
*
* @param \Cake\Datasource\EntityInterface $original The original entity
* @param array $data key value list of languages with fields to be merged into the translate entity
* @param array $options list of options
* @return array
*/
protected function _mergeTranslations($original, array $data, array $options = [])
{
$result = $this->_table->mergeTranslations($original, $data, $this, $options);

$errors = [];
if (is_array($result)) {
if ((bool)$result[1]) {
$errors['_translations'] = $result[1];
}
$result = $result[0];
}

return [$result, $errors];
}

/**
* Return if table contains translate behavior or we specificate to use via `translations` options.
*
* ### Options:
*
* - translations: Set to false to disable translations
*
* @param array $options List of options
* @return bool
*/
protected function _hasTranslations(array $options = [])
{
return ($this->_table->behaviors()->hasMethod('mergeTranslations') && (bool)$options['translations']);
}

/**
* Add `_translations` field to `fieldList` $options if it's not present inside
*
* @param array $options List of options
* @return array
*/
protected function _addTranslationsToFieldList(array $options = [])
{
if (!empty($options['fieldList']) && !in_array('_translations', $options['fieldList'])) {
array_push($options['fieldList'], '_translations');
}

return $options;
}

/**
* Merges `$data` into `$entity` and recursively does the same for each one of
* the association names passed in `$options`. When merging associations, if an
Expand Down

0 comments on commit ba06adb

Please sign in to comment.