From 1d2ce9657a44398646ed1a3980d89a1d2f50fa05 Mon Sep 17 00:00:00 2001 From: Sem Date: Fri, 13 Jul 2012 07:42:36 +0200 Subject: Fixes #1334. Added dropdown to change the parent of a page. --- mod/pages/views/default/forms/pages/edit.php | 10 +++----- mod/pages/views/default/input/parent.php | 37 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 mod/pages/views/default/input/parent.php (limited to 'mod/pages/views/default') diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 9469f5eb9..119b9ba23 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -18,6 +18,9 @@ foreach ($variables as $name => $type) { if (($type == 'access' || $type == 'write_access') && !$can_change_access) { continue; } + if ($name == 'parent_guid' && empty($vars['parent_guid'])) { + continue; + } ?>
@@ -29,6 +32,7 @@ foreach ($variables as $name => $type) { echo elgg_view("input/$type", array( 'name' => $name, 'value' => $vars[$name], + 'entity' => ($name == 'parent_guid') ? $vars['entity'] : null, )); ?>
@@ -52,12 +56,6 @@ echo elgg_view('input/hidden', array( 'name' => 'container_guid', 'value' => $vars['container_guid'], )); -if ($vars['parent_guid']) { - echo elgg_view('input/hidden', array( - 'name' => 'parent_guid', - 'value' => $vars['parent_guid'], - )); -} echo elgg_view('input/submit', array('value' => elgg_echo('save'))); diff --git a/mod/pages/views/default/input/parent.php b/mod/pages/views/default/input/parent.php new file mode 100644 index 000000000..f354129fe --- /dev/null +++ b/mod/pages/views/default/input/parent.php @@ -0,0 +1,37 @@ +getContainerEntity(); +} + +$pages = pages_get_navigation_tree($container); +$options = array(); + +foreach ($pages as $page) { + $spacing = ""; + for ($i = 0; $i < $page['depth']; $i++) { + $spacing .= "--"; + } + $options[$page['guid']] = "$spacing " . $page['title']; +} + +$defaults = array( + 'class' => 'elgg-input-parent-picker', + 'options_values' => $options, +); + +$vars = array_merge($defaults, $vars); + +echo elgg_view('input/dropdown', $vars); -- cgit v1.2.3 From 3bd71fbe0aa4a64021c4c2d59b0782faba8c22b6 Mon Sep 17 00:00:00 2001 From: Sem Date: Sat, 14 Jul 2012 21:42:20 +0200 Subject: Refs #1334. Prevent cycles in the pages tree. --- mod/pages/actions/pages/edit.php | 22 +++++++++++++++++++++- mod/pages/views/default/forms/pages/edit.php | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'mod/pages/views/default') diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php index e6387c1a4..bf54ae87d 100644 --- a/mod/pages/actions/pages/edit.php +++ b/mod/pages/actions/pages/edit.php @@ -70,7 +70,27 @@ if (sizeof($input) > 0) { // need to add check to make sure user can write to container $page->container_guid = $container_guid; -if ($parent_guid) { +if ($parent_guid && $parent_guid != $page_guid) { + // Check if parent isn't below of the page in the tree + if ($page_guid) { + $tree_page = get_entity($parent_guid); + while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) { + $tree_page = get_entity($tree_page->parent_guid); + } + // If is below, bring all child elements forward + if ($page_guid == $tree_page->guid) { + $previous_parent = $page->parent_guid; + $children = elgg_get_entities_from_metadata(array( + 'metadata_name' => 'parent_guid', + 'metadata_value' => $page->getGUID() + )); + if ($children) { + foreach ($children as $child) { + $child->parent_guid = $previous_parent; + } + } + } + } $page->parent_guid = $parent_guid; } diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 119b9ba23..583dc414f 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -18,7 +18,8 @@ foreach ($variables as $name => $type) { if (($type == 'access' || $type == 'write_access') && !$can_change_access) { continue; } - if ($name == 'parent_guid' && empty($vars['parent_guid'])) { + // don't show parent picker input for top or new pages. + if ($name == 'parent_guid' && (!$vars['parent_guid'] || !$vars['guid'])) { continue; } ?> -- cgit v1.2.3 From 21eb7616a11906a19260a081070a6b1c51820fa3 Mon Sep 17 00:00:00 2001 From: Sem Date: Sat, 14 Jul 2012 22:24:09 +0200 Subject: Refs #1334. Readded hidden input in edit page form, only on page creation. --- mod/pages/views/default/forms/pages/edit.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mod/pages/views/default') diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php index 583dc414f..653a7ee47 100644 --- a/mod/pages/views/default/forms/pages/edit.php +++ b/mod/pages/views/default/forms/pages/edit.php @@ -57,6 +57,12 @@ echo elgg_view('input/hidden', array( 'name' => 'container_guid', 'value' => $vars['container_guid'], )); +if (!$vars['guid']) { + echo elgg_view('input/hidden', array( + 'name' => 'parent_guid', + 'value' => $vars['parent_guid'], + )); +} echo elgg_view('input/submit', array('value' => elgg_echo('save'))); -- cgit v1.2.3