/**
  * Update value.
  *
  * @param  Papi_Core_Property $property
  * @param  mixed  $value
  * @param  string $slug
  * @param  int    $post_id
  *
  * @return array
  */
 protected function update_value($property, $value, $slug, $post_id)
 {
     if (!is_array($value) || !$this->should_update_array($slug)) {
         return $property->import_value($value, $slug, $post_id);
     }
     $old = papi_get_field($post_id, $slug, []);
     $value = array_merge($old, $value);
     $value = $property->import_value($value, $slug, $post_id);
     if ($property->import_setting('property_array_slugs')) {
         return papi_from_property_array_slugs($value, $slug);
     }
     return $property->update_value($value, $slug, $post_id);
 }
 /**
  * Change value after it's loaded from the database
  * and populate every property in the flexible with the right property type.
  *
  * @param mixed  $value
  * @param string $repeater_slug
  * @param int    $post_id
  *
  * @return array
  */
 public function load_value($value, $repeater_slug, $post_id)
 {
     if (is_array($value)) {
         return $value;
     }
     list($results, $trash) = $this->get_results($value, $repeater_slug, $post_id);
     // Will not need this array.
     unset($trash);
     $store = $this->get_store();
     $results = papi_from_property_array_slugs($results, unpapify($repeater_slug));
     if (is_null($store)) {
         return $this->default_value;
     }
     return $this->load_child_properties($results, $this);
 }
 /**
  * Load child properties.
  *
  * @param  array              $results
  * @param  Papi_Core_Property $property
  *
  * @return array
  */
 protected function load_child_properties(array $results, $property = null)
 {
     foreach ($results as $index => $row) {
         foreach ($row as $slug => $value) {
             if (is_array($value) && isset($value[$slug])) {
                 $child_property = $this->get_store()->get_property($this->get_slug(true), $slug);
                 if (papi_is_property($child_property) && !empty($child_property->get_child_properties())) {
                     $value = papi_from_property_array_slugs($value, unpapify($slug));
                     $results[$index][$slug] = $this->load_child_properties($value, $child_property);
                 }
             }
             $type_key = papi_get_property_type_key_f($slug);
             if ($property->match_slug($slug)) {
                 $results[$index][$type_key] = $property;
             } else {
                 $results[$index][$type_key] = $property->get_child_property($slug);
             }
         }
     }
     return $results;
 }
 /**
  * Change value after it's loaded from the database
  * and populate every property in the flexible with the right property type.
  *
  * @param mixed  $value
  * @param string $repeater_slug
  * @param int    $post_id
  *
  * @return array
  */
 public function load_value($value, $repeater_slug, $post_id)
 {
     if (is_array($value)) {
         return $value;
     }
     list($results, $trash) = $this->get_results($value, $repeater_slug, $post_id);
     // Will not need this array.
     unset($trash);
     $page = $this->get_page();
     $results = papi_from_property_array_slugs($results, papi_remove_papi($repeater_slug));
     if (is_null($page)) {
         return $this->default_value;
     }
     foreach ($results as $index => $row) {
         foreach ($row as $slug => $value) {
             if (papi_is_property_type_key($slug)) {
                 continue;
             }
             if ($property = $page->get_property($repeater_slug, $slug)) {
                 $type_key = papi_get_property_type_key_f($slug);
                 $results[$index][$type_key] = $property;
             }
         }
     }
     return $results;
 }