From 936aa9182ebafad5b1e54da6da31583c6c9eb0e8 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 27 Apr 2017 13:40:57 -0400 Subject: [PATCH 1/8] Update for Symphony 4.x Update release version. Update generated buttons to conform them to the Symphony 4.x layout. --- extension.driver.php | 115 ++++++++++++++++++++++--------------------- extension.meta.xml | 13 +++-- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 58c0950..f070757 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -32,14 +32,14 @@ public function getSubscribedDelegates(){ ) ); } - + public function entryPostEdit($context) { $section = $context['section']; $errors = Administration::instance()->Page->_errors; - + $isReturn = isset($_POST['fields']['save-and-return-h']) && strlen($_POST['fields']['save-and-return-h']) > 1; $isNew = isset($_POST['fields']['save-and-new-h']) && strlen($_POST['fields']['save-and-new-h']) > 1; - + // if save returned no errors and return or new button was hit if (($isReturn || $isNew) && count($errors) < 1) { try { @@ -56,58 +56,63 @@ public function entryPostEdit($context) { } } } - + public function appendElement($context) { - + // if in edit or new page if ($this->isInEditOrNew()) { - + // Get this section's limit $limits = $this->getSectionLimit(); - + // Exit early if no limits where found if ($limits === FALSE || empty($limits) || !is_array($limits)) { return; } - + // Exit early if the limit is one if ($limits['limit'] == 1) { return; } - + // add new if limit is 0 or total is less than limit $shouldAddNew = $limits['limit'] == 0 || ($limits['total']+1) < $limits['limit']; - + // add return if the limit is not 1 $shouldAddReturn = $limits['limit'] != 1; - + $page = $context['oPage']; - + $form = $page->Form; - - $button_wrap = new XMLELement('div', NULL, array( - 'id' => 'save-and', - 'style' => 'float:right' - )); - + + $button_wrap = new XMLElement('div'); + if ($shouldAddReturn) { // add return button in wrapper $button_return = $this->createButton('save-and-return', 'Save & return'); $hidden_return = $this->createHidden('save-and-return-h'); - - $button_wrap->appendChild($button_return); + + $button_wrap->appendChild(Widget::SVGIconContainer( + 'save', + $button_return, + array('id' => 'save-and') + )); $button_wrap->appendChild($hidden_return); } - + if ($shouldAddNew) { // add the new button $button_new = $this->createButton('save-and-new', 'Save & new'); $hidden_new = $this->createHidden('save-and-new-h'); - - $button_wrap->appendChild($button_new); + + $button_wrap->appendChild(Widget::SVGIconContainer( + 'save', + $button_return, + array('id' => 'save-and') + )); $button_wrap->appendChild($hidden_new); } - + // save current query string: the raw (visible) query string $queryString = explode('?', $_SERVER['REQUEST_URI'], 2); if ($queryString != FALSE && count($queryString) == 2) { @@ -118,17 +123,17 @@ public function appendElement($context) { $qs_hidden = $this->createHidden('save-and-qs'); $qs_hidden->setAttribute('value', $queryString); $button_wrap->appendChild($qs_hidden); - + // add content to the right div $div_action = $this->getChildrenWithClass($form, 'div', 'actions'); - + // if there is no fields, div_action may not be there if ($div_action != NULL) { - $div_action->appendChild($button_wrap); + $div_action->insertChildAt(1, $button_wrap); } } } - + private function createButton($id, $value) { $btn = new XMLElement('input', NULL, array( 'id' => $id, @@ -137,10 +142,10 @@ private function createButton($id, $value) { 'type' => 'submit' )); $btn->setSelfClosingTag(true); - + return $btn; } - + private function createHidden($id) { $h = new XMLElement('input', NULL, array( 'id' => $id, @@ -148,80 +153,80 @@ private function createHidden($id) { 'type' => 'hidden' )); $h->setSelfClosingTag(true); - + return $h; } - + private function getPath($isNew) { - + $queryString = isset($_POST['fields']['save-and-qs']) && strlen($_POST['fields']['save-and-qs']) > 1; - + if ($queryString) { $queryString = '?' . urldecode($_POST['fields']['save-and-qs']); } else { $queryString = ''; } - + if ($isNew) { return '%s/publish/%s/new/' . $queryString; } return '%s/publish/%s/' . $queryString; } - + private function isInEditOrNew() { $c = Administration::instance()->getPageCallback(); $c = $c['context']['page']; - + return Symphony::Engine()->isLoggedIn() && ($c == 'edit' || $c == 'new'); } - + private function getChildrenWithClass($rootElement, $tagName, $className) { if (! ($rootElement) instanceof XMLElement) { return NULL; // not and XMLElement } - + // contains the right css class and the right node name if (strpos($rootElement->getAttribute('class'), $className) > -1 && $rootElement->getName() == $tagName) { return $rootElement; } - + // recursive search in child elements foreach ($rootElement->getChildren() as $child) { $res = $this->getChildrenWithClass($child, $tagName, $className); - + if ($res != NULL) { return $res; } } - + return NULL; } - - + + private function getSectionLimit(){ $extman = Symphony::ExtensionManager(); - + // limit section entries $status = $extman->fetchStatus(array('handle' => 'limit_section_entries', 'version' => '1')); - + if (in_array(EXTENSION_ENABLED, $status)) { require_once (EXTENSIONS . '/limit_section_entries/lib/class.LSE.php'); $limit = LSE::getMaxEntries(); $total = LSE::getTotalEntries(); - + return array( 'limit' => $limit, 'total' => $total ); } - + return FALSE; } - + public function appendJS($context){ - + if ($this->isInEditOrNew()) { - + Administration::instance()->Page->addElementToHead( new XMLElement( 'script', @@ -230,7 +235,7 @@ public function appendJS($context){ $('#save-and-return').click(function () { $('#save-and-return-h').val('true'); }); - + $('#save-and-new').click(function () { $('#save-and-new-h').val('true'); }); @@ -238,7 +243,7 @@ public function appendJS($context){ })(jQuery);" ), time()+100 ); - + // add CSS for subsection manager Administration::instance()->Page->addElementToHead( new XMLElement( @@ -248,7 +253,7 @@ public function appendJS($context){ ), time()+101 ); } - + } } - + diff --git a/extension.meta.xml b/extension.meta.xml index 7d47cb0..9fc15f9 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -23,6 +23,9 @@ + + - Update for Symphony 4.x + - Fixed some typos @@ -46,13 +49,13 @@ - Fixes for compatibility with Static Section - - Fixes for compatibility with Symphony 2.3 + - Fixes for compatibility with Symphony 2.3 - - Fix issue #1 and #2 (the buttons appeared when not needed) + - Fix issue #1 and #2 (the buttons appeared when not needed) - - Update CSS for hiding the buttons in the Subsection Manager extension + - Update CSS for hiding the buttons in the Subsection Manager extension - Update for compatibility with Static Section v1.7 @@ -63,6 +66,6 @@ - First release - + - \ No newline at end of file + From 24bbd65b92d1f2a714b7510a53e2170a74721507 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 5 May 2017 13:10:04 -0400 Subject: [PATCH 2/8] Fix button for Save&New. --- extension.driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index f070757..4ba93b9 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -107,7 +107,7 @@ public function appendElement($context) { $button_wrap->appendChild(Widget::SVGIconContainer( 'save', - $button_return, + $button_new, array('id' => 'save-and') )); $button_wrap->appendChild($hidden_new); From 2ee6542f7f29e78aa071b1caee3590040c79fe46 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 11 May 2017 15:41:12 -0400 Subject: [PATCH 3/8] Add stylesheet to fix bugs in layout --- assets/save_and_return.css | 16 ++++++++++++++++ extension.driver.php | 19 ++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 assets/save_and_return.css diff --git a/assets/save_and_return.css b/assets/save_and_return.css new file mode 100644 index 0000000..f6c690d --- /dev/null +++ b/assets/save_and_return.css @@ -0,0 +1,16 @@ +body.inline.subsection #save-and { + display: none; + visibility: collapse; +} + +@media (max-width: 1023px) { + #save-and { + display: flex; + flex-direction: row; + align-items: center; + } + + #save-and > * + * { + margin-left: 1rem; + } +} diff --git a/extension.driver.php b/extension.driver.php index 4ba93b9..bce153b 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -86,6 +86,7 @@ public function appendElement($context) { $form = $page->Form; $button_wrap = new XMLElement('div'); + $button_wrap->setAttribute('id', 'save-and'); if ($shouldAddReturn) { // add return button in wrapper @@ -94,8 +95,7 @@ public function appendElement($context) { $button_wrap->appendChild(Widget::SVGIconContainer( 'save', - $button_return, - array('id' => 'save-and') + $button_return )); $button_wrap->appendChild($hidden_return); } @@ -107,8 +107,7 @@ public function appendElement($context) { $button_wrap->appendChild(Widget::SVGIconContainer( 'save', - $button_new, - array('id' => 'save-and') + $button_new )); $button_wrap->appendChild($hidden_new); } @@ -244,13 +243,11 @@ public function appendJS($context){ ), time()+100 ); - // add CSS for subsection manager - Administration::instance()->Page->addElementToHead( - new XMLElement( - 'style', - "body.inline.subsection #save-and { display: none; visibility: collapse }", - array('type' => 'text/css') - ), time()+101 + Administration::instance()->Page->addStylesheetToHead( + URL . '/extensions/save_and_return/assets/save_and_return.css', + 'screen', + time() + 1, + false ); } From 4daca0d8fac862b31123a2e79f94457a2838e14c Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 17 May 2017 11:01:18 -0400 Subject: [PATCH 4/8] Update php-min/php-max info --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 9fc15f9..7790eed 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -23,7 +23,7 @@ - + - Update for Symphony 4.x From 05637b40092e2526f1b7d10b7871d92a31fa2d44 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 24 Aug 2017 16:05:10 -0400 Subject: [PATCH 5/8] SQL and PHP cases PHP true,false,null in lowercase SQL keywords uppercase --- extension.driver.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index bce153b..fb6c94e 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -66,7 +66,7 @@ public function appendElement($context) { $limits = $this->getSectionLimit(); // Exit early if no limits where found - if ($limits === FALSE || empty($limits) || !is_array($limits)) { + if ($limits === false || empty($limits) || !is_array($limits)) { return; } @@ -114,7 +114,7 @@ public function appendElement($context) { // save current query string: the raw (visible) query string $queryString = explode('?', $_SERVER['REQUEST_URI'], 2); - if ($queryString != FALSE && count($queryString) == 2) { + if ($queryString != false && count($queryString) == 2) { $queryString = $queryString[1]; } else { $queryString = ''; @@ -127,14 +127,14 @@ public function appendElement($context) { $div_action = $this->getChildrenWithClass($form, 'div', 'actions'); // if there is no fields, div_action may not be there - if ($div_action != NULL) { + if ($div_action != null) { $div_action->insertChildAt(1, $button_wrap); } } } private function createButton($id, $value) { - $btn = new XMLElement('input', NULL, array( + $btn = new XMLElement('input', null, array( 'id' => $id, 'name' => 'action[save]', 'value' => __($value), @@ -146,7 +146,7 @@ private function createButton($id, $value) { } private function createHidden($id) { - $h = new XMLElement('input', NULL, array( + $h = new XMLElement('input', null, array( 'id' => $id, 'name' => "fields[$id]", 'type' => 'hidden' @@ -181,7 +181,7 @@ private function isInEditOrNew() { private function getChildrenWithClass($rootElement, $tagName, $className) { if (! ($rootElement) instanceof XMLElement) { - return NULL; // not and XMLElement + return null; // not and XMLElement } // contains the right css class and the right node name @@ -193,12 +193,12 @@ private function getChildrenWithClass($rootElement, $tagName, $className) { foreach ($rootElement->getChildren() as $child) { $res = $this->getChildrenWithClass($child, $tagName, $className); - if ($res != NULL) { + if ($res != null) { return $res; } } - return NULL; + return null; } @@ -219,7 +219,7 @@ private function getSectionLimit(){ ); } - return FALSE; + return false; } public function appendJS($context){ From b292147842e66b0cb57308945d5f4ecf7d865b05 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 7 Jun 2018 15:46:08 -0400 Subject: [PATCH 6/8] Fix dependency status --- extension.driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index fb6c94e..b6935bf 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -208,7 +208,7 @@ private function getSectionLimit(){ // limit section entries $status = $extman->fetchStatus(array('handle' => 'limit_section_entries', 'version' => '1')); - if (in_array(EXTENSION_ENABLED, $status)) { + if (in_array(Extension::EXTENSION_ENABLED, $status)) { require_once (EXTENSIONS . '/limit_section_entries/lib/class.LSE.php'); $limit = LSE::getMaxEntries(); $total = LSE::getTotalEntries(); From a48a8f1d11608349fd973bc81204a892d38f5e1e Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 4 Jul 2018 13:32:17 -0400 Subject: [PATCH 7/8] Remove deprecated errors check --- extension.driver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index b6935bf..edace9c 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -35,13 +35,12 @@ public function getSubscribedDelegates(){ public function entryPostEdit($context) { $section = $context['section']; - $errors = Administration::instance()->Page->_errors; $isReturn = isset($_POST['fields']['save-and-return-h']) && strlen($_POST['fields']['save-and-return-h']) > 1; $isNew = isset($_POST['fields']['save-and-new-h']) && strlen($_POST['fields']['save-and-new-h']) > 1; - // if save returned no errors and return or new button was hit - if (($isReturn || $isNew) && count($errors) < 1) { + // if return or new button was hit + if ($isReturn || $isNew) { try { redirect(vsprintf( $this->getPath($isNew), From 6dcc4c1de43dae5cb869519d44118b6d86c73862 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 25 Feb 2019 09:31:20 -0500 Subject: [PATCH 8/8] Apply patch from @nitriques : Use the getErrors() method instead of the (now) protected $_errors property --- extension.driver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/extension.driver.php b/extension.driver.php index edace9c..abc7931 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -35,6 +35,7 @@ public function getSubscribedDelegates(){ public function entryPostEdit($context) { $section = $context['section']; + $errors = Administration::instance()->Page->getErrors(); $isReturn = isset($_POST['fields']['save-and-return-h']) && strlen($_POST['fields']['save-and-return-h']) > 1; $isNew = isset($_POST['fields']['save-and-new-h']) && strlen($_POST['fields']['save-and-new-h']) > 1;