Fixes setting value for multiple config

This commit is contained in:
Rodrigo Guimarães 2020-12-23 17:56:08 -03:00
parent 5ca77d3373
commit 539a3721e4
3 changed files with 14 additions and 19 deletions

View File

@ -2,7 +2,7 @@
# Executa o comando 'sass' para verificar se existe (veja http://stackoverflow.com/a/677212/329911) # Executa o comando 'sass' para verificar se existe (veja http://stackoverflow.com/a/677212/329911)
command -v sass >/dev/null 2>&1 || { command -v sass >/dev/null 2>&1 || {
echo >&2 "SASS parece não está disponivel."; echo >&2 "Sass parece não estar disponivel.";
exit 1; exit 1;
} }

View File

@ -188,13 +188,9 @@ class REST_Item_Metadata_Controller extends REST_Controller {
$body = json_decode( $request->get_body(), true ); $body = json_decode( $request->get_body(), true );
if ($body) { if ($body) {
$item_id = $request['item_id']; $item_id = $request['item_id'];
$metadatum_id = $request['metadatum_id']; $value = $body['values'];
$value = $body['values']; $metadatum_id = $request['metadatum_id'];
if (is_array($value)) {
$value = implode(' ', $value);
}
$value = $this->filter_value($value);
$parent_meta_id = isset( $body['parent_meta_id'] ) && $body['parent_meta_id'] > 0 ? $body['parent_meta_id'] : null; $parent_meta_id = isset( $body['parent_meta_id'] ) && $body['parent_meta_id'] > 0 ? $body['parent_meta_id'] : null;
$item = $this->item_repository->fetch($item_id); $item = $this->item_repository->fetch($item_id);
@ -202,6 +198,11 @@ class REST_Item_Metadata_Controller extends REST_Controller {
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum, null, $parent_meta_id); $item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum, null, $parent_meta_id);
if (is_array($value) && !$item_metadata->is_multiple()) {
$value = implode(' ', $value);
}
$value = $this->filter_value($value);
$item_metadata->set_value($value); $item_metadata->set_value($value);
if ($item_metadata->validate()) { if ($item_metadata->validate()) {

View File

@ -199,10 +199,9 @@ class Item_Metadata_Entity extends Entity {
public function get_value_as_array() { public function get_value_as_array() {
$value = $this->get_value(); $value = $this->get_value();
$primitive_type = $this->get_metadatum()->get_metadata_type_object()->get_primitive_type(); $primitive_type = $this->get_metadatum()->get_metadata_type_object()->get_primitive_type();
$return = [];
if ( $this->is_multiple() ) {
$return = []; if ($this->is_multiple()) {
foreach ($value as $v) { foreach ($value as $v) {
if( is_array($v) ) { if( is_array($v) ) {
$options = $this->get_metadatum()->get_metadata_type_object()->get_options(); $options = $this->get_metadatum()->get_metadata_type_object()->get_options();
@ -227,12 +226,8 @@ class Item_Metadata_Entity extends Entity {
$return[] = $v; $return[] = $v;
} }
} }
} else { } else {
if ($primitive_type === 'compound') {
$return = '';
if( $primitive_type === 'compound' ) {
$compounds = []; $compounds = [];
$compounds_not_ordinate = []; $compounds_not_ordinate = [];
$options = $this->get_metadatum()->get_metadata_type_object()->get_options(); $options = $this->get_metadatum()->get_metadata_type_object()->get_options();
@ -274,7 +269,6 @@ class Item_Metadata_Entity extends Entity {
} }
return $return; return $return;
} }
/** /**
@ -285,7 +279,7 @@ class Item_Metadata_Entity extends Entity {
* *
* @return array the representation of this object as an array * @return array the representation of this object as an array
*/ */
public function _toArray( $formatted_values = true, $cascade = false ){ public function _toArray( $formatted_values = true, $cascade = false ){
$as_array = []; $as_array = [];
$as_array['value'] = $this->get_value_as_array(); $as_array['value'] = $this->get_value_as_array();