feat: add action `tainacan-insert-tainacan-item` and `tainacan-pre-insert-tainacan-item` #144
This commit is contained in:
parent
d9da6bae70
commit
f855a57cee
|
@ -344,7 +344,6 @@ class Metadata extends Repository {
|
|||
|
||||
$args = apply_filters( 'tainacan_fetch_args', $args, 'metadata' );
|
||||
|
||||
error_log(json_encode($args));
|
||||
|
||||
$wp_query = new \WP_Query( $args );
|
||||
|
||||
|
|
|
@ -128,9 +128,10 @@ abstract class Repository {
|
|||
$old = '';
|
||||
|
||||
$diffs = [];
|
||||
|
||||
do_action( 'tainacan-pre-insert', $obj );
|
||||
do_action( 'tainacan-pre-insert-' . $obj->get_post_type(), $obj );
|
||||
$obj_post_type = $obj->get_post_type();
|
||||
if( $obj_post_type != false )
|
||||
do_action( "tainacan-pre-insert-$obj_post_type", $obj );
|
||||
|
||||
$map = $this->get_map();
|
||||
|
||||
|
@ -159,6 +160,8 @@ abstract class Repository {
|
|||
|
||||
$post_t = $collection->get_db_identifier();
|
||||
$obj->WP_Post->post_type = $post_t;
|
||||
$obj_post_type = 'tainacan-item';
|
||||
do_action( "tainacan-pre-insert-$obj_post_type", $obj );
|
||||
}
|
||||
|
||||
// TODO verificar se salvou mesmo
|
||||
|
@ -176,7 +179,9 @@ abstract class Repository {
|
|||
update_post_meta( $id, '_user_edit_lastr', get_current_user_id() );
|
||||
|
||||
do_action( 'tainacan-insert', $obj, $diffs, $is_update );
|
||||
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
|
||||
if( $obj_post_type != false ) {
|
||||
do_action( "tainacan-insert-$obj_post_type", $obj );
|
||||
}
|
||||
|
||||
// return a brand new object
|
||||
return new $this->entities_type( $obj->WP_Post );
|
||||
|
|
|
@ -23,17 +23,15 @@ class Control extends Metadata_Type {
|
|||
'control_metadatum_options' => ['document_type', 'collection_id'],
|
||||
'control_metadatum' => 'document_type'
|
||||
]);
|
||||
add_action( 'tainacan-api-item-updated', [&$this, 'update_control_metadatum'], 10, 2 );
|
||||
add_action( 'tainacan-insert-tainacan-item', array( $this, 'update_control_metadatum' ), 10, 1 );
|
||||
}
|
||||
|
||||
public function update_control_metadatum( \Tainacan\Entities\Item $item, $attributes) {
|
||||
|
||||
function update_control_metadatum( $item ) {
|
||||
if ( $item instanceof \Tainacan\Entities\Item ) {
|
||||
|
||||
$metadata = $item->get_metadata();
|
||||
foreach ($metadata as $item_metadatum) {
|
||||
|
||||
if ( $item_metadatum->get_metadatum()->get_metadata_type_object() instanceof \Tainacan\Metadata_Types\Control && $item_metadatum->get_metadatum()->get_metadata_type_options()['control_metadatum'] == $this->get_option('control_metadatum')) {
|
||||
if ( $item_metadatum->get_metadatum()->get_metadata_type_object() instanceof \Tainacan\Metadata_Types\Control &&
|
||||
$item_metadatum->get_metadatum()->get_metadata_type_options()['control_metadatum'] == $this->get_option('control_metadatum')) {
|
||||
|
||||
$update_item_metadatum = new \Tainacan\Entities\Item_Metadata_Entity( $item, $item_metadatum->get_metadatum() );
|
||||
switch ( $this->get_option('control_metadatum') ) {
|
||||
|
@ -62,7 +60,6 @@ class Control extends Metadata_Type {
|
|||
}
|
||||
|
||||
public function validate_options( Metadatum $metadatum ) {
|
||||
|
||||
if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) )
|
||||
return true;
|
||||
|
||||
|
@ -71,9 +68,7 @@ class Control extends Metadata_Type {
|
|||
'control_metadatum' => __('Required control metadatum.','tainacan')
|
||||
];
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function get_control_metadatum_value($value, $control_metadatum, $format) {
|
||||
|
@ -101,10 +96,8 @@ class Control extends Metadata_Type {
|
|||
* @return string The HTML representation of the value, containing one or multiple items names, linked to the item page
|
||||
*/
|
||||
public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
|
||||
|
||||
$value = $item_metadata->get_value();
|
||||
$control_metadatum = $this->get_option('control_metadatum');
|
||||
|
||||
return $this->get_control_metadatum_value($value, $control_metadatum, 'html');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue