static function render_modules($property_slug) { $relations = papi_get_field($property_slug); if ($relations) { foreach ($relations as $key => $relation) { $blade_template = rtrim(papi_get_page_type_template($relation->ID), '.php'); $view = view($blade_template, ['module' => papi_get_page($relation->ID)]); $pathToCompiled = $view->path; include $pathToCompiled; } } }
/** * Update field with new value. The old value will be deleted. * * @param int $post_id * @param string $slug * @param mixed $value * @param string $type * * @return bool */ function papi_update_field($post_id = null, $slug = null, $value = null, $type = 'page') { if (!is_numeric($post_id) && is_string($post_id)) { $value = $slug; $slug = $post_id; $post_id = null; } if (!is_string($slug) || empty($slug)) { return false; } if (papi_is_empty($value)) { return papi_delete_field($post_id, $slug, $type); } $post_id = papi_get_post_id($post_id); if ($post_id === 0 && $type === Papi_Post_Page::TYPE) { return false; } $page = papi_get_page($post_id, $type); if (is_null($page)) { return false; } $property = $page->get_property($slug); if (!papi_is_property($property)) { return false; } papi_delete_field($post_id, $slug, $type); $value = $property->update_value($value, $slug, $post_id); $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $post_id); return papi_update_property_meta_value(['type' => $type, 'post_id' => $post_id, 'slug' => $slug, 'value' => $value]); }
/** * Get the page that the property is on. * * @return Papi_Core_Page|null */ public function get_page() { if ($this->page instanceof Papi_Core_Page) { return $this->page; } return papi_get_page($this->get_post_id()); }
/** * Get the current page. Like in EPiServer. * * @deprecated deprecated since version 2.0.0. * * @return Papi_Page|null */ function current_page() { _deprecated_function(__FUNCTION__, '2.0.0'); return papi_get_page(); }
/** * Get boxes with properties slug for a page. * * @param int $post_id * * @return array */ function papi_get_slugs($post_id = 0) { $page = papi_get_page($post_id); if ($page instanceof Papi_Post_Page === false) { return []; } $page_type = $page->get_page_type(); if (empty($page_type)) { return []; } $value = []; $boxes = $page_type->get_boxes(); foreach ($boxes as $box) { if (count($box) < 2 || empty($box[0]['title']) || !is_array($box[1])) { continue; } if (!isset($value[$box[0]['title']])) { $value[$box[0]['title']] = []; } foreach ($box[1] as $property) { $value[$box[0]['title']][] = $property->get_slug(true); } } return $value; }
/** * Get boxes with properties slug for a page. * * @param int $post_id * * @return array */ function papi_get_slugs($post_id = 0) { $page = papi_get_page($post_id); if ($page instanceof Papi_Post_Page === false) { return []; } $page_type = $page->get_page_type(); if (empty($page_type)) { return []; } $value = []; $boxes = $page_type->get_boxes(); foreach ($boxes as $box) { $title = $box->title; if (!isset($value[$title])) { $value[$title] = []; } foreach ($box->properties as $property) { $value[$title][] = $property->get_slug(true); } } return $value; }
/** * Export data from Papi. With or without all property options. * * @param mixed $post_id * @param bool $only_values * * @return array */ public function export($post_id, $only_values = false) { $post_id = papi_get_post_id($post_id); if (empty($post_id)) { return []; } $slugs = papi_get_slugs($post_id); foreach ($slugs as $key => $box) { foreach ($box as $index => $slug) { unset($slugs[$key][$index]); $value = papi_get_field($post_id, $slug, null); if ($only_values === true) { $slugs[$key][$slug] = $value; } else { $page = papi_get_page($post_id); // @codeCoverageIgnoreStart if (is_null($page)) { continue; } // @codeCoverageIgnoreEnd $property = $page->get_property($slug); // @codeCoverageIgnoreStart if (!papi_is_property($property)) { continue; } // @codeCoverageIgnoreEnd $options = clone $property->get_options(); $options->value = $value; $slugs[$key][$slug] = $options; } } } return $slugs; }