add suffix to log title when Importing #261

This commit is contained in:
Leo Germani 2019-09-17 21:41:38 -03:00
parent 4b382f84b4
commit 1ab013d6f8
4 changed files with 15 additions and 18 deletions

View File

@ -145,7 +145,7 @@ class Log extends Entity {
* @return void
*/
public function set_title( $value ) {
$this->set_mapped_property( 'title', $value );
$this->set_mapped_property( 'title', apply_filters('tainacan-log-set-title', $value) );
}
/**

View File

@ -41,6 +41,8 @@ class Logs extends Repository {
add_action( 'add_attachment', array( $this, 'insert_attachment' ) );
add_action( 'delete_attachment', array( $this, 'pre_delete_attachment' ) );
add_action( 'delete_post', array( $this, 'delete_attachment' ) );
add_filter('tainacan-log-set-title', [$this, 'filter_log_title']);
}
protected function _get_map() {
@ -412,6 +414,7 @@ class Logs extends Repository {
if ( $creating ) {
$diff['new'] = $unsaved->_toArray();
$has_diff = true;
} else {
$map = $unsaved->get_repository()->get_map();
@ -754,5 +757,13 @@ class Logs extends Repository {
}
}
public function filter_log_title($title) {
if (defined('TAINACAN_DOING_IMPORT') && true === TAINACAN_DOING_IMPORT) {
$_title = __('Importer', 'tainacan');
$title .= " ($_title)";
}
return $title;
}
}

View File

@ -31,6 +31,8 @@ class Background_Importer extends Background_Process {
$data = $batch->data;
$key = $batch->key;
define('TAINACAN_DOING_IMPORT', true);
$className = $data['class_name'];
if (class_exists($className)) {
$object = new $className($data);

View File

@ -159,24 +159,8 @@ abstract class Importer {
}
}
// add_filter('tainacan-entity-set-property', [$this, 'filter_log_title']);
}
// public function filter_log_title($title, $prop, $entity) {
// if ($entity instanceof Entities\Log && $prop == 'title') {
// global $Tainacan_Importer_Handler;
// $importer = $Tainacan_Importer_Handler->get_importer_by_object($this);
// if ($importer && isset($importer['name'])) {
// // translators: %s is the name of the importer. Ex: CSV Importer
// $_title = sprintf( __('%s Importer'), $importer['name'] );
// } else {
// $_title = __('Importer');
// }
// $title .= " ($_title)";
// }
// return $title;
// }
}
public function _to_Array($short = false) {
$return = ['id' => $this->get_id()];